本帖最后由 xiaoye 于 2015-9-30 11:04 编辑
[Python] 纯文本查看 复制代码 #!/usr/bin/python
#Filename: Auto Backup root DIR and file
#write wugk 2013-11-07
import os
import time
#Define SOURCE and TARGET DIR
SOURCE = ['/root','/var/www/html','/etc']
TARGET_DIR = '/data/backup/'
NAME_FILE = 'System_bak'
today = TARGET_DIR + time.strftime('%Y%m%d')
TARGET = TARGET_DIR + time.strftime('%Y%m%d') + "/" + NAME_FILE + '.zip'
zip_command = "zip -qr '%s' %s " % (TARGET, ' '.join(SOURCE))
#Scripts Exec process Start
print '-------------------------------------------------'
print "The Scripts Backup Starting,Please waiting ......"
print
#Judge today DIR
if not os.path.exists(today):
os.mkdir(today) # make DIRectory
print 'Successfully created Directory', today
#Exec Zip Command to Dir or file
if os.system(zip_command) == 0:
print 'Successful backup to', TARGET
else:
print 'backup failed !'
#print Backup end info
print
os.system('sleep 2')
print '--------------- backup done ------------------' |