HBase Incremental backup and restoration tools

Source: Internet
Author: User

The export/import mechanism provided by HBase can implement the Backup Restore function. In addition, Incremental Backup can be implemented. The following python script sets up Incremental backup. In this script, Incremental backup is performed every day, and full backup is performed every 15 days.

 
 
  1. import time 
  2. import datetime 
  3. from datetime import date 
  4. import sys 
  5. import os 
  6.  
  7. tablename=sys.argv[1] 
  8. backupDst=sys.argv[2] 
  9. today=date.today() 
  10. if today.day == 15:    //every month, we do a full backup 
  11.         backupSubFolder=backupDst+today.isoformat()+"-full" 
  12.         cmd="hbase org.apache.hadoop.hbase.mapreduce.Export %s %s"%(tablename,backupSubFolder) 
  13. else: 
  14.  
  15.         yesterday=datetime.date.today()- datetime.timedelta(days=1) 
  16.         todayTimeStamp=time.mktime(today.timetuple()) 
  17.         yesTimeStamp=time.mktime(yesterday.timetuple()) 
  18.         backupSubFolder=backupDst+today.isoformat() 
  19.         cmd="hbase org.apache.hadoop.hbase.mapreduce.Export %s %s %s"%(tablename,backupSubFolder,str(int(todayTimeStamp)*1000) 
  20.  
  21. print cmd 
  22.  
  23. os.system(cmd) 

The Restore mechanism is simpler.

 
 
  1. hbase org.apache.hadoop.hbase.mapreduce.Import tablename restorefolder 

Note that the original table must be created during Restore. Therefore, if the table itself is damaged, you need to create a new empty table and Restore it again.

Also, the path of hbase and Zookeeper must be configured in the Hadoop-env.sh with such a statement

 
 
  1. export HADOOP_CLASSPATH="/usr/lib/hadoop-hbase/hbaseXXX.jar:/usr/lib/hadoop-hbase/lib/zookeeperXXX.jar:/etc/hadoop-hbase/conf" 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.