python使用7z解压软件备份文件脚本分享
2014-02-21 00:00
876 查看
要求安装:
1.Python
2.7z解压软件
backup_2.py
1.Python
2.7z解压软件
backup_2.py
# Filename: backup_2.py '''Backup files. Version: V2, based on Python 3.3 Usage: backup.py -s:"dir1|dir2|..." -t:"target_dir" [-c:"comment"] -s: The source directories. -t: The target directory. -c: Optional, any comment. Examples: backup.py -s:"c:\\src\\F1|c:\\src\\F2|c:\\src\\F 3" -t:"c:\\backup" backup.py -s:"c:\\src\\F 3" -t:"c:\\backup" -c:"For sample"''' import os import sys import time # Read sys.argv print(sys.argv) if len(sys.argv) < 2: print(__doc__) sys.exit() source=[] target_dir='' comment='' for arg in sys.argv: if arg.startswith('-s:'): source=arg[3:].split('|') print(source) elif arg.startswith('-t:'): target_dir=arg[3:]+os.sep print(target_dir) elif arg.startswith('-c:'): comment=arg[3:] print(comment) for i in range(0, len(source)): source[i] = "\"" + source[i] + "\"" print(source[i]) # Make the file name with the time and comment today=target_dir+time.strftime('%Y%m%d') now=time.strftime('%H%M%S') if len(comment)==0: # check if a comment was entered target=today+os.sep+now+'.7z' else: target=today+os.sep+now+'_'+\ comment.replace(' ','_')+'.7z' # Create the subdirectory by day if not os.path.exists(today): os.mkdir(today) # make directory print('Successfully created directory',today) # zip command zip_command="7z a %s %s" %(target,' '.join(source)) print(zip_command) # Run the backup if os.system(zip_command)==0: print('Successful backup to',target) else: print('Backup FAILED')
相关文章推荐
- python使用7z解压软件备份文件脚本分享
- Python实现简单的文件传输与MySQL备份的脚本分享
- CentOS环境使用python脚本备份文件
- 两个使用Python脚本操作文件的小示例分享
- 两个使用Python脚本操作文件的小示例分享
- 使用python脚本配合cygwin自动备份文件搭配文件服务器
- Python实现简单的文件传输与MySQL备份的脚本分享
- Python脚本实现windows下文件的备份
- python脚本编程:使用zip或者tar压缩和解压文件
- unix/windows下编写一个python脚本(文件备份)--python学习(4)
- Shell脚本:使用rsync备份文件/目录
- linux系统使用python监控apache服务器进程脚本分享
- 使用python脚本实现mysql目录的备份
- 使用PyInstaller2将Python脚本转化为可执行文件(上-安装部分)(转载自博客园balian)
- Python脚本 —Windows下文件备份
- 使用函数封装-公司自动化处理文件备份管理脚本
- shell备份文件、重命名文件、删除指定文件的3个脚本分享
- 使用python脚本,清空文件 追加数字
- python: 通过脚本实现重要文件的备份
- Python写的备份目录文件的脚本