教程中的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)
else:
print('Backup FAILED')
~~~~~~