Things change, roll with the punches.Oh, yeah. Go for it man, jump off the high dive, stare down the barrel of the gun, pee into the wind!

backup_ver2.py

上一篇 / 下一篇  2007-01-15 13:19:47 / 个人分类:代码冢

#!/usr/bin/python
# Filename : backup_ver2.py
# backup and package /home/mushroom & /root directory 
# to /root/backup/YearMonthDay/HourMinuteSecond.tar.gz

import os
import time

source = ['/home/mushroom/','/root/']
target_dir = '/root/backup/'
today = target_dir + time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')

if not os.path.exists(today):
        os.mkdir(today)
        print 'Successfully created directory',today

target = today + os.sep + now + '.tar.gz'

zip_command = "tar zcvf '%s' %s" % (target,' '.join(source))

if os.system(zip_command) == 0:
        print 'Successful backup to',target
else:
        print 'Backup Failed'

TAG: 代码冢 Python

 

评分:0

我来说两句

日历

« 2024-04-16  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 45842
  • 日志数: 42
  • 图片数: 3
  • 文件数: 1
  • 书签数: 13
  • 建立时间: 2007-01-05
  • 更新时间: 2007-03-03

RSS订阅

Open Toolbar