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