2017-07-19 113 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"