Search in sources :

Example 96 with HBaseAdmin

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();
    }
}
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 97 with HBaseAdmin

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();
    }
}
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 98 with HBaseAdmin

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

Example 99 with HBaseAdmin

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

Example 100 with HBaseAdmin

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

Aggregations

HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)180 Test (org.junit.Test)93 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)76 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)72 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)70 Connection (java.sql.Connection)66 Properties (java.util.Properties)54 TableName (org.apache.hadoop.hbase.TableName)36 IOException (java.io.IOException)33 ResultSet (java.sql.ResultSet)27 BaseTest (org.apache.phoenix.query.BaseTest)27 HTable (org.apache.hadoop.hbase.client.HTable)26 SQLException (java.sql.SQLException)22 TestUtil.closeConnection (org.apache.phoenix.util.TestUtil.closeConnection)22 Put (org.apache.hadoop.hbase.client.Put)16 Configuration (org.apache.hadoop.conf.Configuration)13 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)13 PreparedStatement (java.sql.PreparedStatement)12 PhoenixIOException (org.apache.phoenix.exception.PhoenixIOException)12 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)9