Search in sources :

Example 11 with BackupSystemTable

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

the class TestBackupSystemTable method testBackupSetAddExistsIntersects.

@Test
public void testBackupSetAddExistsIntersects() throws IOException {
    try (BackupSystemTable table = new BackupSystemTable(conn)) {
        String[] tables = new String[] { "table1", "table2", "table3" };
        String setName = "name";
        table.addToBackupSet(setName, tables);
        String[] addTables = new String[] { "table3", "table4", "table5", "table6" };
        table.addToBackupSet(setName, addTables);
        List<TableName> tnames = table.describeBackupSet(setName);
        assertTrue(tnames != null);
        assertTrue(tnames.size() == tables.length + addTables.length - 1);
        for (int i = 0; i < tnames.size(); i++) {
            assertTrue(tnames.get(i).getNameAsString().equals("table" + (i + 1)));
        }
        cleanBackupTable();
    }
}
Also used : BackupSystemTable(org.apache.hadoop.hbase.backup.impl.BackupSystemTable) TableName(org.apache.hadoop.hbase.TableName) Test(org.junit.Test)

Example 12 with BackupSystemTable

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

the class TestBackupSystemTable method testBackupSetRemoveSomeNotExists.

@Test
public void testBackupSetRemoveSomeNotExists() throws IOException {
    try (BackupSystemTable table = new BackupSystemTable(conn)) {
        String[] tables = new String[] { "table1", "table2", "table3", "table4" };
        String setName = "name";
        table.addToBackupSet(setName, tables);
        String[] removeTables = new String[] { "table4", "table5", "table6" };
        table.removeFromBackupSet(setName, removeTables);
        List<TableName> tnames = table.describeBackupSet(setName);
        assertTrue(tnames != null);
        assertTrue(tnames.size() == tables.length - 1);
        for (int i = 0; i < tnames.size(); i++) {
            assertTrue(tnames.get(i).getNameAsString().equals("table" + (i + 1)));
        }
        cleanBackupTable();
    }
}
Also used : BackupSystemTable(org.apache.hadoop.hbase.backup.impl.BackupSystemTable) TableName(org.apache.hadoop.hbase.TableName) Test(org.junit.Test)

Example 13 with BackupSystemTable

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

the class TestFullBackup method testFullBackupMultipleCommand.

@Test
public void testFullBackupMultipleCommand() throws Exception {
    LOG.info("test full backup on a multiple tables with data: command-line");
    try (BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {
        int before = table.getBackupHistory().size();
        String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-t", table1.getNameAsString() + "," + table2.getNameAsString() };
        // Run backup
        int ret = ToolRunner.run(conf1, new BackupDriver(), args);
        assertTrue(ret == 0);
        List<BackupInfo> backups = table.getBackupHistory();
        int after = table.getBackupHistory().size();
        assertTrue(after == before + 1);
        for (BackupInfo data : backups) {
            String backupId = data.getBackupId();
            assertTrue(checkSucceeded(backupId));
        }
    }
    LOG.info("backup complete");
}
Also used : BackupSystemTable(org.apache.hadoop.hbase.backup.impl.BackupSystemTable) Test(org.junit.Test)

Example 14 with BackupSystemTable

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

the class TestFullBackupSet method testFullBackupSetExist.

/**
   * Verify that full backup is created on a single table with data correctly.
   * @throws Exception
   */
@Test
public void testFullBackupSetExist() throws Exception {
    LOG.info("Test full backup, backup set exists");
    // 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 15 with BackupSystemTable

use of org.apache.hadoop.hbase.backup.impl.BackupSystemTable 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)

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