Wednesday, November 12, 2008

Simple script for backup

I understood some time ago that I often do the same operation:
- get come folder
- make a folders like "1","2","3" and put backup versions of the working folder there.
This habit saved me a lot of time by not letting intermediate results gone by mistake. However, the actions so routine that I decided to create a script that can be run from using the shortcut in the quick launch bar. After a few iterations I've got the following.

SET SOURCE_DIR="D:\tests\ReportBrowser\"
SET APP_NAME=ReportBrowser
SET ARCHIVE_PATH=D:\Archive\

@ECHO ON
FOR /L %%X IN (300,-1,1) DO IF NOT EXIST %ARCHIVE_PATH%%APP_NAME%\%%X SET PATH_DIR=%ARCHIVE_PATH%%APP_NAME%\%%X
MKDIR %PATH_DIR%\

XCOPY %SOURCE_DIR%*.* %PATH_DIR%\ /i /f /r /k /y /s

Now, if I need a new folder to backup, I create a copy of that script, then change 2 first variables(SOURCE_DIR and APP_NAME) and I have it working. The script copies the whole content to folder (1,2,3) in D:\Archive\ReportBrowser (in case if variables are the same as in the sample). Thus by I a single click I save the folder I need and have all previous backups to rollback in case I need it