CentOS环境使用python脚本备份文件
2017-12-05 11:30
483 查看
备份脚本一
#!/usr/bin/python # Filename: backup_ver1.py import os import time # 1. The files and directories to be backed up are specified in a list. source = ['/home/swaroop/byte', '/home/swaroop/bin'] # If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that # 2. The backup must be stored in a main backup directory target_dir = '/mnt/e/backup/' # Remember to change this to what you will be using # 3. The files are backed up into a zip file. # 4. The name of the zip archive is the current date and time target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip' # 5. We use the zip command (in Unix/Linux) to put the files in a zip archive zip_command = "zip -qr '%s' %s" % (target, ' '.join(source)) # Run the backup if os.system(zip_command) == 0: print 'Successful backup to', target else: print 'Backup FAILED'
备份脚本二
#!/usr/bin/python # Filename: backup_ver2.py import os import time # 1. The files and directories to be backed up are specified in a list. source = ['/home/swaroop/byte', '/home/swaroop/bin'] # If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that # 2. The backup must be stored in a main backup directory target_dir = '/mnt/e/backup/' # Remember to change this to what you will be using # 3. The files are backed up into a zip file. # 4. The current day is the name of the subdirectory in the main directory today = target_dir + time.strftime('%Y%m%d') # The current time is the name of the zip archive now = time.strftime('%H%M%S') # Create the subdirectory if it isn't already there if not os.path.exists(today): os.mkdir(today) # make directory print 'Successfully created directory', today # The name of the zip file target = today + os.sep + now + '.zip' # 5. We use the zip command (in Unix/Linux) to put the files in a zip archive zip_command = "zip -qr '%s' %s" % (target, ' '.join(source)) # Run the backup if os.system(zip_command) == 0: print 'Successful backup to', target else: print 'Backup FAILED'
备份脚本三
#!/usr/bin/python # Filename: backup_ver3.py import os import time # 1. The files and directories to be backed up are specified in a list. source = ['/home/swaroop/byte', '/home/swaroop/bin'] # If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that # 2. The backup must be stored in a main backup directory target_dir = '/mnt/e/backup/' # Remember to change this to what you will be using # 3. The files are backed up into a zip file. # 4. The current day is the name of the subdirectory in the main directory today = target_dir + time.strftime('%Y%m%d') # The current time is the name of the zip archive now = time.strftime('%H%M%S') # Take a comment from the user to create the name of the zip file comment = raw_input('Enter a comment --> ') if len(comment) == 0: # check if a comment was entered target = today + os.sep + now + '.zip' else: target = today + os.sep + now + '_' + \ comment.replace(' ', '_') + '.zip' # Notice the backslash! # Create the subdirectory if it isn't already there if not os.path.exists(today): os.mkdir(today) # make directory print 'Successfully created directory', today # 5. We use the zip command (in Unix/Linux) to put the files in a zip archive zip_command = "zip -qr '%s' %s" % (target, ' '.join(source)) # Run the backup if os.system(zip_command) == 0: print 'Successful backup to', target else: print 'Backup FAILED'
相关文章推荐
- 使用python脚本配合cygwin自动备份文件搭配文件服务器
- python使用7z解压软件备份文件脚本分享
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中
- python使用7z解压软件备份文件脚本分享
- CentOS6.5环境下使用rsync增量同步备份文件的方法
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中(转)
- python 网站文件及数据库备份脚本
- 使用PyInstaller2将Python脚本转化为可执行文件(下-进阶使用)
- CentOS 6.3_ RSync实现文件定时备份同步配置与使用 推荐
- 使用PyInstaller2将Python脚本转化为可执行文件(上-安装部分)(转载自博客园balian)
- 使用PyInstaller2将Python脚本转化为可执行文件(下-进阶使用)(转载自博客园balian)
- 一个python的邮件发送脚本,自动,定时,可以附件发送,抄送,附有说明文件 (本脚本是python的2.7.x环境下可用)
- 使用PyInstaller2将Python脚本转化为可执行文件(上-安装部分)
- [转]使用PyInstaller2将Python脚本转化为可执行文件(上-安装部分)
- 使用PyInstaller2将Python脚本转化为可执行文件(下-进阶使用)
- CentOS使用yum配置安装LAMP环境自动化脚本
- 使用PyInstaller2将Python脚本转化为可执行文件(中-使用部分)
- 把Python脚本打包成exe文件 ——py2exe使用小记
- 使用PyInstaller2将Python脚本转化为可执行文件(中-使用部分)(转载自博客园balian)