Class BackupUtils
java.lang.Object
org.apache.hadoop.hbase.backup.util.BackupUtils
A collection for methods used by multiple classes to backup HBase tables.
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final org.slf4j.Logger
static final String
static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
checkPathExist
(String backupStr, org.apache.hadoop.conf.Configuration conf) Check whether the backup path existstatic void
checkTargetDir
(String backupRootPath, org.apache.hadoop.conf.Configuration conf) Check target path first, confirm it doesn't exist before backupstatic void
cleanupBackupData
(BackupInfo context, org.apache.hadoop.conf.Configuration conf) private static void
cleanupHLogDir
(BackupInfo backupInfo, org.apache.hadoop.conf.Configuration conf) Clean up directories which are generated when DistCp copying hlogsprivate static void
cleanupTargetDir
(BackupInfo backupInfo, org.apache.hadoop.conf.Configuration conf) static void
copyTableRegionInfo
(Connection conn, BackupInfo backupInfo, org.apache.hadoop.conf.Configuration conf) copy out Table RegionInfo into incremental backup image need to consider move this logic into HBackupFileSystemstatic BulkLoadHFiles
createLoader
(org.apache.hadoop.conf.Configuration config) static RestoreRequest
createRestoreRequest
(String backupRootDir, String backupId, boolean check, TableName[] fromTables, TableName[] toTables, boolean isOverwrite) Create restore request.static boolean
failed
(int result) static String
findMostRecentBackupId
(String[] backupIds) static org.apache.hadoop.fs.Path
getBulkOutputDir
(String tableName, org.apache.hadoop.conf.Configuration conf, boolean deleteOnExit) static org.apache.hadoop.fs.Path
getBulkOutputDir
(org.apache.hadoop.fs.Path restoreRootDir, String tableName, org.apache.hadoop.conf.Configuration conf) static org.apache.hadoop.fs.Path
getBulkOutputDir
(org.apache.hadoop.fs.Path restoreRootDir, String tableName, org.apache.hadoop.conf.Configuration conf, boolean deleteOnExit) static Long
getCreationTime
(org.apache.hadoop.fs.Path p) Given the log file, parse the timestamp from the file name.static String
getFiles
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootDir, List<String> files, org.apache.hadoop.fs.PathFilter filter) static long
getFilesLength
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir) Get the total length of files under the given directory recursively.static List<BackupInfo>
getHistory
(org.apache.hadoop.conf.Configuration conf, int n, org.apache.hadoop.fs.Path backupRootPath, BackupInfo.Filter... filters) private static List<BackupInfo>
getHistory
(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.Path backupRootPath) static String
getLogBackupDir
(String backupRootDir, String backupId) Given the backup root dir and the backup id, return the log file location for an incremental backup.static <T> Long
getMinValue
(Map<T, Long> map) Get the min value for all the Values a map.static String
getPath
(org.apache.hadoop.fs.Path p) Return the 'path' component of a Path.Loop through the RS log timestamp map for the tables, for each RS, find the min timestamp value for the RS among the tables.static String
getTableBackupDir
(String backupRootDir, String backupId, TableName tableName) Given the backup root dir, backup id and the table name, return the backup image location, which is also where the backup manifest file is.static org.apache.hadoop.fs.Path
getTmpRestoreOutputDir
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.conf.Configuration conf) Build temporary output pathstatic String
getUniqueWALFileNamePart
(String walFileName) Returns WAL file namestatic String
getUniqueWALFileNamePart
(org.apache.hadoop.fs.Path p) Returns WAL file namegetWALFilesOlderThan
(org.apache.hadoop.conf.Configuration c, HashMap<String, Long> hostTimestampMap) Get list of all old WAL files (WALs and archive)static org.apache.hadoop.fs.FileStatus[]
listStatus
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, org.apache.hadoop.fs.PathFilter filter) Calls fs.listStatus() and treats FileNotFoundException as non-fatal This accommodates differences between hadoop versions, where hadoop 1 does not throw a FileNotFoundException, and return an empty FileStatus[] while Hadoop 2 will throw FileNotFoundException.static BackupInfo
loadBackupInfo
(org.apache.hadoop.fs.Path backupRootPath, String backupId, org.apache.hadoop.fs.FileSystem fs) static String
parseHostFromOldLog
(org.apache.hadoop.fs.Path p) Parses host name:port from archived WAL pathstatic String
parseHostNameFromLogFile
(org.apache.hadoop.fs.Path p) Parses hostname:port from WAL file pathstatic TableName[]
parseTableNames
(String tables) static ArrayList<BackupInfo>
sortHistoryListDesc
(ArrayList<BackupInfo> historyList) Sort history list by start time in descending order.static boolean
succeeded
(int result) static boolean
validate
(List<TableName> tables, BackupManifest backupManifest, org.apache.hadoop.conf.Configuration conf) static void
writeRegioninfoOnFilesystem
(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path regionInfoDir, RegionInfo regionInfo) Write the .regioninfo file on-disk.
-
Field Details
-
LOG
-
LOGNAME_SEPARATOR
- See Also:
-
MILLISEC_IN_HOUR
- See Also:
-
-
Constructor Details
-
BackupUtils
private BackupUtils()
-
-
Method Details
-
getRSLogTimestampMins
public static Map<String,Long> getRSLogTimestampMins(Map<TableName, Map<String, Long>> rsLogTimestampMap) Loop through the RS log timestamp map for the tables, for each RS, find the min timestamp value for the RS among the tables.- Parameters:
rsLogTimestampMap
- timestamp map- Returns:
- the min timestamp of each RS
-
copyTableRegionInfo
public static void copyTableRegionInfo(Connection conn, BackupInfo backupInfo, org.apache.hadoop.conf.Configuration conf) throws IOException copy out Table RegionInfo into incremental backup image need to consider move this logic into HBackupFileSystem- Parameters:
conn
- connectionbackupInfo
- backup infoconf
- configuration- Throws:
IOException
- exception
-
writeRegioninfoOnFilesystem
public static void writeRegioninfoOnFilesystem(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path regionInfoDir, RegionInfo regionInfo) throws IOException Write the .regioninfo file on-disk.- Throws:
IOException
-
parseHostNameFromLogFile
Parses hostname:port from WAL file path- Parameters:
p
- path to WAL file- Returns:
- hostname:port
-
getUniqueWALFileNamePart
Returns WAL file name- Parameters:
walFileName
- WAL file name- Returns:
- WAL file name
-
getUniqueWALFileNamePart
Returns WAL file name- Parameters:
p
- WAL file path- Returns:
- WAL file name
-
getFilesLength
public static long getFilesLength(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir) throws IOException Get the total length of files under the given directory recursively.- Parameters:
fs
- The hadoop file systemdir
- The target directory- Returns:
- the total length of files
- Throws:
IOException
- exception
-
getWALFilesOlderThan
public static List<String> getWALFilesOlderThan(org.apache.hadoop.conf.Configuration c, HashMap<String, Long> hostTimestampMap) throws IOExceptionGet list of all old WAL files (WALs and archive)- Parameters:
c
- configurationhostTimestampMap
- {host,timestamp} map- Returns:
- list of WAL files
- Throws:
IOException
- exception
-
parseTableNames
-
checkPathExist
public static boolean checkPathExist(String backupStr, org.apache.hadoop.conf.Configuration conf) throws IOException Check whether the backup path exist- Parameters:
backupStr
- backupconf
- configuration- Returns:
- Yes if path exists
- Throws:
IOException
- exception
-
checkTargetDir
public static void checkTargetDir(String backupRootPath, org.apache.hadoop.conf.Configuration conf) throws IOException Check target path first, confirm it doesn't exist before backup- Parameters:
backupRootPath
- backup destination pathconf
- configuration- Throws:
IOException
- exception
-
getMinValue
Get the min value for all the Values a map.- Parameters:
map
- map- Returns:
- the min value
-
parseHostFromOldLog
Parses host name:port from archived WAL path- Parameters:
p
- path- Returns:
- host name
-
getCreationTime
Given the log file, parse the timestamp from the file name. The timestamp is the last number.- Parameters:
p
- a path to the log file- Returns:
- the timestamp
- Throws:
IOException
- exception
-
getFiles
public static List<String> getFiles(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootDir, List<String> files, org.apache.hadoop.fs.PathFilter filter) throws IOException - Throws:
IOException
-
cleanupBackupData
public static void cleanupBackupData(BackupInfo context, org.apache.hadoop.conf.Configuration conf) throws IOException - Throws:
IOException
-
cleanupHLogDir
private static void cleanupHLogDir(BackupInfo backupInfo, org.apache.hadoop.conf.Configuration conf) throws IOException Clean up directories which are generated when DistCp copying hlogs- Parameters:
backupInfo
- backup infoconf
- configuration- Throws:
IOException
- exception
-
cleanupTargetDir
private static void cleanupTargetDir(BackupInfo backupInfo, org.apache.hadoop.conf.Configuration conf) -
getTableBackupDir
Given the backup root dir, backup id and the table name, return the backup image location, which is also where the backup manifest file is. return value look like: "hdfs://backup.hbase.org:9000/user/biadmin/backup1/backup_1396650096738/default/t1_dn/"- Parameters:
backupRootDir
- backup root directorybackupId
- backup idtableName
- table name- Returns:
- backupPath String for the particular table
-
sortHistoryListDesc
Sort history list by start time in descending order.- Parameters:
historyList
- history list- Returns:
- sorted list of BackupCompleteData
-
listStatus
public static org.apache.hadoop.fs.FileStatus[] listStatus(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, org.apache.hadoop.fs.PathFilter filter) throws IOException Calls fs.listStatus() and treats FileNotFoundException as non-fatal This accommodates differences between hadoop versions, where hadoop 1 does not throw a FileNotFoundException, and return an empty FileStatus[] while Hadoop 2 will throw FileNotFoundException.- Parameters:
fs
- file systemdir
- directoryfilter
- path filter- Returns:
- null if dir is empty or doesn't exist, otherwise FileStatus array
- Throws:
IOException
-
getPath
Return the 'path' component of a Path. In Hadoop, Path is a URI. This method returns the 'path' component of a Path's URI: e.g. If a Path ishdfs://example.org:9000/hbase_trunk/TestTable/compaction.dir
, this method returns/hbase_trunk/TestTable/compaction.dir
. This method is useful if you want to print out a Path without qualifying Filesystem instance.- Parameters:
p
- file system Path whose 'path' component we are to return.- Returns:
- Path portion of the Filesystem
-
getLogBackupDir
Given the backup root dir and the backup id, return the log file location for an incremental backup.- Parameters:
backupRootDir
- backup root directorybackupId
- backup id- Returns:
- logBackupDir: ".../user/biadmin/backup1/WALs/backup_1396650096738"
-
getHistory
private static List<BackupInfo> getHistory(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.Path backupRootPath) throws IOException - Throws:
IOException
-
getHistory
public static List<BackupInfo> getHistory(org.apache.hadoop.conf.Configuration conf, int n, org.apache.hadoop.fs.Path backupRootPath, BackupInfo.Filter... filters) throws IOException - Throws:
IOException
-
loadBackupInfo
public static BackupInfo loadBackupInfo(org.apache.hadoop.fs.Path backupRootPath, String backupId, org.apache.hadoop.fs.FileSystem fs) throws IOException - Throws:
IOException
-
createRestoreRequest
public static RestoreRequest createRestoreRequest(String backupRootDir, String backupId, boolean check, TableName[] fromTables, TableName[] toTables, boolean isOverwrite) Create restore request.- Parameters:
backupRootDir
- backup root dirbackupId
- backup idcheck
- check onlyfromTables
- table list fromtoTables
- table list toisOverwrite
- overwrite data- Returns:
- request obkect
-
validate
public static boolean validate(List<TableName> tables, BackupManifest backupManifest, org.apache.hadoop.conf.Configuration conf) throws IOException - Throws:
IOException
-
getBulkOutputDir
public static org.apache.hadoop.fs.Path getBulkOutputDir(org.apache.hadoop.fs.Path restoreRootDir, String tableName, org.apache.hadoop.conf.Configuration conf, boolean deleteOnExit) throws IOException - Throws:
IOException
-
getBulkOutputDir
public static org.apache.hadoop.fs.Path getBulkOutputDir(org.apache.hadoop.fs.Path restoreRootDir, String tableName, org.apache.hadoop.conf.Configuration conf) throws IOException - Throws:
IOException
-
getBulkOutputDir
public static org.apache.hadoop.fs.Path getBulkOutputDir(String tableName, org.apache.hadoop.conf.Configuration conf, boolean deleteOnExit) throws IOException - Throws:
IOException
-
getTmpRestoreOutputDir
public static org.apache.hadoop.fs.Path getTmpRestoreOutputDir(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.conf.Configuration conf) Build temporary output path- Parameters:
fs
- filesystem for default output dirconf
- configuration- Returns:
- output path
-
getFileNameCompatibleString
-
failed
-
succeeded
-
createLoader
-
findMostRecentBackupId
-