#python 2.7
#Filename:backup.py
import os
import time
source = [r'C:\Users\zeng.shufang\Desktop\messages_zh_CN-update.properties',r'C:\Users\zeng.shufang\Desktop\Capture.PNG']
target_dir=r'C:\Users\zeng.shufang\Desktop'
today = target_dir+os.sep+time.strftime('%Y%m%d')
now=time.strftime('%H%M%S')
comment=raw_input('Enter a comment-->')
if len(comment)==0:
    target = today+os.sep+now+'.rar'
else:
    target = today+os.sep+now+'_'+\
        comment.replace(' ','_')+'.rar'
if not os.path.exists(today):
    os.mkdir(today)
    print 'Successfully created directory',today
zip_command = "Winrar A %s %s -r" %(target,' '.join(source))
if os.system(zip_command)==0:
    print 'Successful backup to',target
else:
    print 'backup failed'

注:由于Windows没有自带的压缩命令,需要把Winrar.exe文件复制到C:\Windows目录下