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.
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.
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)
Pay attention to the final cmd string construction, and add the version number based on the HBase version.