1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.backup;
20
21 import static org.junit.Assert.*;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
30 import org.apache.hadoop.hbase.client.HBaseAdmin;
31 import org.apache.hadoop.hbase.testclassification.LargeTests;
32 import org.apache.hadoop.util.ToolRunner;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35
36 @Category(LargeTests.class)
37 public class TestFullBackupSetRestoreSet extends TestBackupBase {
38
39 private static final Log LOG = LogFactory.getLog(TestFullBackupSetRestoreSet.class);
40
41 @Test
42 public void testFullRestoreSetToOtherTable() throws Exception {
43
44 LOG.info("Test full restore set");
45
46
47 try (BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {
48 String name = "name";
49 table.addToBackupSet(name, new String[] { table1.getNameAsString() });
50 List<TableName> names = table.describeBackupSet(name);
51
52 assertNotNull(names);
53 assertTrue(names.size() == 1);
54 assertTrue(names.get(0).equals(table1));
55
56 String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-set", name };
57
58 int ret = ToolRunner.run(conf1, new BackupDriver(), args);
59 assertTrue(ret == 0);
60 ArrayList<BackupInfo> backups = table.getBackupHistory();
61 assertTrue(backups.size() == 1);
62 String backupId = backups.get(0).getBackupId();
63 assertTrue(checkSucceeded(backupId));
64
65 LOG.info("backup complete");
66
67
68 args =
69 new String[] { BACKUP_ROOT_DIR, backupId, "-set", name, table1_restore.getNameAsString(),
70 "-overwrite" };
71
72 ret = ToolRunner.run(conf1, new RestoreDriver(), args);
73 assertTrue(ret == 0);
74 HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
75 assertTrue(hba.tableExists(table1_restore));
76
77 assertEquals(TEST_UTIL.countRows(table1), TEST_UTIL.countRows(table1_restore));
78 TEST_UTIL.deleteTable(table1_restore);
79 LOG.info("restore into other table is complete");
80 hba.close();
81 }
82 }
83
84 @Test
85 public void testFullRestoreSetToSameTable() throws Exception {
86
87 LOG.info("Test full restore set to same table");
88
89
90 try (BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {
91 String name = "name1";
92 table.addToBackupSet(name, new String[] { table1.getNameAsString() });
93 List<TableName> names = table.describeBackupSet(name);
94
95 assertNotNull(names);
96 assertTrue(names.size() == 1);
97 assertTrue(names.get(0).equals(table1));
98
99 String[] args = new String[] { "create", "full", BACKUP_ROOT_DIR, "-set", name };
100
101 int ret = ToolRunner.run(conf1, new BackupDriver(), args);
102 assertTrue(ret == 0);
103 ArrayList<BackupInfo> backups = table.getBackupHistory();
104 String backupId = backups.get(0).getBackupId();
105 assertTrue(checkSucceeded(backupId));
106
107 LOG.info("backup complete");
108 int count = TEST_UTIL.countRows(table1);
109 TEST_UTIL.deleteTable(table1);
110
111
112 args = new String[] { BACKUP_ROOT_DIR, backupId, "-set", name, "-overwrite" };
113
114 ret = ToolRunner.run(conf1, new RestoreDriver(), args);
115 assertTrue(ret == 0);
116 HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
117 assertTrue(hba.tableExists(table1));
118
119 assertEquals(count, TEST_UTIL.countRows(table1));
120 LOG.info("restore into same table is complete");
121 hba.close();
122
123 }
124
125 }
126
127 }