Python script for incremental backups of HBase
This article will explain in detail the python script about how to incrementally back up HBase. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
The export/import mechanism of HBase can realize the function of BackupRestore. And incremental backup can be implemented.
Python script for how HBase incrementally backs up
In this script, do an incremental backup every day and a full backup on the 15th of each month.
Importtime importdatetime fromdatetimeimportdate importsys importos tablename=sys.argv [1] backupDst=sys.argv [2] today=date.today () iftoday.day==15://everymonth,wedoafullbackup backupSubFolder=backupDst+today.isoformat () + "- full" cmd= "hbaseorg.apache.hadoop.hbase.mapreduce.Export%s%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= "hbaseorg.apache.hadoop.hbase.mapreduce.Export%s%s%s"% (tablename,backupSubFolder,str (int (todayTimeStamp) * 1000) printcmd os.system (cmd)
Python script for how HBase incrementally backs up
And the Restore mechanism is even simpler.
Hbaseorg.apache.hadoop.hbase.mapreduce.Importtablenamerestorefolder
It is important to note that when doing Restore, the original table must be created. So if the table itself is corrupted, you need to recreate a new empty table and Restore it.
Also, the paths to hbase and Zookeeper must be configured in Hadoop-env.sh, with statements like this
ExportHADOOP_CLASSPATH= "/ usr/lib/hadoop-hbase/hbaseXXX.jar:/usr/lib/hadoop-hbase/lib/zookeeperXXX.jar:/etc/hadoop-hbase/conf"
Add this to crontab and you can make regular backups every day.
This is the end of the article on "python script for incremental backup of HBase". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.