Python 备份程序

# -*-encoding:utf8 -*-
import os,time,getpasspython

#须要备份的目录ide

#[r' ']方括号的不是无辜存在的,若是不添加方括号,那么文字就会变成全角的样子,而不是简单的咱们想要的。你能够在作zip的命令的时候print查看一下,传给zip的#命令究竟是什么
source = [r'"D:\Python27\test"']
#定义备份的目标目录
target_d = r'D:\Python27\test\python'
print target_dip

#获取当前备份脚本的用户
user = getpass.getuser()get

print userinput

#定义今天的时间
today = target_d + time.strftime('%Y%m%d')
#获取当前时间
now = time.strftime('%H%M%S')
#定义在备份目录中须要注释的文字,能够选填
comment = raw_input('Please input :')
#判断用户有没有输入 备份注释文字
#若是没有,那么target的目录名定义为 备份目标目录+当前时间+用户+zip
if len(comment) == 0:
    target = today + '' +user + '.zip'
else:
    target = today + ' ' +user + comment + '.zip'it

#zip的语法,能够本身在dos窗口下试验。
#zip -qr 静默方式打包,zip 目标目录 须要备份目录 经过用%来输入
zip = "zip -qr %s %s" % (target, ' '.join(source))
print zip
#判断zip运行是否成功
if os.system(zip) == 0:
    print 'OK'
else:
    print 'Failed'class

 

最后添加上关于time模块的输出,来定制本身想要的zip备份目录test

print (time.strftime('%Y-%m-%d %H:%M:%S'))
2012-04-10 14:52:09import

相关文章
相关标签/搜索