python备份脚本

来源:互联网 发布:淘宝网服务器 编辑:程序博客网 时间:2024/05/22 04:40
#!/usr/bin/env python# coding:utf-8import osimport timedef back_up():    files = raw_input("Please input file or dir path(\"__QUIT\" to quit):")    if files == "__QUIT":        exit(0)    back_path = raw_input("Please input backup path:")    if os.path.exists(files) and os.path.isdir(back_path):        files_sp = files.replace('/','_')        tar =files_sp+time.strftime(".%Y_%m_%d_%H_%M_%S.tar",time.localtime())        os.system("tar cf %s %s 2>log1"%(tar,files))        os.system("mv %s %s 2>log2"%(tar,back_path))        if os.path.getsize("log") == 0:            print "%s successful"%files        else:            os.system("rm -fr %s"%tar)            print "%s filed(\"cat log1 log2\")"    else:       print "%s not exist or %s is not directory"%(files,back_path)while True:    back_up()
1 0
原创粉丝点击