by Andrew Block
Need an easy way to back up your files, but don’t feel like monkeying with expensive or complicated software? Using the xcopy command and a simple text file, you can accomplish this rather easily. Here’s what I do.
First, make sure that file extensions are not hidden by going to My Computer > Tools > Folder Options > View. Uncheck Hide Extensions for Known File Types and click OK (if it’s already unchecked, don’t worry about it).
Now create a blank text document on your desktop. Rename it to backup.bat. Now right click on the newly created file and click Edit. Do not just double click, because that will actually run the batch file—we want to edit it for now.
The syntax for xcopy is pretty simple:
xcopy <source location> <destination location> /switch
And then there are a bunch of switches you can use. I’ll give you an entry from my batch file, and then I’ll explain what the switches all do. To copy my files from my hard disk to my USB drive, I use (follow the syntax exactly, including the quotes!):
xcopy "C:Docs*.*" "G:ANDYBDocs" /d /s /e /c /i /h /r /k /o /y /f
As you can see, wild card characters can be used to filter your backup. I just use *.* to get everything. Now, the switches:
Copies only source files that are newer than existing destination files. Basically, existing source files that have not been modified since the last backup will not be copied, saving time (if you’re like me and have 50GB of MP3s, this is an essential switch!)
Copies directories and subdirectories. This is a very important switch, as most of us will have stuff in subdirectories we want to back up.
Copies empty subdirectories. I use this, although I probably don’t really need to.
Ignores errors. This alone is the reason I love xcopy: one corrupted file can bring XP’s regular file copy to a screeching hault. But with xcopy and this switch enabled, corrupt files are skipped and your backup continues (FYI: the regular Vista copy is smart like xcopy, and will do the same thing).
If Source is a directory or contains wildcards and Destination does not exist, xcopy assumes destination specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xcopy prompts you to specify whether Destination is a file or a directory (directly from MS…I don’t fully get this one, but it works better with it enabled).
Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files.
Copies read-only files.
Copies files and retains the read-only attribute on destination files if present on the source files. By default, xcopy removes the read-only attribute.
Copies file ownership and discretionary access control list (DACL) information.
Suppresses prompts (overwrites existing files automatically). Unless you want to babysit your backup, you’ll want to enable this option for sure.
This shows the full source & destination paths of each file being copied.
There are other switches, like /exclude, which—surprise—allows you to exclude one or more files and/or directories. Finally, to run your batch file, simply double click it. Again, remember if you want to edit it, you right-click and choose Edit.
If you want to be really nerdy, you can have xcopy output everything to a log. I guess if you want an inventory of everything that has been backed up, this might be useful to you. Just add > [drive]:log_file_name.txt to the end of each xcopy entry. For example:
xcopy "C:Docs*.*" "G:ANDYBDocs" /d /s /e /c > c:backuplog.log
To append an existing log, use >> [drive]:log_file_name.txt, like this:
xcopy "C:Docs*.*" "G:ANDYBDocs" /d /s /e /c >> c:backuplog.log
Now if you want to get really lazy, you can set your batch file to run as a scheduled task. Most people know how to use the task scheduler in Windows, so I won’t go into that for now…unless someone demands it!