diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/backup/RestoreClient.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/backup/RestoreClient.java index acbcb44..3b1c7bd 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/backup/RestoreClient.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/backup/RestoreClient.java @@ -40,10 +40,11 @@ public interface RestoreClient { * @param tTableArray The array of mapping tables to restore to * @param isOverwrite True then do restore overwrite if target table exists, otherwise fail the * request if target table exists + * @param isIncrBackup true if the backup was incremental backup * @throws IOException if any failure during restore */ public void restore( String backupRootDir, String backupId, boolean check, boolean autoRestore, TableName[] sTableArray, - TableName[] tTableArray, boolean isOverwrite) throws IOException; + TableName[] tTableArray, boolean isOverwrite, boolean isIncrBackup) throws IOException; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java index 0dba079..473b8c6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java @@ -30,6 +30,7 @@ import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.backup.impl.BackupRestoreConstants; import org.apache.hadoop.hbase.backup.impl.BackupSystemTable; import org.apache.hadoop.hbase.backup.util.BackupServerUtil; +import org.apache.hadoop.hbase.client.BackupAdmin; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.util.AbstractHBaseTool; @@ -163,13 +164,16 @@ public class RestoreDriver extends AbstractHBaseTool { return -4; } - - RestoreClient client = BackupRestoreClientFactory.getRestoreClient(getConf()); - try{ - client.restore(backupRootDir, backupId, check, autoRestore, sTableArray, - tTableArray, isOverwrite); + try { + try (final Connection conn = ConnectionFactory.createConnection(conf); + final BackupAdmin admin = conn.getAdmin().getBackupAdmin();) { + BackupInfo info = admin.getBackupInfo(backupId); + RestoreClient client = BackupRestoreClientFactory.getRestoreClient(getConf()); + client.restore(backupRootDir, backupId, check, autoRestore, sTableArray, + tTableArray, isOverwrite, info.getType() == BackupType.INCREMENTAL); + } } catch (Exception e){ - e.printStackTrace(); + System.out.println(e); return -5; } return 0; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/RestoreClientImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/RestoreClientImpl.java index 9906f47..b4afb66 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/RestoreClientImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/RestoreClientImpl.java @@ -75,12 +75,13 @@ public final class RestoreClientImpl implements RestoreClient { * @param tTableArray The array of mapping tables to restore to * @param isOverwrite True then do restore overwrite if target table exists, otherwise fail the * request if target table exists + * @param isIncrBackup true if the backup was incremental backup * @throws IOException if any failure during restore */ @Override public void restore(String backupRootDir, String backupId, boolean check, boolean autoRestore, TableName[] sTableArray, - TableName[] tTableArray, boolean isOverwrite) throws IOException { + TableName[] tTableArray, boolean isOverwrite, boolean isIncrBackup) throws IOException { HashMap backupManifestMap = new HashMap<>(); // check and load backup image manifest for the tables @@ -105,7 +106,7 @@ public final class RestoreClientImpl implements RestoreClient { } // check the target tables - checkTargetTables(tTableArray, isOverwrite); + checkTargetTables(tTableArray, isOverwrite, isIncrBackup); // start restore process @@ -155,9 +156,10 @@ public final class RestoreClientImpl implements RestoreClient { * Validate target Tables * @param tTableArray: target tables * @param isOverwrite overwrite existing table + * @param isIncrBackup true if the backup was incremental backup * @throws IOException exception */ - private void checkTargetTables(TableName[] tTableArray, boolean isOverwrite) + private void checkTargetTables(TableName[] tTableArray, boolean isOverwrite, boolean isIncrBackup) throws IOException { ArrayList existTableList = new ArrayList<>(); ArrayList disabledTableList = new ArrayList<>(); @@ -180,11 +182,13 @@ public final class RestoreClientImpl implements RestoreClient { if (existTableList.size() > 0) { if (!isOverwrite) { - LOG.error("Existing table found in the restore target, please add \"-overwrite\" " + if (!isIncrBackup) { + LOG.error("Existing table found in the restore target, please add \"-overwrite\" " + "option in the command if you mean to restore to these existing tables"); - LOG.info("Existing table list in restore target: " + existTableList); - throw new IOException("Existing table found in target while no \"-overwrite\" " + LOG.info("Existing table list in restore target: " + existTableList); + throw new IOException("Existing table found in target while no \"-overwrite\" " + "option found"); + } } else { if (disabledTableList.size() > 0) { LOG.error("Found offline table in the restore target, "