Saturday, February 28, 2009

How to Synchronize Directories on a Network or PC

You really should create a backup of your valuable data, because otherwise in the event of a hard drive failure, that data could be lost. Today, many people store their photographs in digital format, printing only the choicest ones. The very thought of losing an entire lifetime's worth of digital photos is troubling. Some of us also have journals, diaries, spreadsheets and other personal material stored on a hard drive that would be difficult or impossible to replace if it were ever lost. Everyone knows that hard drives eventually fail and that their time of failure is not always predictable. Therefore, we must all backup our important data.

My method of backing up valuable data relies upon two strategies. For critical files and folders, I burn a backup on DVD, which is the most secure and foolproof method of backup. A DVD placed inside a plastic case out of harm's way can endure for decades, although not forever, according to some research. I believe the lifespan of a DVD ranges from 10 to 50 years. Over time, even DVDs deteriorate, however at a much slower rate than hard drives.

For data that encompasses hundreds of gigabytes, DVD's are impractical. Backing up the contents of a 500-gigabyte drive would require over one hundred 4.3 gigabyte DVD's, though slightly less if you compressed the data. This is not an especially good option, unless you cherish the thought of shifting DVD's in and out of a drive all day long and all night long.

For large amounts of data and for automated backups, I take advantage of the multiple hard drives on various PC's in my network. Hard drives fail individually, rather than all at once. If one fails, I will always have a backup of the important files on another drive. This concept is known as data redundancy. In this case, I am simply using spare space on networked drives. I have not purchased any additional hardware dedicated to making backups, although many businesses do just that. To gain a better appreciation for my particular strategy, examine the prices of dedicated backup systems, such as tape drives.

Always backup your data to a different physical hard drive and never the same drive! The entire purpose is to save your bacon in the event of physical hard drive failure.

The following is a very simple method of mirroring a single folder or collection of folders, but not an entire hard drive. The trouble with copying an entire drive is that it would take many hours in today's world of thousand-gigabyte hard drives. There is no reason to copy Operating System files or Program Files. What most people want to backup are things like their personal family photo album, documents, spreadsheets, and music. The backup should be as quick as possible, and therefore only copy those files that have changed in some way. Longtime readers of my blog will not be surprised to discover that, here also, my solution involves writing a handy-dandy batch file:

igor-quick-and-dirty-backup.bat
-------------------------------

@echo off
cls
echo.
echo.Synchronizing directories...
echo.
echo NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN | xcopy "c:\Photo Album\*.*" "\\kitchen_computer\backup_directory" /D /S
echo.
exit

---------

Due to word wrap, the one truly essential line in the above batch file appears like two or even three separate lines, but you must place all of it on one long line. I refer to the line with an "echo" of a long string of N's followed by the pipe symbol, "|", directing the output into the Xcopy command.

The meat of the batch file is the Xcopy. That's right, the humble Xcopy command is all that is needed to copy all the files within a folder. Some may ask, why not just use Copy? In this instance, Xcopy is better than Copy, because with Xcopy, using the "/S" option, you can access all of the subdirectories as well as the files. The "/D" option instructs Xcopy to only copy those files with a newer date than the ones that may already exist on the destination folder. The first time you run the backup, this will make no difference at all, because all files must be copied. However, on future occasions, this will make a great deal of difference, because only new files will be copied.

However, the Xcopy command is not perfect the way that Microsoft designed it. Even with the "/D" option, I have discovered that Xcopy will sometimes attempt to copy files that don't really need to be copied. These are cases where an exact copy already exists on the destination drive. This highlights a drawback with the Xcopy command. Microsoft failed to provide for what to do if an exact copy of a file already exists. If you always want to overwrite the Destination, a suitable option is provided. If you prefer to answer in the negative, Microsoft would have you press "N" for every instance that this occurs. I overcome this limitation on the part of Windows by echoing a long series of "N," hopefully enough to select "No" at every instance when Windows asks the not-very-bright question, "Do you want to overwrite the destination file, which already exists and is an exact copy?"

Some may argue that by copying a file unnecessarily, at least we create a stronger magnetic impression on the destination disk. If this is your response, please report to the Wienie Registration Bureau and add your name to their list.

This batch file does the trick of backing up your important files with a minimum of fuss and best of all is free. What's that? Thanks? You're welcome. If you wish to control your backup procedures manually, then I suggest creating a shortcut to the batch file on your desktop. If, like me, you prefer the backup to run automatically, then schedule an automatic event in Windows to run the batch file at a certain time every day or once a week. Just visit your Control Panel, go to Scheduled Tasks, and Add a Task.

No comments:

techlorebyigor is my personal journal for ideas & opinions