use of org.apache.hadoop.hbase.client.HBaseAdmin in project hbase by apache.
the class TestFullBackupSetRestoreSet method testFullRestoreSetToSameTable.
@Test
public void testFullRestoreSetToSameTable() throws Exception {
LOG.info("Test full restore set to same table");
// Create set
try (BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {
String name = "name1";
table.addToBackupSet(name, new String[] { table1.getNameAsString() });
List<TableName> names = table.describeBackupSet(name);
assertNotNull(names);
assertTrue(names.size() == 1);
assertTrue(names.get(0).equals(table1));
String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-s", name };
// Run backup
int ret = ToolRunner.run(conf1, new BackupDriver(), args);
assertTrue(ret == 0);
List<BackupInfo> backups = table.getBackupHistory();
String backupId = backups.get(0).getBackupId();
assertTrue(checkSucceeded(backupId));
LOG.info("backup complete");
int count = TEST_UTIL.countRows(table1);
TEST_UTIL.deleteTable(table1);
// Restore from set into other table
args = new String[] { BACKUP_ROOT_DIR, backupId, "-s", name, "-o" };
// Run backup
ret = ToolRunner.run(conf1, new RestoreDriver(), args);
assertTrue(ret == 0);
HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
assertTrue(hba.tableExists(table1));
// Verify number of rows in both tables
assertEquals(count, TEST_UTIL.countRows(table1));
LOG.info("restore into same table is complete");
hba.close();
}
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project hbase by apache.
the class TestFullBackupSetRestoreSet method testFullRestoreSetToOtherTable.
@Test
public void testFullRestoreSetToOtherTable() throws Exception {
LOG.info("Test full restore set");
// Create set
try (BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {
String name = "name";
table.addToBackupSet(name, new String[] { table1.getNameAsString() });
List<TableName> names = table.describeBackupSet(name);
assertNotNull(names);
assertTrue(names.size() == 1);
assertTrue(names.get(0).equals(table1));
String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-s", name };
// Run backup
int ret = ToolRunner.run(conf1, new BackupDriver(), args);
assertTrue(ret == 0);
List<BackupInfo> backups = table.getBackupHistory();
assertTrue(backups.size() == 1);
String backupId = backups.get(0).getBackupId();
assertTrue(checkSucceeded(backupId));
LOG.info("backup complete");
// Restore from set into other table
args = new String[] { BACKUP_ROOT_DIR, backupId, "-s", name, "-m", table1_restore.getNameAsString(), "-o" };
// Run backup
ret = ToolRunner.run(conf1, new RestoreDriver(), args);
assertTrue(ret == 0);
HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
assertTrue(hba.tableExists(table1_restore));
// Verify number of rows in both tables
assertEquals(TEST_UTIL.countRows(table1), TEST_UTIL.countRows(table1_restore));
TEST_UTIL.deleteTable(table1_restore);
LOG.info("restore into other table is complete");
hba.close();
}
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project hbase by apache.
the class TestFullRestore method testFullRestoreCheckCommand.
@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));
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project hbase by apache.
the class TestFullRestore method testFullRestoreSingleCommand.
@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();
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project hbase by apache.
the class TestFullRestore method testFullRestoreMultipleCommand.
/**
* Verify that multiple tables are restored to new tables.
* @throws Exception
*/
@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();
}
Aggregations