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)
  • 相关阅读:
    SpringBoot配置默认日志logback
    SpringBoot静态资源映射、拦截器、过滤器使用
    windows系统安装两个Mysql服务
    SpringBoot使用Jsp开发Web项目
    SpringBoot使用Thymeleaf开发Web项目
    SpringBoot启动原理
    javascript Date
    UDP发送数据测试
    自动迁移
    EF 自测例子
  • 原文地址:https://www.cnblogs.com/rayong/p/7800640.html
Copyright © 2011-2022 走看看