且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

【python】简单的备份脚本

更新时间:2022-07-02 18:17:40

一个简单的python 备份脚本,备份指定目录下的文件到/tmp 文件夹下
[yang@rac1 ~]$ vim backup_ver1.py   
#!/etc/bin/python
#FILENAME :backup_ver1.py
import os
import time
source ='/home/yang/python'
target_dir = '/tmp/'
target = target_dir + time.strftime('%Y%m%d%H%M%S')+'.zip'
zip_command = "zip -qr %s %s" % (target, source)
if os.system(zip_command) == 0:
   print 'Successful backup to ',target
else:
   print 'Backup FAILED!!'
                                                                                                                                                        
"backup_ver1.py" 23L, 406C written                                                                                                                   
[yang@rac1 ~]$ python backup_ver1.py
Successful backup to  /tmp/20110723212009.zip