Linux环境数据备份Python脚本
2015-06-08 15:14
776 查看
#!/usr/bin/python
#Filename:backupscript.py
import os
import time
# The files and directories to be backed up are specified in a list.
source = ['/data/']
# The backup must be stored in a main backup directory
target_dir = '/mnt/backup/'
# 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 tar 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)
print 'Successfully created directory', today
# The name of the tar file
target = today + os.sep + now +'.tar.gz'
# We use the tar command (in Unix/Linux) to put the files in a tar archive
tar_command = "tar zcvf '%s' %s" % (target, ' '.join(source))
if os.system(tar_command) == 0:
print 'Successful backup to', target
else:
print 'Backup failed'
搜索
复制
#Filename:backupscript.py
import os
import time
# The files and directories to be backed up are specified in a list.
source = ['/data/']
# The backup must be stored in a main backup directory
target_dir = '/mnt/backup/'
# 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 tar 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)
print 'Successfully created directory', today
# The name of the tar file
target = today + os.sep + now +'.tar.gz'
# We use the tar command (in Unix/Linux) to put the files in a tar archive
tar_command = "tar zcvf '%s' %s" % (target, ' '.join(source))
if os.system(tar_command) == 0:
print 'Successful backup to', target
else:
print 'Backup failed'
搜索
复制
相关文章推荐
- centos7下配置postfix
- Linux 文件查找命令find,xargs详述
- linux -- Ubuntu network-manager
- 菜鸟学Linux
- Centos 6.5 install caffe+Nvidia driver+cuda 6.5
- linux下overcommit_memory的问题
- Linux中cp和scp命令详解
- linux系统计划任务
- Linux下powerpath共享磁盘名称不一致处理方法
- SELinux(Security-Enhanced Linux)
- Linux CentOS 6.6 安装添加yum 源的简单处理方法
- Redhat 使用CentOS的yum源进行升级或软件安装
- Linux 安全模块
- vimrc设置
- Linux下vim显示中文乱码问题解决方案
- Linux netstat命令详解
- linux性能优化不错哦
- linux下vi命令大全
- Linux系统性能分析工具-操作篇 (很不错)
- 细说Linux系统优化-实践篇 优秀