六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 61|回复: 0

python备份文件

[复制链接]

升级  66%

7

主题

7

主题

7

主题

童生

Rank: 1

积分
33
 楼主| 发表于 2013-1-15 02:59:26 | 显示全部楼层 |阅读模式
#!/bin/python
import os
import time

source = ['hello1.py']  /*原文件*/
#print source

target_dir = '/home/dujy/masen/rwz/back/'  /*目标目录*/
#print target_dir

target = time.strftime('%Y%m%d%H%M%S') + '.tgz' /*备份文件的名字*/
#print target

zip_command = "tar -zcvf %s %s" % (target, ' '.join(source)) /*开始备份的命令*/
print zip_command

if os.system(zip_command) == 0:/*执行命令*/
    print 'Successful backup to', target
else:
    print 'Backup FAILED'
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

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