Backup Batch Script

This project spawned mainly from some of the posts on the LifeHacker blog about using rsync in cygwin to backup your files on your computers to each other. Unfortunately I never managed to get rsync to work and thought that SSH over one 100Mbps wired switch was a little overkill. Thus I sifted through all the comments on the LifeHacker posts (which are well worth the sifting) and discovered that one of Microsoft's own powertoys for Windows XP is a synchronizer program with a good set of options and, even better, a basic command line interface.
Command line interfaces are pretty cool. Open up a command prompt, (Start > run: "cmd") and be able to interact with a program only using text. They get even cooler when you save a whole list of said commands in a .bat file, otherwise called a batch file. I am a huge fan of batch files. Once you know how to write them, they can make your life easier in a few small ways.

The first useful batch file I wrote was called "startup.bat" and all it did was start up all the programs I wanted running when I turned on my computer. Normally this is done by just putting shortcuts to the programs in your startup folder (C:\Documents and Settings\UserName\Start Menu\Programs\Startup) but my problem is that I don't want these programs to start every time I log on, only most of the time. It was a huge pain to have to wait for every program to load, just so I can close it again.
This batch file is pretty simple, just one command repeated for every program you want to have running. This wonderful command is START. Example:
START /D"C:\Program Files\Gaim\" gaim.exe
START /D"C:\Directory\of\program\you\want\running\" nameofprogram.exe
Pretty cool! Just repeat that 6 or 7 times and you can open your chat client(s), web browser, email client, podcast reader, and anything else you want with just one double click.

So back to Backup.bat. Microsoft's SyncToy is really designed for moving files between your cell phone and camera and your computer, but you can really give it any folder name, including one on another computer. For this example let us just use my two main computers, "KWF" and "KWF2" So the trick is that for the SyncToy you give it a folder name that is a shared folder on the other computer. i.e. \\KWF\Backup\

Now for how to backup "My Documents" to \\KWF\Backup\ from KWF2. First set up a job in SyncToy to echo your "My Documents" folder to \\KWF\Backup\ and name the job "My Documents"

START /D"C:\Documents and Settings\UserName\Local Settings\Application Data\SyncToy\" SyncToy.exe -R"My Documents"

That's it. That will work, but the concept is that you come up with a more elegant solution to it then that. My idea was to have it check to make sure the other computer is turned on first before it tries to run the job.

IF EXIST \\kwf\kennethbakup\ (
START /D"C:\Documents and Settings\UserName\Local Settings\Application Data\SyncToy\" SyncToy.exe -R"My Documents"

This also means I can set up many different jobs with different names to back up all of my external storage devices and mirror files to different computers as they become avaliable, etc etc.

That's it. The trick is to set this to run with the AT command every so often so you don't even have to think about it. I think I'll leave using the AT command as a challenge to the reader. It's real easy to find tons of info on it from Google.

One still needs to face the fact that this is not the solution to backing up your data. This is only local and protects you from hardware failure. If your house burns down, you loose both computers and it all counts for nothing anyways. Make sure you keep offsite backups of the real important files somewhere secure.

Popular Posts