Backup and synchronization are inevitable problems when you work on more than one computer. There are two issues: 1) backing up work you have just performed and 2) transferring files to another computer without accidentally over-writing newer versions. The problem is of particular concern for me as a software developer working in a variety of locations. I am reluctant to use commercial backup programs. They generally have far more features than I need, and I don’t feel that I am completely in control. In this article I wanted share a simple but effective system that I use for synchronization. Although the procedure may be obvious to an experienced computer user, I feel it is worthwhile to document it for people who are not familiar with batch files.
Step 1
The critical thing to realize is that if you only record essential files, you can probably fit your entire professional life on one 8 GB USB Flash Drive. Get a good quality USB stick.
Step 2
The computers that you use must have the same data directory structure. For example, I keep all computer programs in a directory c:\progdev. This directory has the same structure on all my computers although individual files may change as I work on projects. To begin your data organization, pick one computer as the master.
Step 3
Use a text editor to create a file CDriveToUSB.bat in the root directory of the USB drive. Here is an example of the content:
REM Software backup: Disk C to USB xcopy /S /D /F /Y C:\PROGDEV\*.f90 \PROGDEV\*.f90 xcopy /S /D /F /Y C:\PROGDEV\*.f \PROGDEV\*.f xcopy /S /D /F /Y C:\PROGDEV\*.rc \PROGDEV\*.rc xcopy /S /D /F /Y C:\PROGDEV\*.cur \PROGDEV\*.cur xcopy /S /D /F /Y C:\PROGDEV\*.ico \PROGDEV\*.ico xcopy /S /D /F /Y C:\PROGDEV\*.bmp \PROGDEV\*.bmp xcopy /S /D /F /Y C:\PROGDEV\*.wpj \PROGDEV\*.wpj
The batch file invokes the DOS XCopy command, described at
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true
The first entry after the switches is the source directory and the final entry is the destination directory. The switches serve the following functions:
/S ? Copy from C:\PROGDEV and all its subdirectories
/D ? Copy only files that are newer than those in the destination directory
/F ? Display the file names while copying
/Y ? Suppress confirmation prompting
The key to a compact backup is to pick only the critical file types. In the example, the batch process saves files of source code, Windows resources, cursors, icons, toolbars and projects. Executables and compiled object files (which take up the most space) are not saved because they may be easily regenerated. With a batch file, you can customize the procedure to fit your data structure and to set the relative importance of material. You needn’t worry about getting everything perfect the first time. You can always add entries later.
To continue, run the batch file on the master computer.
Step 4
Create another file USBToCDrive.bat on the USB drive. This file is the inverse of the first one with an additional line:
REM Software restore: USB to Disk C xcopy /S /D /F /Y \PROGDEV\*.f90 C:\PROGDEV\*.f90 xcopy /S /D /F /Y \PROGDEV\*.f C:\PROGDEV\*.f xcopy /S /D /F /Y \PROGDEV\*.rc C:\PROGDEV\*.rc xcopy /S /D /F /Y \PROGDEV\*.cur C:\PROGDEV\*.cur xcopy /S /D /F /Y \PROGDEV\*.ico C:\PROGDEV\*.ico xcopy /S /D /F /Y \PROGDEV\*.bmp C:\PROGDEV\*.bmp xcopy /S /D /F /Y \PROGDEV\*.wpj C:\PROGDEV\*.wpj REM Precaution against loss of the USB drive xcopy /S /D /F /Y *.* C:\USBBACKUP\*.*
To be safe, rename your data directories on the slave computer(s) before doing anything else. Keep the old directories for a few weeks in case they contain a newer version of a task that you forgot. Then, insert the USB drive and run the restore batch file.
Here’s how the system works:
- When you begin work on a computer, insert the USB drive and run USBToCDrive.bat to make sure the computer is up to date. The process also makes a backup copy of the full content of the USB drive.
- When you are finished, run CDriveToUSB.bat.
It’s that simple!
Two final comments:
- It’s useful put shortcuts to the two batch files on the desktops to minimize work and to act as a reminder.
- Because the USB drives may be assigned different drive letters on different computers, the batch files must be on the USB drive and make no absolute reference to its location.
