AdamTheTech Logo
AdamTheTech
Enthusiast of Technology, Web Development, and Sci-Fi

Microsoft’s Free Virtual Machine Images

Deus Ex: Human Revolution Review

Embed dll Files Within an exe (C# WinForms)

Create a Simple Backup System: Part II

Please be aware that this entry is over two years old. Therefore, it may contain broken links, outdated information, or views and content which are no longer completely valid.

You should have had the chance to give the “Create a Simple Backup System” a whirl by now, but if not, you should probably at least read it first because I’ll be pressing right ahead with the next step of the process: backing up multiple directories with one .bat file!

So, last time you should have created a single batch file that effectively backed up “My Documents” or another directory of your choosing.  If you’re anything like me, you probably have other things you would like to backup that may be scattered around your hard drive, such as your email and address book, pictures, bookmarks, and so on.

So, hold on to your hat, and here we go!

The idea behind the batch file is to automate tasks to save you doing everything by hand.  The easiest way to do that for the purposes of these backups is to make a separate batch file for each directory or file that is similar.  For instance, if you want to backup your bookmarks, it would be best to specify that you want all your bookmark files to be backed up at the same time and RARed into the same archive.  So, here’s an example of a backup file that will take care of IE, FireFox, and Opera:

@echo off
title bookmark backup
REM this is for IE6
<pre>XCOPY "C:\Documents and Settings\Adam\Favorites" "C:\backups\bookmarks\Documents and Settings\Adam\Favorites" /y/s/e/c/i
REM this is for FireFox - the "z35y4x8x.default" directory may be named something else on your computer
XCOPY "C:\Documents and Settings\Adam\Application Data\Mozilla\Firefox\Profiles\z35y4x8x.default\bookmarks.html" "C:\backups\bookmarks\Documents and Settings\Adam\Application Data\Mozilla\Firefox\Profiles\z35y4x8x.default\" /y/c/i
REM this is for Opera
XCOPY "C:\Documents and Settings\Adam\Application Data\Opera\Opera\profile\opera6.adr" "C:\backups\bookmarks\Documents and Settings\Adam\Application Data\Opera\Opera\profile" /y/c/i
REM this is to RAR everything and then delete the copies you made with the above commands
"C:\Program Files\WinRAR\WinRAR.exe" A -r -M3 -MD4096 -Y -O+ -EP -ac -isnd -vn -ep1 "C:\backups\bookmarks.rar" "C:\backups\bookmarks\*.*"
RMDIR "C:\backups\bookmarks" /q/s

Some of this should look somewhat familiar from last time.  IE6’s backup procedure is fairly straight forward.  Just copy the directory to your backup folder to be RARed later.

Next, we have FireFox’s bookmarks, which are contained inside an HTML file.  So, in order to copy that file, you must find out exactly where it is since the containing folder may be different on your machine.  Also, take note that the command switches at the end of that line are different.  This is so only the HTML file is copied, and not all the other files and sub directories.  Also note that the destination path must end with a backslash when copying an individual file.

Opera is much the same as FireFox.  Simply find where the opera6.adr file is located and use that path and the same command switches at the end.

Finally, the last two commands RAR everything together then delete the copies you made, leaving you with the RAR archive.

Neat, huh?

Alright, so no you should have “My Documents” being backed up with one batch file and your bookmarks with another.  How do you call them together so you can just double click on one batch file and let it run while you get a snack or coffee?

For the sake of this example, we’re going to call the My Documents backup file “my_docs_backup.bat” and the bookmarks backup file “bookmarks_backup.bat”

So, like in the beginning of the first backup article, create a new batch file, but name it “full_backup.bat”.  Place all three batch files into the “C:\\backups” directory.

This is going to be the “full_backup.bat” file you execute to get the other two to run.  Here’s what goes in it:

@echo off
title full backup

call "C:\\backups\\bookmarks_backup.bat.bat"
call "C:\\backups\\my_docs_backup.bat.bat"

The call command executes each batch file, but waits before the first one is done before moving onto the second.  In this fashion (with single-core CPUs, anyway), these backups are complete faster since they don’t have to compete with each other for CPU horsepower if they’re both running at the same time.

So now, you can go ahead and create your own set of regular backups!

Now, to restore these directories/files, all you have to do is unzip them on the root of your drive (C:), and they will be automatically placed in the proper directories so long as the folder names remain the same (they may change when you uninstall/reinstall the program(s)).  You can choose to overwrite older files if you wish when you unzip them.  This brings to light the other reason to keep these separate.  If you try to backup everything in one RAR archive, you risk overwriting everything when you go to unzip it.  So, by separating bookmarks and My Documents and whatnot, you can pick and choose what you want to restore.

(Continue to Part III here)

(Originally published on a now-defunct blog)