DEL C:\Backup.log MIRROR "C:\My Documents" "E:\My Documents" /M /C /L:C:\Backup.log /P*.doc /R /W MIRROR "C:\My Pictures" "E:\My Pictures" /M /C /L:C:\Backup.log /P*.bmp /R /W
The log file "C:\Backup.log" will list the operations that were performed and any errors that occurred.
If you had used the XCOPY command instead of MIRROR in the batch file above, after repeated backups your backup CD would eventually fill up with files you had deleted or moved to different directories in your hard disk. If you then wanted to restore those directories, you wouldn't know which files on your backup CD were current and which had been deleted or moved. MIRROR eliminates this problem by making sure your backup disk always has exactly the same files that are on your hard disk.
MIRROR /?" at the command line:
MIRROR, Directory Tree Duplication Utility, Version 1.07
Copyright (c) Christopher P. LaRosa 2000-2001
Creates an exact copy of a source directory tree in a destination directory.
Files in the source directory are copied to the destination directory if they
do not already exist or if they have a different size or time than the existing
destination file. Hidden and system files are also copied. File attributes
are copied along with each file (including read-only, hidden, and system).
Previously copied files that have been moved in the source tree are moved in
the destination tree instead of being deleted and recopied (unless /D is used).
Any files or directories that do not exist in the source directory tree are
deleted from the destination directory tree.
MIRROR source destination [/1] [/A | /M] [/B] [/C] [/D] [/F] [/L:filename]
[/N] [/O] [/P[:filespec [/P:filespec [...]]]] [/Q | /V] [/T] [/R] [/W]
source Source directory.
destination Destination directory. If this path does not exist,
it will be created (including all path elements).
/1 Mirrors only the specified directory (no subdirectories).
/A Copies files with the archive attribute set, and
doesn't change the source file's archive attribute.
/M Copies files with the archive attribute set, and
turns off the source file's archive attribute.
/B Buffers the source directories in memory (may be faster).
/C Continues mirroring even if errors occur.
/D Doesn't move files in the destination. Deletes and recopies.
/F Displays full source and destination file names.
/L:filename Appends a log of operations performed to file "filename".
/N Displays changes that would be made, but doesn't make them.
/O Prompts you before overwriting or deleting existing files.
If used with the /P:filespec option, then prompting will only
occur if the file name matches filespec.
/P:filespec Prompts before deleting file names which match "filespec"
(filespec may contain the wildcard characters * and ?).
If no filespec is given, it prompts before deleting any file.
This option may be repeated for multiple filespecs.
/Q Doesn't display operations being performed (quiet mode).
/T Compare timestamps using a +/-2 second tolerance.
/V Displays all steps, even if no files are affected (verbose).
/R Overwrites and/or deletes read-only files.
/W Displays a summary of operations that will be performed, and
prompts you to press a key before mirroring.
A non-zero exit code is returned if one or more errors occur.
For example, I use MIRROR to backup the "My Documents" directory on my hard disk to a CD-RW disk using packet CD (UDF file system). Packet CD allows me to access my CD-RW drive like a floppy disk. To backup the "My Documents" directory to my CD-RW drive (drive H:), I type the following command line:
MIRROR "C:\My Documents" H:\
The basic mirror process works as follows:
Step 1 must be done before step 2 to prevent a destination disk that is almost full from exceeding its capacity. Unfortunately, this simple process has a flaw. If you rename a directory on your source disk, all the files in that directory will be deleted during step 1 and then recopied during step 2. If your source disk crashes after step 1 and before step 2, you've lost the entire contents of the renamed directory on both your source disk and your destination disk! And all because of a simple rename. The same problem occurs if you simply move files between subdirectories.
To prevent the risky steps of deleting and recopying files that have simply been moved on the source disk, MIRROR automatically detects files that have been moved and performs a corresponding move operation on the destination disk. The moved files are never actually deleted from the destination disk, and therefore your backup copy always exists.
XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/W]
[/C] [/I] [/Q] [/F] [/L] [/H] [/R] [/T] [/U]
[/K] [/N]
* source Specifies the file(s) to copy.
* destination Specifies the location and/or name of new files.
* /A Copies files with the archive attribute set,
doesn't change the attribute.
* /M Copies files with the archive attribute set,
turns off the archive attribute.
! /D:date Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
! /P Prompts you before creating each destination file.
# /S Copies directories and subdirectories except empty ones.
# /E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
* /W Prompts you to press a key before copying.
* /C Continues copying even if errors occur.
# /I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
* /Q Does not display file names while copying.
* /F Displays full source and destination file names while copying.
* /L Displays files that would be copied.
# /H Copies hidden and system files also.
* /R Overwrites read-only files.
! /T Creates directory structure, but does not copy files. Does not
include empty directories or subdirectories. /T /E includes
empty directories and subdirectories.
/U Updates the files that already exist in destination.
# /K Copies attributes. Normal Xcopy will reset read-only attributes.
# /Y Overwrites existing files without prompting.
* /-Y Prompts you before overwriting existing files.
/N Copy using the generated short names.
Parameters marked with a green asterisk (*) function basically the same in MIRROR as they do in XCOPY (with some minor variations). Parameters marked with a blue number sign (#) are allowed on the MIRROR command line, but specify options that are enabled by default. Parameters marked with a red exclamation point (!) have a different function in MIRROR than they do in XCOPY.