1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.backup;
19
20 import static org.junit.Assert.assertTrue;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.hadoop.hbase.TableName;
28 import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
29 import org.apache.hadoop.hbase.testclassification.LargeTests;
30 import org.apache.hadoop.util.ToolRunner;
31 import org.junit.Test;
32 import org.junit.experimental.categories.Category;
33
34 import com.google.common.collect.Lists;
35
36 @Category(LargeTests.class)
37 public class TestFullBackup extends TestBackupBase {
38
39 private static final Log LOG = LogFactory.getLog(TestFullBackup.class);
40
41
42
43
44
45 @Test
46 public void testFullBackupSingle() throws Exception {
47 LOG.info("test full backup on a single table with data");
48 List<TableName> tables = Lists.newArrayList(table1);
49 String backupId = fullTableBackup(tables);
50 assertTrue(checkSucceeded(backupId));
51 LOG.info("backup complete for " + backupId);
52 }
53
54
55
56
57
58 @Test
59 public void testFullBackupSingleCommand() throws Exception {
60 LOG.info("test full backup on a single table with data: command-line");
61 try(BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {
62 int before = table.getBackupHistory().size();
63 String[] args = new String[]{"create", "full", BACKUP_ROOT_DIR, table1.getNameAsString() };
64
65 int ret = ToolRunner.run(conf1, new BackupDriver(), args);
66 assertTrue(ret == 0);
67 ArrayList<BackupInfo> backups = table.getBackupHistory();
68 int after = table.getBackupHistory().size();
69 assertTrue(after == before +1);
70 for(BackupInfo data : backups){
71 String backupId = data.getBackupId();
72 assertTrue(checkSucceeded(backupId));
73 }
74 }
75 LOG.info("backup complete");
76 }
77
78
79
80
81
82
83 @Test
84 public void testFullBackupMultiple() throws Exception {
85 LOG.info("create full backup image on multiple tables with data");
86 List<TableName> tables = Lists.newArrayList(table1, table1);
87 String backupId = fullTableBackup(tables);
88 assertTrue(checkSucceeded(backupId));
89 }
90
91 @Test
92 public void testFullBackupMultipleCommand() throws Exception {
93 LOG.info("test full backup on a multiple tables with data: command-line");
94 try(BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {
95 int before = table.getBackupHistory().size();
96 String[] args = new String[]{"create", "full", BACKUP_ROOT_DIR,
97 table1.getNameAsString() +","+ table2.getNameAsString() };
98
99 int ret = ToolRunner.run(conf1, new BackupDriver(), args);
100 assertTrue(ret == 0);
101 ArrayList<BackupInfo> backups = table.getBackupHistory();
102 int after = table.getBackupHistory().size();
103 assertTrue(after == before +1);
104 for(BackupInfo data : backups){
105 String backupId = data.getBackupId();
106 assertTrue(checkSucceeded(backupId));
107 }
108 }
109 LOG.info("backup complete");
110 }
111
112
113
114
115 @Test
116 public void testFullBackupAll() throws Exception {
117 LOG.info("create full backup image on all tables");
118 String backupId = fullTableBackup(null);
119 assertTrue(checkSucceeded(backupId));
120
121 }
122
123 @Test
124 public void testFullBackupAllCommand() throws Exception {
125 LOG.info("create full backup image on all tables: command-line");
126 try(BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {
127 int before = table.getBackupHistory().size();
128 String[] args = new String[]{"create", "full", BACKUP_ROOT_DIR };
129
130 int ret = ToolRunner.run(conf1, new BackupDriver(), args);
131 assertTrue(ret == 0);
132 ArrayList<BackupInfo> backups = table.getBackupHistory();
133 int after = table.getBackupHistory().size();
134 assertTrue(after == before +1);
135 for(BackupInfo data : backups){
136 String backupId = data.getBackupId();
137 assertTrue(checkSucceeded(backupId));
138 }
139 }
140 }
141 }