python备份数据脚本
2014-04-22 21:18
337 查看
python 数据备份脚本
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 ifa comment was entered
target = today +
os
.sep + now +
'.zip'
else
:
target = today +
os
.sep + now +
'_'
+ \
comment.replace(
' '
,
'_'
) +
'.zip'
# Notice the backslash!
# Create the subdirectory ifit isn't already there
ifnot
os
.path.exists(today):
os
.mkdir(today)
# make directory
'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
:
'Successful backup to'
,target
else
:
'Backup FAILED'
相关文章推荐
- Linux环境数据备份Python脚本
- Python脚本备份数据库
- Python 简单数据备份脚本
- python脚本用sqoop把mysql数据导入hive数据仓库中
- python使用7z解压软件备份文件脚本分享
- SQL 备份数据 脚本 -添加到作业 步骤里面 可删除历史天文件
- Python把csv中的数据整合成多条json数据插入列表的脚本
- Linux平台和Windows平台下两种自动备份MySQL数据的脚本(Shell&Bat)和步骤
- 用python编写脚本从wireshark导出的数据文件中提取数据
- expdp数据泵自动备份脚本
- A Byte of Python习题:用于备份文件的Python脚本
- Python把csv中的数据整合成多条json数据插入列表的脚本
- 第一次用Python试着写一个在Windows环境下的备份脚本
- 写LINUX shell脚本 自动备份ORACLE用户下的表 保留30天数据
- mysqldump批量备份恢复数据脚本
- shell脚本备份mysql和项目数据
- 利用TSQL脚本将备份数据自动上传到ftp
- 程序员(媛)Shell脚本必备技能之中的一个: 在Linux下怎样自己主动备份mysql数据
- 用shell脚本自动化备份数据库
- 浅谈Python数据类型判断及列表脚本操作