public static void main(String[] args) throws Exception { Configuration conf = HBaseConfiguration.create(); Path hbasedir = FSUtils.getRootDir(conf); URI defaultFs = hbasedir.getFileSystem(conf).getUri(); FSUtils.setFsDefault(conf, new Path(defaultFs)); int ret = ToolRunner.run(conf, new RestoreDriver(), args); System.exit(ret); }
@Override protected void addOptions() { // define supported options addOptNoArg(OPTION_OVERWRITE, OPTION_OVERWRITE_DESC); addOptNoArg(OPTION_CHECK, OPTION_CHECK_DESC); addOptNoArg(OPTION_DEBUG, OPTION_DEBUG_DESC); addOptWithArg(OPTION_SET, OPTION_SET_RESTORE_DESC); addOptWithArg(OPTION_TABLE, OPTION_TABLE_LIST_DESC); addOptWithArg(OPTION_TABLE_MAPPING, OPTION_TABLE_MAPPING_DESC); addOptWithArg(OPTION_YARN_QUEUE_NAME, OPTION_YARN_QUEUE_NAME_RESTORE_DESC); }
@Override public int run(String[] args) { if (conf == null) { LOG.error("Tool configuration is not initialized"); throw new NullPointerException("conf"); } CommandLine cmd; try { // parse the command line arguments cmd = parseArgs(args); cmdLineArgs = args; } catch (Exception e) { System.out.println("Error when parsing command-line arguments: " + e.getMessage()); printToolUsage(); return EXIT_FAILURE; } if (cmd.hasOption(SHORT_HELP_OPTION) || cmd.hasOption(LONG_HELP_OPTION)) { printToolUsage(); return EXIT_FAILURE; } processOptions(cmd); int ret = EXIT_FAILURE; try { ret = doWork(); } catch (Exception e) { LOG.error("Error running command-line tool", e); return EXIT_FAILURE; } return ret; }
if (!BackupManager.isBackupEnabled(getConf())) { System.err.println(BackupRestoreConstants.ENABLE_BACKUP); return -1; System.err.println("Options -s and -t are mutaully exclusive,"+ " you can not specify both of them."); printToolUsage(); return -1; printToolUsage(); return -1; printToolUsage(); return -1; String setName = cmd.getOptionValue(OPTION_SET); try { tables = getTablesForSet(conn, setName, conf); } catch (IOException e) { System.out.println("ERROR: " + e.getMessage() + " for setName=" + setName); printToolUsage(); return -2; System.out.println("ERROR: Backup set '" + setName + "' is either empty or does not exist"); printToolUsage(); return -3; (sTableArray.length != tTableArray.length)) {
protected RestoreDriver() throws IOException { init(); }
@Override protected int doWork() throws Exception { return parseAndRun(cmd.getArgs()); }
@Test public void testRestoreDriverUnrecognizedOption() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); String[] args = new String[] { "-xx" }; ToolRunner.run(conf, new RestoreDriver(), args); String output = baos.toString(); System.out.println(baos.toString()); assertTrue(output.indexOf(USAGE_RESTORE) >= 0); }
@Test public void testRestoreDriverHelp() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); String[] args = new String[] { "-help" }; ToolRunner.run(conf, new RestoreDriver(), args); String output = baos.toString(); System.out.println(baos.toString()); assertTrue(output.indexOf(USAGE_RESTORE) >= 0); assertTrue(output.indexOf(BackupRestoreConstants.OPTION_TABLE_LIST_DESC) > 0); baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); args = new String[] { "-h" }; ToolRunner.run(conf, new RestoreDriver(), args); output = baos.toString(); System.out.println(baos.toString()); assertTrue(output.indexOf(USAGE_RESTORE) >= 0); assertTrue(output.indexOf(BackupRestoreConstants.OPTION_TABLE_LIST_DESC) > 0); }
/** * Verify that restore fails on multiple tables that do not exist. * * @throws Exception if doing the backup or restoring it fails */ @Test public void testFullRestoreMultipleDNECommand() throws Exception { LOG.info("test restore fails on multiple tables that do not exist: command-line"); List<TableName> tables = Lists.newArrayList(table2, table3); String backupId = fullTableBackup(tables); assertTrue(checkSucceeded(backupId)); TableName[] restore_tableset = new TableName[] { TableName.valueOf("faketable1"), TableName.valueOf("faketable2") }; TableName[] tablemap = new TableName[] { table2_restore, table3_restore }; String[] args = new String[] { BACKUP_ROOT_DIR, backupId, StringUtils.join(restore_tableset, ","), "-m", StringUtils.join(tablemap, ",") }; // Run restore int ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret != 0); } }
/** * Verify that restore fails on a single table that does not exist. * * @throws Exception if doing the backup or restoring it fails */ @Test public void testFullRestoreSingleDNECommand() throws Exception { LOG.info("test restore fails on a single table that does not exist: command-line"); List<TableName> tables = Lists.newArrayList(table1); String backupId = fullTableBackup(tables); assertTrue(checkSucceeded(backupId)); LOG.info("backup complete"); TableName[] tableset = new TableName[] { TableName.valueOf("faketable") }; TableName[] tablemap = new TableName[] { table1_restore }; String[] args = new String[] { BACKUP_ROOT_DIR, backupId, StringUtils.join(tableset, ","), "-m", StringUtils.join(tablemap, ",") }; // Run restore int ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret != 0); }
/** * Verify that a single table is restored using overwrite. * * @throws Exception if doing the backup or an operation on the tables fails */ @Test public void testFullRestoreSingleOverwriteCommand() throws Exception { LOG.info("test full restore on a single table empty table: command-line"); List<TableName> tables = Lists.newArrayList(table1); String backupId = fullTableBackup(tables); assertTrue(checkSucceeded(backupId)); LOG.info("backup complete"); TableName[] tableset = new TableName[] { table1 }; // restore <backup_root_path> <backup_id> <tables> [tableMapping] String[] args = new String[] { BACKUP_ROOT_DIR, backupId, "-t", StringUtils.join(tableset, ","), "-o" }; // Run restore int ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertTrue(hba.tableExists(table1)); hba.close(); }
@Test public void testFullRestoreCheckCommand() throws Exception { LOG.info("test full restore on a single table: command-line, check only"); List<TableName> tables = Lists.newArrayList(table1); String backupId = fullTableBackup(tables); LOG.info("backup complete"); assertTrue(checkSucceeded(backupId)); // restore <backup_root_path> <backup_id> <tables> [tableMapping] String[] args = new String[] { BACKUP_ROOT_DIR, backupId, "-t", table1.getNameAsString(), "-m", table1_restore.getNameAsString(), "-c" }; // Run backup int ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); //Verify that table has not been restored HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertFalse(hba.tableExists(table1_restore)); }
@Test public void testFullRestoreSingleCommand() throws Exception { LOG.info("test full restore on a single table empty table: command-line"); List<TableName> tables = Lists.newArrayList(table1); String backupId = fullTableBackup(tables); LOG.info("backup complete"); assertTrue(checkSucceeded(backupId)); // restore <backup_root_path> <backup_id> <tables> [tableMapping] String[] args = new String[] { BACKUP_ROOT_DIR, backupId, "-t", table1.getNameAsString(), "-m", table1_restore.getNameAsString() }; // Run backup int ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertTrue(hba.tableExists(table1_restore)); TEST_UTIL.deleteTable(table1_restore); hba.close(); }
/** * Verify that multiple tables are restored to new tables using overwrite. * * @throws Exception if doing the backup or an operation on the tables fails */ @Test public void testFullRestoreMultipleOverwriteCommand() throws Exception { LOG.info("create full backup image on multiple tables: command-line"); List<TableName> tables = Lists.newArrayList(table2, table3); String backupId = fullTableBackup(tables); assertTrue(checkSucceeded(backupId)); TableName[] restore_tableset = new TableName[] { table2, table3 }; // restore <backup_root_path> <backup_id> <tables> [tableMapping] String[] args = new String[] { BACKUP_ROOT_DIR, backupId, "-t", StringUtils.join(restore_tableset, ","), "-o" }; // Run backup int ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertTrue(hba.tableExists(table2)); assertTrue(hba.tableExists(table3)); hba.close(); }
/** * Verify that multiple tables are restored to new tables. * * @throws Exception if doing the backup, restoring it or an operation on the tables fails */ @Test public void testFullRestoreMultipleCommand() throws Exception { LOG.info("create full backup image on multiple tables: command-line"); List<TableName> tables = Lists.newArrayList(table2, table3); String backupId = fullTableBackup(tables); assertTrue(checkSucceeded(backupId)); TableName[] restore_tableset = new TableName[] { table2, table3 }; TableName[] tablemap = new TableName[] { table2_restore, table3_restore }; // restore <backup_root_path> <backup_id> <tables> [tableMapping] String[] args = new String[] { BACKUP_ROOT_DIR, backupId, "-t", StringUtils.join(restore_tableset, ","), "-m", StringUtils.join(tablemap, ",") }; // Run backup int ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertTrue(hba.tableExists(table2_restore)); assertTrue(hba.tableExists(table3_restore)); TEST_UTIL.deleteTable(table2_restore); TEST_UTIL.deleteTable(table3_restore); hba.close(); }
ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
table1_restore.getNameAsString(), "-o" }; ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
table1_restore.getNameAsString(), "-o" }; ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();