教程中的zip文档,不太适合现在win系统中大家安装的winrar软件,
于是我作了一个小更改。。
~~~~~~~~~~
#!/usr/bin/python
# filename: backup_ver1.py
import os
import time
source = ['c:\\device ','c:\\source']
target_dir = 'd:\\backup'
winrar_dir = '"c:\\winrar\\"'
today = target_dir + os.sep + time.strftime('%y_%m_%d')
now = time.strftime('%h_%m_%s')
comment = input('enter a comment --> ')
if len(comment) == 0:
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('successfully created directory',today)
zip_command = winrar_dir + "winrar.exe a -ad {0} {1}".format(target,''.join(source))
if os.system(zip_command) == 0:
print('successful backup to' ,target)
print('backup failed')
~~~~~~
