Python自动备份代码
本帖最后由 xiaoye 于 2015-9-30 11:04 编辑#!/usr/bin/python
#Filename: Auto Backup root DIR and file
#write wugk 2013-11-07
importos
importtime
#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 ......"
#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
os.system('sleep 2')
print '--------------- backup done ------------------' 支持中国红客联盟(ihonker.org) 支持中国红客联盟(ihonker.org) 学习学习技术,加油! 感谢楼主的分享~ 支持中国红客联盟(ihonker.org) 感谢楼主的分享~ 支持中国红客联盟(ihonker.org) 支持中国红客联盟(ihonker.org)