A backup program for Python
This is a backup script. Please change the path yourself.
This is a backup script, according to the current date of the directory, the time as the file name, and can be added to the file name Note information.
Zip as a compression method, there are special needs can be changed.
Instance code:
#! /usr/bin/python#coding=utf-8 #这是一个备份脚本, according to the current date of the directory, the time as the file name, and you can add notes information in the file name. #以zip方式作为压缩方式, there are special needs that can be changed. Import Osimport Time Source = ['/home/leeicoding/workspace/j2ee ', '/home/leeicoding/workspace/python '] target_dir = '/home/leeicoding /bak ' #获取系统时间today = target_dir + time.strftime ('%y%m%d ') now = Time.strftime ('%h%m%s ') # Enter Comment comment = raw_input (' Please enter remark: ') if len (comment) = = 0: print (' no Notes ') target = today + Os.sep + now + '. Zip ' else : target = today + OS.SEP + Now + comment.replace (", ' _ ') + '. zip ' if not os.path.exists (today): Os.mkdir (today) print (' Create directory ' +today+ ' success ' # Backup Command # Q silent mode r recursive directory Zip_command = ' zip-qr '%s '%s '% (target, '. Join (source) ') if Os.system (zip_command) = = 0:
print (' Backup succeeded, stored in: ' +target)
Thank you for reading, hope to help everyone, thank you for the support of this site!