| MICRO CENTER, COMPUTERS & ELECTRONICS · MICRO CENTER ONLINE | ||||
![]() |
||||
| Using XCOPY to Back Up Files and Settings
One method of backing up your files to another location under Windows can be accomplished using the XCOPY program in a Command Prompt window. You can also build a text batch file that will execute one or more XCOPY commands in a sequence and then configure a scheduled event to execute your file at a specified time or interval. A batch file is nothing more than a text file with a series of command line strings listed in the order of execution. To avoid entering commands that are invalid or might generate errors, you can always enter the command manually in a command window, and then copy it into the text file. To create a batch file script that copies a group of common files and settings to another drive or network share, you will need to identify what directories or files you want to duplicate. To archive most of the normal document and media files, favorites, and desktop configuration of the different users, you will want to duplicate at least the following three locations:
Add to these any other files or directories where important data is being saved, and keep in mind that the locations specified here already include "My Documents" and all the other sub folders under it, including "My Music" "My, Pictures", etc. If you are running applications that store their data somewhere else, you need to determine the file path being used. Program files rarely benefit from being backed up, but since "legacy" settings and scripts may be saved to the application directory, building an archive with these program directories makes sense. You would still have to reinstall the application to build the necessary registry changes and to install the program libraries, but once your archived directory is copied over the top of the fresh install, all of your settings should be restored in most cases. By using the complete path in the command, the batch file should not need to be running from the root directory, and you can specify multiple paths or drive letters in the same script. Using the directory examples listed above, an XCOPY backup batch file might look something like this:
The first time these commands are run, if the target directory structure does not exist, you should receive a prompt asking something like: "Does D:\backup location\Procomm specify a file name or directory name on the target (F = file, D = directory)?" Be sure to answer "Directory" or else you will end up with a really big file containing all of the content of the original files, and no way to split-out or identify anything useful in it. You can always start off by drag-and-drop copying the directories to the target drive from within Windows to avoid this, but if you receive an error, the copy process will terminate. Note the use of quote (") marks around the source and target paths; these are necessary because of the spaces included in the long filename path. The command line toggles I have selected here will make sure that: (/r) Read-only files are over-written, (/e) Empty directories and subdirectories are duplicated, (/h) hidden files are copied, (/k) File attributes are copied, (/c) xcopy will continue to execute even if errors are encountered, and (/y) xcopy will not pause to prompt for your decisions. Build your batch file: 1. Open "My Computer" or some other location where you want to store the batch file. 2. Right click and select "New", "Text Document". A new_text_document.txt file will be created and is selected for renaming. 3. Enter a name for your file and change the extension from .txt to .bat, such as "archive.bat" 4.You should receive a warning that changing the extension could make the file unusable. Click "Yes" to confirm the change. 5. Right click on the file and select "Edit". The empty file should be opened in NotePad. 6. Open a command prompt window for testing your xcopy commands. Click Start, Run, enter "CMD" in the open box (without the quotes) and click "OK". 7. Build your xcopy commands in the NotePad document. To do this using one of the following methods:
8. Save the file once all your lines have been created. XCOPY Notes: To execute the batch file, just double click on the icon. You can create shortcuts to your start menu, desktop, or any other location you find convenient. To add this to the Windows Task Scheduler so that it runs automatically, open Control Panel and then open the "Scheduled Tasks" tool (classic view; under task view, select "Performance and Maintenance" and then click on "Scheduled Tasks" at the bottom of the window.) Double click on "Add a Task" and follow the prompts to configure when to run the batch file. To do this:
Reduce the time it takes to copy files by adding a "/M" option to the lines to copy only files that have been modified since the last copy. Note that if you use programs that clear the "archive" file attribute, it is possible that xcopy could miss a file now and again. To run the xcopy batch file in a minimized window, create a shortcut to the batch file; right click the shortcut and select properties; on the "Shortcut" tab, change the "Run" option from "Normal Window" to "Minimized" and click OK to save the change. If you are using Task Scheduler to run the file, browse to the shortcut instead of the batch file itself. Entering " XCOPY /? " at a command prompt will display the help screen for using XCOPY to replicate files and directory structure. The syntax and possible command line switches for XCOPY are shown here:
|
Understanding
Tech |
|||
|
|
||||
© 2008 Micro Electronics, Inc. |
||||