1. 程式人生 > >用python指令碼定期備份檔案

用python指令碼定期備份檔案

2008-05-21
#!/usr/bin/env python
# file name : backup.py
# author: zhouhh
# blog: http://blog.csdn.net/ablo_zhou
# Email: [email protected]
# Date : 2008.5.21
# back up files and dir to a time format tgz file.
# you could add this script to crontab
#

import os
import time


source=['/home/zhouhh/test/','/home/zhouhh/test1/'
] print ' backup files:',source target_dir='/home/zhouhh/backup/' target=target_dir+time.strftime('%Y%m%d%H%M%S')+'.tar.gz' cmd='tar -zcvf %s %s '%(target,' '.join(source)) if os.system(cmd)==0 : print 'successfull backup to ',target else: print 'failed backup'

可以將這個指令碼加入crontab中,定期備份檔案。如需要備份到windows,需要先mount windows分割槽,然後將目標地址修改為mount到的分割槽目錄。

如非註明轉載, 均為原創. 本站遵循知識共享CC協議,轉載請註明來源