一个简单的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