Wednesday, January 20, 2010

Simple Script to Schedule Backup

I am recently asked to improve/automate a manual backup job. What they did previously was to copy a complete folder from c:\xxx to f:\xxx manually everyday at 4:30pm, and what is more annoying was that the user was prompted every time if he/she was to overwrite the existing file in destination folder.

Here i managed to create a batch file which i believe will help anyone who needs to do this manually everyday.

Open Notepad, copy and paste the following lines to your notepad and save it as copy.bat
set copycmd=/y
XCOPY C:\temp\* D:\temp\ /i /s

In line 1, copycmd=/y tells the system not to prompt to ask overwrite whatever existed in destination folder. If you changed it to copycmd=/-y, then the system will prompt if you want to overwrite it.

In line 2, XCOPY allows you to copy files and/or directory trees to another folder. XCOPY is similar to the COPY command except that it has additional switches to specify both the source and destination in detail; where C:\temp\* is your source, D:\temp\ is your destination, /i means if in doubt always assume the destination is a folder e.g. when the destination does not exist, and /s means copy folders and subfolders.

Then last step, you open the Scheduled Tasks (Start->Accessories->System Tools->Scheduled Tasks in WinXP), double-click Add Scheduled Tasks, browse to your copy.bat, and finally define when you want the system to perform this task.

Hopefully this can help. Cheers...

Additional link: WindowsXP Command guide