python-backup

太久没空写东西,只能随便写点东西来冲冲数量,python学了很久一直没怎么用上,今天实在闲得很,在原有的基础上将备份脚本进一步完善一下,空间越来越丑,实在让人火大,不说了贴代码:

#!/usr/bin/python#coding=utf8#filename:backup.pyimport osimport timedef backup_file(dir):    source = dir    #print source    target_dir='/home/jack/test/'    today = target_dir + time.strftime('%Y%m%d')    now = time.strftime('%H%M%S')    comment = raw_input('Enter a comment --> ')    if len(comment) == 0:        target = today + os.sep + now + '.tar.gz'    else:        target = today + os.sep + now + '_' +             comment.replace(' ', '_') + '.tar.gz'    if not os.path.exists(today):        os.mkdir(today)        print 'Successfully create directory',today    tar_command="tar -czf '%s' %s" %(target, ' '.join(source))    if os.system(tar_command) == 0:        print 'Successful backup to', target    else:        print 'Backup FAILED'def path(dir):    one_path = raw_input("Tell me backup path: ")    dir.append(one_path)    #print dir    x = raw_input("Do you have another path? [y]").lower()    if x and x[0] =='y':        path(dir)    else:        print "Please wait............"    return dirdef main():    start=raw_input("Tell me What type of backup(A:File backup; B:Databases backup): ")    if start == "A":        dir = []        path(dir)        backup_file(dir)    else:        passif __name__ == '__main__':    main()

python-backup,首发于运维者。

当一个人把寂寞当作人生预约的美丽,

python-backup

相关文章:

你感兴趣的文章:

标签云: