Example of Simple Windows Xcopy Script Backup
Xcopy is a powerful tool for duplicating data, and it is included natively in Windows.
To set up an Xcopy script to handle a simple backup, follow these steps:
1. Connect your external hard drive, and make a note of the drive letter it is assigned by Windows (the rest of this example will assume the external drive was given the R:\ letter designation).
2. Open notepad, by going to Start, Run, and type "Notepad.exe" and click ok.
3. In notepad, type the following: xcopy [the folder you want to back up] [folder on the external drive you want to copy to] and then add the relevant switches. For example:
xcopy E:\data\files\*.* R:\backup\files\ /c/d/e/h/y/i
4. Save the file, and rename it from .txt to .bat.
5. Use Windows Scheduled Tasks to run the batch file on a schedule.
This script will make an exact copy of the original folder on the external drive. To restore a file, you simply browse to its location in the backup folder, and copy it wherever you like.
Remember, if there's a space in the path, you need to put quotation marks around the path. For example: xcopy "E:\data\New Files\*.*" "R:\backup\new files".
In the example above, the switches are as follows:
- /c - tells xcopy to continue the process if there's an error copying a file.
- /d - tells xcopy to copy only files that are newer than the same files in the destination.
- /e - tells xcopy to copy directories and sub-directories, even if they're empty (remember: "e for everything").
- /h - tells xcopy to copy hidden files.
- /y - tells xcopy not to ask you to confirm each file.
- /i - tells xcopy that if the destination does not exist already, and you're copying multiple files, assume the destination is a directory.
For more information on what the different switches do, click here.
Limitations to Xcopy:
- Xcopy will not copy any files that have more than 254 characters in their file path.
- Files that are removed from the live data are not removed from the backup, so the data has to be removed from time to time.
- There is no data compression like there is with programs like Backup Exec.
- Cannot make copies of open files.