MIRROR

MIRROR is an easy-to-use Windows command line utility that is used to maintain an exact copy of a directory structure and its contents at another location. It is perfect for maintaining a backup copy of your hard disk on CD-RW or ZIP disk. It is similar to "XCOPY /S /H /K" but with the following additional features:
  1. If a file is removed from the source directory tree, MIRROR will delete it from the destination directory tree (with optional verification based on file type).
  2. If a file is moved to a different subdirectory in the source directory tree, MIRROR will move it in the destination directory tree.
  3. Files are copied from the source to the destination if any of the following conditions are true:
    1. The source file's archive attribute is turned on (if used with the /A or /M option)
    2. The source file's size is different than the destination file's size
    3. The source file's date/time is different than the destination file's date/time
  4. The destination directory tree is cached in memory to minimize access to the destination disk. This can speed up backups to CD-RW significantly.
  5. All user prompts are displayed before any modifications are made to the destination directory tree. This makes backups to slow CD-RW much more convenient, since you don't have to wait for the operation to be performed in between each prompt.
MIRROR can be used in batch files for backing up multiple directory structures as part of a larger backup script. For example, the following batch file could be used to backup the contents of your "My Documents" and "My Pictures" directories to a CD-RW disk on drive E:

  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.

Command Line Syntax

The command line usages message is shown below. You can display this message at any time by typing "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.

The Benefit of the Move Operation

MIRROR can be used to maintain a backup copy of a disk on another disk.

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:

  1. Delete all files from destination disk that do not exist at the same location on the source disk.
  2. Copy all new or updated files from the source disk to the same location on the destination disk (XCOPY can do this).

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 Compatibility

MIRROR maintains some syntax compatibility with the Windows XCOPY command. Below is an annotated list of the XCOPY command line parameters:

  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.


Copyright 2000, 2001 by Christopher P. LaRosa <cplarosa@yahoo.com>
Last Update:  March 21, 2001