取り付け要求:
1.Python
2.7z解压软件
backup_2.py
'''バックアップ ファイル。
バージョン: V2、Python 3.3 ベース
使用法:backup.py -s:"dir1|dir2|..." -t:"target_dir" [-c: "comment"]
-s: ソース ディレクトリ。
-t: ターゲット ディレクトリ。
-c: オプション、任意のコメント。
例:
backup.py -s:" c:\src\F1|c:\src\F2|c:\src\F 3" -t:"c:\backup"
backup.py -s:"c:\src\F 3" - t:"c:\backup" -c:"サンプル用"''
os のインポート
sys のインポート
時間のインポート
# sys.argv を読み取ります
print(sys.argv)
if len(sys.argv) < 2:
print(__doc__)
sys.exit()
source=[]
target_dir=''
comment=''
for arg in sys.argv:
if arg.startswith('-s:'):
ソース=arg[3:].split('|')
print(source)
elif arg.startswith('-t:'):
target_dir=arg[3:]+os.sep
print(target_dir)
elif arg.startswith('-c:'):
comment=arg[3:]
print(comment)
for i in range(0, len(source)):
source[i] = """ + source[i] + """
print(source[i])
# 時刻とコメントを付けたファイル名を作成します
today=target_dir+time.strftime('%Y%m%d')
now=time.strftime('%H%M%S' )
if len(comment)==0: # コメントが入力されたかどうかを確認します
target=today+os.sep+now+'.7z'
else:
target=today+os.sep +now+'_'+
comment.replace(' ','_')+'.7z'
# 日までにサブディレクトリを作成します
if not os.path.exists(today):
os.mkdir(today) # ディレクトリを作成
print('ディレクトリが正常に作成されました',today)
# zip コマンド
zip_command="7z a %s %s" %(target,' '.join(source))
print(zip_command)
# バックアップを実行します
if os.system(zip_command)==0:
print('Successful back to',target)
else:
print('Backup FAILED')