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 SummaryFieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Loggerstatic final Stringstatic final int
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleancheckPathExist(String backupStr, org.apache.hadoop.conf.Configuration conf) Check whether the backup path existstatic voidcheckTargetDir(String backupRootPath, org.apache.hadoop.conf.Configuration conf) Check target path first, confirm it doesn't exist before backupstatic voidcleanupBackupData(BackupInfo context, org.apache.hadoop.conf.Configuration conf) private static voidcleanupHLogDir(BackupInfo backupInfo, org.apache.hadoop.conf.Configuration conf) Clean up directories which are generated when DistCp copying hlogsprivate static voidcleanupTargetDir(BackupInfo backupInfo, org.apache.hadoop.conf.Configuration conf) static voidcopyTableRegionInfo(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 BulkLoadHFilescreateLoader(org.apache.hadoop.conf.Configuration config) static RestoreRequestcreateRestoreRequest(String backupRootDir, String backupId, boolean check, TableName[] fromTables, TableName[] toTables, boolean isOverwrite) Create restore request.static booleanfailed(int result) static StringfindMostRecentBackupId(String[] backupIds) static org.apache.hadoop.fs.PathgetBulkOutputDir(String tableName, org.apache.hadoop.conf.Configuration conf, boolean deleteOnExit) static org.apache.hadoop.fs.PathgetBulkOutputDir(org.apache.hadoop.fs.Path restoreRootDir, String tableName, org.apache.hadoop.conf.Configuration conf) static org.apache.hadoop.fs.PathgetBulkOutputDir(org.apache.hadoop.fs.Path restoreRootDir, String tableName, org.apache.hadoop.conf.Configuration conf, boolean deleteOnExit) static LonggetCreationTime(org.apache.hadoop.fs.Path p) Given the log file, parse the timestamp from the file name.static StringgetFiles(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootDir, List<String> files, org.apache.hadoop.fs.PathFilter filter) static longgetFilesLength(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 StringgetLogBackupDir(String backupRootDir, String backupId) Given the backup root dir and the backup id, return the log file location for an incremental backup.static <T> LonggetMinValue(Map<T, Long> map) Get the min value for all the Values a map.static StringgetPath(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 StringgetTableBackupDir(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.PathgetTmpRestoreOutputDir(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.conf.Configuration conf) Build temporary output pathstatic StringgetUniqueWALFileNamePart(String walFileName) Returns WAL file namestatic StringgetUniqueWALFileNamePart(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 BackupInfoloadBackupInfo(org.apache.hadoop.fs.Path backupRootPath, String backupId, org.apache.hadoop.fs.FileSystem fs) static StringparseHostFromOldLog(org.apache.hadoop.fs.Path p) Parses host name:port from archived WAL pathstatic StringparseHostNameFromLogFile(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 booleansucceeded(int result) static booleanvalidate(HashMap<TableName, BackupManifest> backupManifestMap, org.apache.hadoop.conf.Configuration conf) static voidwriteRegioninfoOnFilesystem(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- 
BackupUtilsprivate BackupUtils()
 
- 
- 
Method Details- 
getRSLogTimestampMinspublic 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
 
- 
copyTableRegionInfopublic 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- connection
- backupInfo- backup info
- conf- configuration
- Throws:
- IOException- exception
 
- 
writeRegioninfoOnFilesystempublic 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
 
- 
parseHostNameFromLogFileParses hostname:port from WAL file path- Parameters:
- p- path to WAL file
- Returns:
- hostname:port
 
- 
getUniqueWALFileNamePartReturns WAL file name- Parameters:
- walFileName- WAL file name
- Returns:
- WAL file name
 
- 
getUniqueWALFileNamePartReturns WAL file name- Parameters:
- p- WAL file path
- Returns:
- WAL file name
 
- 
getFilesLengthpublic 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 system
- dir- The target directory
- Returns:
- the total length of files
- Throws:
- IOException- exception
 
- 
getWALFilesOlderThanpublic 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- configuration
- hostTimestampMap- {host,timestamp} map
- Returns:
- list of WAL files
- Throws:
- IOException- exception
 
- 
parseTableNames
- 
checkPathExistpublic static boolean checkPathExist(String backupStr, org.apache.hadoop.conf.Configuration conf) throws IOException Check whether the backup path exist- Parameters:
- backupStr- backup
- conf- configuration
- Returns:
- Yes if path exists
- Throws:
- IOException- exception
 
- 
checkTargetDirpublic 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 path
- conf- configuration
- Throws:
- IOException- exception
 
- 
getMinValueGet the min value for all the Values a map.- Parameters:
- map- map
- Returns:
- the min value
 
- 
parseHostFromOldLogParses host name:port from archived WAL path- Parameters:
- p- path
- Returns:
- host name
 
- 
getCreationTimeGiven 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
 
- 
getFilespublic 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
 
- 
cleanupBackupDatapublic static void cleanupBackupData(BackupInfo context, org.apache.hadoop.conf.Configuration conf) throws IOException - Throws:
- IOException
 
- 
cleanupHLogDirprivate 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 info
- conf- configuration
- Throws:
- IOException- exception
 
- 
cleanupTargetDirprivate static void cleanupTargetDir(BackupInfo backupInfo, org.apache.hadoop.conf.Configuration conf) 
- 
getTableBackupDirGiven 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 directory
- backupId- backup id
- tableName- table name
- Returns:
- backupPath String for the particular table
 
- 
sortHistoryListDescSort history list by start time in descending order.- Parameters:
- historyList- history list
- Returns:
- sorted list of BackupCompleteData
 
- 
listStatuspublic 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 system
- dir- directory
- filter- path filter
- Returns:
- null if dir is empty or doesn't exist, otherwise FileStatus array
- Throws:
- IOException
 
- 
getPathReturn 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
 
- 
getLogBackupDirGiven the backup root dir and the backup id, return the log file location for an incremental backup.- Parameters:
- backupRootDir- backup root directory
- backupId- backup id
- Returns:
- logBackupDir: ".../user/biadmin/backup1/WALs/backup_1396650096738"
 
- 
getHistoryprivate static List<BackupInfo> getHistory(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.Path backupRootPath) throws IOException - Throws:
- IOException
 
- 
getHistorypublic 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
 
- 
loadBackupInfopublic static BackupInfo loadBackupInfo(org.apache.hadoop.fs.Path backupRootPath, String backupId, org.apache.hadoop.fs.FileSystem fs) throws IOException - Throws:
- IOException
 
- 
createRestoreRequestpublic static RestoreRequest createRestoreRequest(String backupRootDir, String backupId, boolean check, TableName[] fromTables, TableName[] toTables, boolean isOverwrite) Create restore request.- Parameters:
- backupRootDir- backup root dir
- backupId- backup id
- check- check only
- fromTables- table list from
- toTables- table list to
- isOverwrite- overwrite data
- Returns:
- request obkect
 
- 
validatepublic static boolean validate(HashMap<TableName, BackupManifest> backupManifestMap, org.apache.hadoop.conf.Configuration conf) throws IOException- Throws:
- IOException
 
- 
getBulkOutputDirpublic 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
 
- 
getBulkOutputDirpublic 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
 
- 
getBulkOutputDirpublic static org.apache.hadoop.fs.Path getBulkOutputDir(String tableName, org.apache.hadoop.conf.Configuration conf, boolean deleteOnExit) throws IOException - Throws:
- IOException
 
- 
getTmpRestoreOutputDirpublic 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 dir
- conf- configuration
- Returns:
- output path
 
- 
getFileNameCompatibleString
- 
failed
- 
succeeded
- 
createLoader
- 
findMostRecentBackupId
 
-