手动备份 version 1

#!/usr/bin/python
#Filename: backup_v1.py

import os
import time

source = ['/root/slp/NetWrokProgram/client','/root/slp/NetWrokProgram/server']

dist = '/root/slp/NetWrokProgram/backup'

now = time.strftime("%Y%m%d")

today_dir = dist + "/" + now 

if not os.path.exists(today_dir):
    if 0 == os.mkdir(today_dir):
        print 'mkdir %s success' % today_dir
    else:
        print 'mkdir %s failed' % today_dir

comment = raw_input("Please enter a comment:")
if len(comment) == 0:
    target = today_dir + os.sep + time.strftime("%H%M%S")+'.tar.gz'else:
    target = today_dir + os.sep  + time.strftime("%H%M%S")+comment.replace(' ','_')+'.tar.gz'

tar_cmd = "tar -czvf %s %s" % (target,' '.join(source))

if os.system(tar_cmd) == 0:
    print 'success backup to',target
else:
    print 'backup failed'


Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐