Home  >  Article  >  Database  >  HBase 定期备份

HBase 定期备份

WBOY
WBOYOriginal
2016-06-07 17:27:191029browse

使用Export与Import定期备份的Python代码。每月15日做一次完整备份,每天进行一次增量备份。

如何使用HBase的Export与Import完成备份功能,请参照我之前的《HBase 增量备份》。
 
转载一份使用Export与Import定期备份的Python代码。每月15日做一次完整备份,每天进行一次增量备份。

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 %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 %s %s"%(tablename,backupSubFolder,str(int(todayTimeStamp)*1000) 
 
print cmd 
 
os.system(cmd)

注意最后的cmd字符串构建,,视HBase版本在对应位置添加上版本号。

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn