#!/usr/bin/env python
# coding:utf-8
import os
import time
def 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()
python备份脚本
最新推荐文章于 2024-03-25 15:55:08 发布