For more information about how to use the Export and Import functions of HBase to complete backup, see my previous HBase Incremental backup.
Reprint the Python code that regularly backs up data using Export and Import. Complete backup is performed on the 15th day of every month, and Incremental backup is performed on a daily basis.
Import time
Import datetime
From datetime import date
Import sys
Import OS
Tablename = sys. argv [1]
BackupDst = sys. argv [2]
Today = date. today ()
If today. day = 15: // every month, we do a full backup
BackupSubFolder = backupDst + today. isoformat () + "-full"
Cmd = "hbase org. apache. Hadoop. hbase. mapreduce. Export % s" % (tablename, backupSubFolder)
Else:
Yesterday = datetime. date. today ()-datetime. timedelta (days = 1)
TodayTimeStamp = time. mktime (today. timetuple ())
YesTimeStamp = time. mktime (yesterday. timetuple ())
BackupSubFolder = backupDst + today. isoformat ()
Cmd = "hbase org. apache. hadoop. hbase. mapreduce. Export % s" % (tablename, backupSubFolder, str (int (todayTimeStamp) * 1000)
Print cmd
OS. system (cmd)
Note that the last cmd string is constructed, and the version number is added to the corresponding location according to the HBase version.