六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 58|回复: 0

用python脚本定期备份文件

[复制链接]

升级  47.35%

633

主题

633

主题

633

主题

探花

Rank: 6Rank: 6

积分
1947
 楼主| 发表于 2013-1-15 01:56:57 | 显示全部楼层 |阅读模式
<div style="padding-right: 5.4pt; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 4px; width: 95%; padding-top: 4px;">#!/usr/bin/envpython
#
filename:backup.py
#
author:zhouhh
#
blog:http://blog.csdn.net/ablo_zhou
#
Email:ablozhou@gmail.com
#
Date:2008.5.21
#
backupfilesanddirtoatimeformattgzfile.
#
youcouldaddthisscripttocrontab
#

importos
importtime


source
=['/home/zhouhh/test/','/home/zhouhh/test1/']
print'backupfiles:',source

target_dir
='/home/zhouhh/backup/'
target
=target_dir+time.strftime('%Y%m%d%H%M%S')+'.tar.gz'


cmd
='tar-zcvf%s%s'%(target,''.join(source))

ifos.system(cmd)==0:
print'successfullbackupto',target
else:
print'failedbackup'
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表