python windows下实现备份
来源:互联网 发布:简单的拼图软件 编辑:程序博客网 时间:2024/05/29 17:09
代码如下:
#-*- coding: utf-8 -*- import osimport time#step1:需要备份的文件source='F:\\backuptest\\source\\aa.txt'#step2:存储备份文件的位置target_dir='F:\\backuptest\\'#step3:将备份文件压缩成rar#step4:当前日期作为目录名today=target_dir+time.strftime('%Y%m%d')#step4:当前时间now=time.strftime('%H%M%S')#step4:用户注释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 #step5:使用备份命令rar_command='"C:\\Program Files\\WinRAR\\WinRAR.exe" A %s %s -r' % (target,source)# rar_command='"C:\\Program Files\\WinRAR\\WinRAR.exe" A %s %s -r' % (target,source)if os.system(rar_command)==0: print "Successfully backup to",targetelse: print "Backup FAILED"
说明:
1)个人觉得自然字符串容易出问题,所以都使用转义字符
2)备份命令里必须是WinRAR的安装路径,否则命令无法执行
3)备份命令中的‘A’不可缺少,否则虽然显示备份成功 但会找不到备份的文件
0 0
- python windows下实现备份
- 【Python学习】--Windows下实现备份的Python脚本
- python备份windows下数据
- 《a byte of python》学习笔记:windows下实现备份的python脚本
- python在windows下的备份程序
- python在windows下的备份程序
- Windows下用python备份MySQL数据库
- 用python在windows下备份
- Python在Windows下实现文件备份 脚本程序 版本1
- windows平台下实现《简明python教程》第10章的文件备份示例四
- windows下实现oracle自动备份 bat
- Windows下实现PostgreSQL自动备份
- Windows下自动备份的实现
- windows下实现oracle自动备份 bat
- windows和linux下的python备份脚本
- python在windows下 完成文件备份的例子
- windows和ubuntu下使用python写备份脚本
- 使用python在windows 下 编写 自动备份脚本
- 李开复写给中国大学生的信
- Create an iOS Universal Framework
- HDU5323 Solve this interesting problem 暴力DFS
- MySql取得日期(前一天、某一天)
- 04-Js给action传值,出现乱码如何解决
- python windows下实现备份
- iOS开发 Objective-C中@property的属性详解
- HDFS架构
- 在ubuntu 14.04 64位系统上安装32位库
- 百度定位当前城市
- 排序算法
- LeetCode 5_Longest Palindromic Substring
- 求助SQL Server I/O设备错误!!!
- Android性能优化之提高ListView性能的技巧