Introduction: This article aims to teach its readers how to use batch files to backup files. It wouldn't be possible without this article, which shows you how to backup via a network.
The methods explained here simply involve copying files from one location to another, which creates duplicates of the files. These duplicates can be on any number of storage devices, such as floppy discs, removable or fixed hard-drives, usb drives, or storage on a network.
Simple: I've uploaded a simple version of a backup batch file here. It backs-up several drives simultaneously. What we're concerned with is the line:
xcopy e: i: /E /H /Y
Take the first part xcopy e:. It uses a command built into Windows called xcopy. This part is telling Windows to use the xcopy function on the e: drive. The second part states:
i: /E /H /Y
This is telling Windows to copy the e: drive to the i: drive. A simple backup, which could exist in a system that had two hard-drives, one a fixed data drive, the second a removable backup drive. The commands following i: dictate several additional functions that are associated with xcopy. I've uploaded an image showing all of xcopy's switches available here. Use it to work out what switches I'm using in the above example.
So, you now know how to copy data from one drive to another using xcopy. Let's put this to use... We need to backup the d: drive on a computer, which holds all our documents, to a backup drive labelled e:
xcopy d: e: /E /H /Y
Again, work out what switches are used here, and refer to the xcopy switches to decide if you need any additional ones in your situation.
Network: At home I have a simple network setup, with 5 clients and 1 fileserver. I regularly backup my laptop to the fileserver, and on a fortnightly basis I backup the fileserver to a removable 160gb drive. Backing up via a network can be achieved using two methods. The first involves mapping a network drive(s) and then using the mapped drive for backup. For more information on network drive mapping, see this article.
The other method simply uses network administrator shares, and the computer's name:
\fileserver\d$
Using the above as the file destination will copy the files to the d$ administrator share on the computer named fileserver, otherwise known as the d drive. Using the knowledge on network drives, we can now create a backup batch file that backs up via a network instead of on the local machine, for example:
xcopy c: "\fileserver\d$" /E /H /Y /D /F /R
This copys the c: drive on the local machine to the d: drive on a computer named fileserver on the network.
Advanced: If you wish to use specific folders for backup, instead of drive letters, then read on...
Again, I've uploaded an example .txt file here for you to use as a reference when writing your own backup batch files. Take the following line from the example:
xcopy "C:\Documents and Settings\All Users\Documents" "S:\All Users\Documents" /E /H /Y /D /F /R
It uses the xcopy function to copy the Shared Documents on the computer's c: drive, to a folder named Documents within the folder All Users on the s: drive. Again, work out what switches have been used.
Note that if you wish to specify a location other than a drive letter, then you need to include speech marks before and after. For example:
C:\Documents and Settings
becomes:
"C:\Documents and Settings"
If you're having problems with your batch file, then this may be the cause.
Conclusion: If you follow this article carefully, and use the linked files as a reference, then you should have created your own backup batch file! Feel free to play around with your batch file until you get the setup you desire.
For the ultimate in backup, I'd recommend using a removable drive, and creating a batch file to backup all your important data to the drive. Then you can simply connect the drive, execute the batch file and you're done. Or alternatively, you can setup the batch file to run at specified times during the week, via Scheduled Tasks in the Control Panel.