Search in sources :

Example 1 with RestoreTool

use of org.apache.hadoop.hbase.backup.util.RestoreTool in project hbase by apache.

the class RestoreTablesClient method restoreImages.

/**
   * Restore operation handle each backupImage in array
   * @param svc: master services
   * @param images: array BackupImage
   * @param sTable: table to be restored
   * @param tTable: table to be restored to
   * @param truncateIfExists: truncate table
   * @throws IOException exception
   */
private void restoreImages(BackupImage[] images, TableName sTable, TableName tTable, boolean truncateIfExists) throws IOException {
    // First image MUST be image of a FULL backup
    BackupImage image = images[0];
    String rootDir = image.getRootDir();
    String backupId = image.getBackupId();
    Path backupRoot = new Path(rootDir);
    RestoreTool restoreTool = new RestoreTool(conf, backupRoot, backupId);
    Path tableBackupPath = HBackupFileSystem.getTableBackupPath(sTable, backupRoot, backupId);
    String lastIncrBackupId = images.length == 1 ? null : images[images.length - 1].getBackupId();
    // We need hFS only for full restore (see the code)
    BackupManifest manifest = HBackupFileSystem.getManifest(sTable, conf, backupRoot, backupId);
    if (manifest.getType() == BackupType.FULL) {
        LOG.info("Restoring '" + sTable + "' to '" + tTable + "' from full" + " backup image " + tableBackupPath.toString());
        restoreTool.fullRestoreTable(conn, tableBackupPath, sTable, tTable, truncateIfExists, lastIncrBackupId);
    } else {
        // incremental Backup
        throw new IOException("Unexpected backup type " + image.getType());
    }
    if (images.length == 1) {
        // full backup restore done
        return;
    }
    List<Path> dirList = new ArrayList<Path>();
    // full backup path comes first
    for (int i = 1; i < images.length; i++) {
        BackupImage im = images[i];
        String logBackupDir = HBackupFileSystem.getLogBackupDir(im.getRootDir(), im.getBackupId());
        dirList.add(new Path(logBackupDir));
    }
    String dirs = StringUtils.join(dirList, ",");
    LOG.info("Restoring '" + sTable + "' to '" + tTable + "' from log dirs: " + dirs);
    Path[] paths = new Path[dirList.size()];
    dirList.toArray(paths);
    restoreTool.incrementalRestoreTable(conn, tableBackupPath, paths, new TableName[] { sTable }, new TableName[] { tTable }, lastIncrBackupId);
    LOG.info(sTable + " has been successfully restored to " + tTable);
}
Also used : Path(org.apache.hadoop.fs.Path) RestoreTool(org.apache.hadoop.hbase.backup.util.RestoreTool) BackupImage(org.apache.hadoop.hbase.backup.impl.BackupManifest.BackupImage) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Path (org.apache.hadoop.fs.Path)1 BackupImage (org.apache.hadoop.hbase.backup.impl.BackupManifest.BackupImage)1 RestoreTool (org.apache.hadoop.hbase.backup.util.RestoreTool)1