Search in sources :

Example 16 with BackupSystemTable

use of org.apache.hadoop.hbase.backup.impl.BackupSystemTable 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();
    }
}
Also used : BackupSystemTable(org.apache.hadoop.hbase.backup.impl.BackupSystemTable) TableName(org.apache.hadoop.hbase.TableName) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) Test(org.junit.Test)

Example 17 with BackupSystemTable

use of org.apache.hadoop.hbase.backup.impl.BackupSystemTable in project hbase by apache.

the class TestBackupDelete method testBackupDelete.

/**
   * Verify that full backup is created on a single table with data correctly. Verify that history
   * works as expected
   * @throws Exception
   */
@Test
public void testBackupDelete() throws Exception {
    LOG.info("test backup delete on a single table with data");
    List<TableName> tableList = Lists.newArrayList(table1);
    String backupId = fullTableBackup(tableList);
    assertTrue(checkSucceeded(backupId));
    LOG.info("backup complete");
    String[] backupIds = new String[] { backupId };
    BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection());
    BackupInfo info = table.readBackupInfo(backupId);
    Path path = new Path(info.getBackupRootDir(), backupId);
    FileSystem fs = FileSystem.get(path.toUri(), conf1);
    assertTrue(fs.exists(path));
    int deleted = getBackupAdmin().deleteBackups(backupIds);
    assertTrue(!fs.exists(path));
    assertTrue(fs.exists(new Path(info.getBackupRootDir())));
    assertTrue(1 == deleted);
    table.close();
    LOG.info("delete_backup");
}
Also used : BackupSystemTable(org.apache.hadoop.hbase.backup.impl.BackupSystemTable) Path(org.apache.hadoop.fs.Path) TableName(org.apache.hadoop.hbase.TableName) FileSystem(org.apache.hadoop.fs.FileSystem) Test(org.junit.Test)

Aggregations

BackupSystemTable (org.apache.hadoop.hbase.backup.impl.BackupSystemTable)17 Test (org.junit.Test)16 TableName (org.apache.hadoop.hbase.TableName)13 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)3 FileStatus (org.apache.hadoop.fs.FileStatus)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)1 Path (org.apache.hadoop.fs.Path)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 Connection (org.apache.hadoop.hbase.client.Connection)1 HTable (org.apache.hadoop.hbase.client.HTable)1 Put (org.apache.hadoop.hbase.client.Put)1