kalor

导航

 

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

[python]
    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版本在对应位置添加上版本号。

posted on 2013-12-12 15:34  kalor  阅读(233)  评论(0编辑  收藏  举报