# !/usr/bin/envpython # filename:backup.py # author:zhouhh # blog:http://blog.csdn.net/ablo_zhou # Email:ablozhou@gmail.com # Date:2008.5.21 # backupfilesanddirtoatimeformattgzfile. # youcouldaddthisscripttocrontab # import os import timesource = [ ' /home/zhouhh/test/ ' , ' /home/zhouhh/test1/ ' ] print ' backupfiles: ' ,sourcetarget_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 ' successfullbackupto ' ,target else : print ' failedbackup ' 可以将这个脚本加入crontab中,定期备份文件。如需要备份到windows,需要先mount windows分区,然后将目标地址修改为mount到的分区目录。