zoukankan      html  css  js  c++  java
  • python 备份脚本

    #!/usr/bin/env python
    #script name: backup_ssdb.py
    #desc:        copy /data/ssdb 
    #Time:        2017-08-10 09:58
    #autho:       lei
    import os
    import datetime,time
    
    source_dir = '/data/ssdb'
    targat_dir = '/home/ssdb_backup/'
    
    now_time = datetime.datetime.now()
    yes_time = now_time + datetime.timedelta(days=-7)
    yes_time_nry = yes_time.strftime('%Y%m%d')
    
    #copy /data/ssdb
    copy_ssdb = 'cp -rf %s %s' % (source_dir,targat_dir)
    os.system(copy_ssdb)
    
    home_ssdb_dir = '%sssdb' % targat_dir
    
    if os.path.exists(home_ssdb_dir):
        target = home_ssdb_dir + time.strftime('%Y%m%d') + '.tar.gz'
    
        tar_command = "tar czvf %s %s --exclude=log* --exclude=*log" %(target,source_dir)
        print tar_command
    
        if os.system(tar_command) == 0:
            print 'Successful backup to',target
        else:
            print 'Backup FAILED'
    else:
        print 'directory does not exist'
    
    #Delete /home/ssdb_backup/ssdb
    delete_home_file = '%sssdb' % targat_dir
    delete_home_ssdb = 'rm %s -rf ' % delete_home_file
    os.system(delete_home_ssdb)
    
    #Delete data one day before
    yes_file = 'ssdb%s.tar.gz' % yes_time_nry
    delte_dir = targat_dir + yes_file
    
    del_file = 'rm %s -rf ' % delte_dir
    os.system(del_file)
  • 相关阅读:
    python入门之函数及其方法
    Python入门知识点2---字符串
    Python列表 元组 字典 以及函数
    Python入门知识
    Autofac使用代码
    优化EF以及登录验证
    CRM框架小知识以及增删查改逻辑代码
    分页SQL
    触发器SQL
    动态生成lambda表达式
  • 原文地址:https://www.cnblogs.com/rayong/p/7800640.html
Copyright © 2011-2022 走看看