Recipe 19.8. Using XCOPY for Interim Backups


Problem

You want a simple, straightforward way t o make backups of your current working data throughout the day, and you don't want to have to launch the Backup applet.

Solution

Using a command-line interface

Use xcopy from the command line to perform easy, relatively fast incremental backups. This recipe assumes that you're connected to a network with available shares to map to a drive letter or that you have multiple hard drives that are assigned different drive letters and that you (and other users on your machine) store data within your individual My Documents folders.

Type the following into Notepad and save as backup.bat:

@echo off Cls Net use k: \\machinename\backupshare K: xcopy c:\docume~1\*.* /s /e /a /h /c c: cd \docume~1\ attrib *.* -a /s net use k: /disconnect

To run the file, double-click on it, open a command prompt and type its name on the command line, or set it as a scheduled task to run at a specified time during the day regularly.

Discussion

This script maps drive K to a target share on another machine, and then copies the entire contents of the Documents and Settings path on your local hard drive to the remote share using the xcopy command. The /s option tells xcopy to copy subdirectories of Documents and Settings; the /e option tells it to copy subdirectories that contain no files; the /a option tells it to copy only files that have the archive bit set on in effect, the copy will process only those files that have been created or changed since the last backup; the /h switch copies hidden files and folders; the /c option tells xcopy to continue the operation even if it encounters an error, like a PST file being open. Without that /c option, xcopy blows up and dies on the first error it encounters.

Once the xcopy operation completes, the batch file runs the attrib command on the local Documents and Settings folder, which sets the archive bit off for all files (the /a switch) and processes subdirectories (the /s option). All files within that folder are marked as being backed up, so the next time the batch file is run it copies only files that have been created or changed since the last time it was run.

See Also

MS KB 128756, "Command Line Switches for the XCOPY Command," and MS KB 289493, "Switches That You Can Use with Xcopy and Xcopy32 Commands"



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net