# encoding: utf8# Filename: backup_ver_0.2.py# Author: JDI# Date : 2012-12-02 18:41:14import osimport timeimport datetime# 1. The files and directories to be backed up are specified in a listsource = [r'e:\doc', r'e:\media']# using Windows# 2. The backup must be stored in a main backup directorytarget_dir = r'f:\backup' # Remember to change this to what you will be using# 3. The files are backed up into a zip file# 4. The name of the zip archive is the current date and timetarget = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'# 5. We use the zip commandzip_command = "7z a %s %s" % (target, ' '.join(source))# before run the commandstarttime = datetime.datetime.now()# Run the backupif os.system(zip_command) == 0: print 'Successful backup to', targetelse: print 'Backup FAILED'# after run the command, write th dateendtime = datetime.datetime.now()countTime = (endtime - starttime).secondshour = time.strftime('%H', time.gmtime(countTime))minutes = time.strftime('%M', time.gmtime(countTime))secs = time.strftime('%S', time.gmtime(countTime))strCountTime = u"%s时%s分%s秒" % (hour, minutes, secs)print u"一共用时:%s" % (strCountTime) 来自《简明python教程》的备份脚本的修改加入了备份的用时计算