博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 备份脚本
阅读量:7029 次
发布时间:2019-06-28

本文共 1175 字,大约阅读时间需要 3 分钟。

#!/usr/bin/env python#script name: backup_ssdb.py#desc:        copy /data/ssdb #Time:        2017-08-10 09:58#autho:       leiimport osimport datetime,timesource_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/ssdbcopy_ssdb = 'cp -rf %s %s' % (source_dir,targat_dir)os.system(copy_ssdb)home_ssdb_dir = '%sssdb' % targat_dirif 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/ssdbdelete_home_file = '%sssdb' % targat_dirdelete_home_ssdb = 'rm %s -rf ' % delete_home_fileos.system(delete_home_ssdb)#Delete data one day beforeyes_file = 'ssdb%s.tar.gz' % yes_time_nrydelte_dir = targat_dir + yes_filedel_file = 'rm %s -rf ' % delte_diros.system(del_file)

 

转载于:https://www.cnblogs.com/rayong/p/7800640.html

你可能感兴趣的文章
RabbitMQie消息列队整理
查看>>
45种Javascript技巧大全
查看>>
【Unity】7.3 键盘输入
查看>>
abap number range
查看>>
那些最好的轮子 - PHP篇
查看>>
1.2方程求根之不定点迭代法
查看>>
css attr 利用特殊字体 图片 :before content
查看>>
移动平台3G手机网站前端开发布局技巧汇总(转)
查看>>
2018-2019-1 20165231《信息安全系统设计基础》第一周学习总结
查看>>
VSSより、指定したファイルを取得するマクロ(パス入り)
查看>>
Android控件第7类——对话框
查看>>
执行JS
查看>>
学校中有老师和学生两类人,而在职研究生既是老师又是学生,对学生的管理和对教师的管理在他们身上都有体现。...
查看>>
黑马程序员——JAVA学习笔记七(String类)
查看>>
20135202闫佳歆20135220谈愈敏实验一
查看>>
CodeForces 678D Iterated Linear Function
查看>>
ACdream 1083 人民城管爱人民
查看>>
内存缓存memory-cache
查看>>
MultiByteToWideChar
查看>>
centos7下zookeeper集群安装部署
查看>>