1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.backup;
21
22 import java.io.IOException;
23 import java.util.HashMap;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.fs.FileSystem;
29 import org.apache.hadoop.fs.Path;
30 import org.apache.hadoop.hbase.HConstants;
31 import org.apache.hadoop.hbase.TableName;
32 import org.apache.hadoop.hbase.backup.impl.BackupManifest;
33 import org.apache.hadoop.hbase.classification.InterfaceAudience;
34 import org.apache.hadoop.hbase.classification.InterfaceStability;
35
36
37
38
39
40 @InterfaceAudience.Private
41 @InterfaceStability.Evolving
42 public class HBackupFileSystem {
43 public static final Log LOG = LogFactory.getLog(HBackupFileSystem.class);
44
45
46
47
48 private HBackupFileSystem() {
49 }
50
51
52
53
54
55
56
57
58
59
60 public static String getTableBackupDir(String backupRootDir, String backupId,
61 TableName tableName) {
62 return backupRootDir + Path.SEPARATOR+ backupId + Path.SEPARATOR +
63 tableName.getNamespaceAsString() + Path.SEPARATOR
64 + tableName.getQualifierAsString() + Path.SEPARATOR ;
65 }
66
67
68
69
70
71
72
73
74
75
76 public static Path getTableBackupPath(TableName tableName, Path backupRootPath, String backupId) {
77 return new Path(getTableBackupDir(backupRootPath.toString(), backupId, tableName));
78 }
79
80
81
82
83
84
85
86
87 public static String getLogBackupDir(String backupRootDir, String backupId) {
88 return backupRootDir + Path.SEPARATOR + backupId+ Path.SEPARATOR
89 + HConstants.HREGION_LOGDIR_NAME;
90 }
91
92 public static Path getLogBackupPath(String backupRootDir, String backupId) {
93 return new Path(getLogBackupDir(backupRootDir, backupId));
94 }
95
96 private static Path getManifestPath(TableName tableName, Configuration conf,
97 Path backupRootPath, String backupId) throws IOException {
98 Path manifestPath = new Path(getTableBackupPath(tableName, backupRootPath, backupId),
99 BackupManifest.MANIFEST_FILE_NAME);
100 FileSystem fs = backupRootPath.getFileSystem(conf);
101 if (!fs.exists(manifestPath)) {
102
103 manifestPath =
104 new Path(getLogBackupDir(backupRootPath.toString(), backupId) + Path.SEPARATOR
105 + BackupManifest.MANIFEST_FILE_NAME);
106 if (!fs.exists(manifestPath)) {
107 String errorMsg =
108 "Could not find backup manifest " + BackupManifest.MANIFEST_FILE_NAME + " for " +
109 backupId + " in " + backupRootPath.toString() +
110 ". Did " + backupId + " correspond to previously taken backup ?";
111 throw new IOException(errorMsg);
112 }
113 }
114 return manifestPath;
115 }
116
117 public static BackupManifest getManifest(TableName tableName, Configuration conf,
118 Path backupRootPath, String backupId) throws IOException {
119 BackupManifest manifest = new BackupManifest(conf,
120 getManifestPath(tableName, conf, backupRootPath, backupId));
121 return manifest;
122 }
123
124
125
126
127
128
129
130 public static void checkImageManifestExist(HashMap<TableName, BackupManifest> backupManifestMap,
131 TableName[] tableArray, Configuration conf,
132 Path backupRootPath, String backupId) throws IOException {
133 for (TableName tableName : tableArray) {
134 BackupManifest manifest = getManifest(tableName, conf, backupRootPath, backupId);
135 backupManifestMap.put(tableName, manifest);
136 }
137 }
138 }