2017-07-19 9 views
1

私はサポート技術者のために社内のcmdラインツールを維持していました。そのため、私は何かが横になった場合に備えて、以前のバージョンのファイルを保管しておきたいと思っていました。簡易バックアップスクリプト

ネットワーク共有上に開発フォルダのコピーを作成するために、X日ごとにスケジュールされたタスクとして実行できる単純なバッチファイルを作成したかったのです。

答えて

1

これは私が思いついたものです。最もエレガントではありませんが、仕事は終わりました。私は匿名化されたスクリプトを通過しましたが、あなたのニーズに合ったディレクトリパスを置き換えることは難しくありません。

@echo off 
rem Copies the targeted directory to a folder in my documents and appends the date. 
rem It also copies it to a backup dir on the shared drive itself 

rem This part uses the current date a time, but arranges it into a useful manner 
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b) 
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b) 


rem This copies the folder from the shared drive to a local copy in Documents. 
robocopy "Z:\Support\Development" "C:\Users\SmithJ\Documents\Support_Tool\%mydate%" /LOG+:"C:\Users\SmithJ\Documents\Support_Tool\log.txt" 

rem This copies the same shared folder to a backup folder on the share drive itself just to be sure. 
robocopy "Z:\Support\Development" "Z:\SmithJ\Support_Tool_Backup\%mydate%" /LOG+:"Z:\SmithJ\Support_Tool_Backup\log.txt"