To keep five copies of a target folder synchronized with a source directory, you must use the Robocopy command with the
/MIR switch. This flag mirrors the source tree, including deletions, ensuring the destination matches the source exactly. You should run this command in a loop or schedule it to maintain the required number of backups without manual intervention.
Understanding the Mirror Switch
The core challenge in maintaining multiple identical folders is handling file deletions. If you simply copy new files, old files that were removed from the source will remain in your backup folders, causing divergence. The
/MIR (Mirror) option solves this by performing a two-way sync: it copies new and updated files from the source to the destination, and crucially, it deletes files in the destination that no longer exist in the source.
When you use
/MIR, Robocopy replicates the entire directory structure. This includes empty directories if they exist in the source. It is important to note that
/MIR is equivalent to using both
/E (copy subdirectories, including empty ones) and
/PURGE (delete files and directories in the destination that no longer exist in the source). Using
/XO (exclude older files) alongside
/MIR is incorrect because
/XO prevents the deletion of older files, which directly contradicts the purpose of mirroring where the destination must reflect the current state of the source.
Configuring Multiple Target Copies
Robocopy only accepts one destination path per command execution. Therefore, to maintain five separate copies, you cannot list all five destinations in a single command line. Instead, you must execute the Robocopy command five times, once for each target folder. You can automate this process using a batch script or a scheduled task.
Here is the basic structure for a single synchronization step:
robocopy "C:\SourceFolder" "D:\Backup1" /MIR /R:3 /W:5
In this example, replace
"C:\SourceFolder" with your actual source path and
"D:\Backup1" with the first backup location. The
/R:3 parameter sets the number of retries on failed copies to three, and
/W:5 sets the wait time between retries to five seconds. Adjust these values based on your network speed and storage reliability.
To create five copies, you would repeat this command four more times, changing the destination path for each iteration:
robocopy "C:\SourceFolder" "D:\Backup1" /MIR /R:3 /W:5
robocopy "C:\SourceFolder" "D:\Backup2" /MIR /R:3 /W:5
robocopy "C:\SourceFolder" "D:\Backup3" /MIR /R:3 /W:5
robocopy "C:\SourceFolder" "D:\Backup4" /MIR /R:3 /W:5
robocopy "C:\SourceFolder" "D:\Backup5" /MIR /R:3 /W:5
This approach ensures that each backup folder is an independent mirror of the source. If a file is deleted from the source, it is removed from all five backup locations. This method avoids the complexity of managing symbolic links or complex directory structures that might lead to infinite duplication loops. For more details on preventing such issues, see
Avoiding Infinite Subfolder Duplication with Robocopy on Windows.
Optimizing Performance and Reliability
Running five full mirror operations can be resource-intensive. To optimize performance, consider adding logging options. The
/LOG+: switch appends log information to a specified file, which helps in troubleshooting future synchronization issues. Without logging, determining why a specific file was not copied or deleted can be difficult.
robocopy "C:\SourceFolder" "D:\Backup1" /MIR /R:3 /W:5 /LOG+:C:\Logs\sync_backup1.log
Additionally, you may want to exclude certain temporary files or system folders that do not need to be backed up. While
/MIR handles the main synchronization, adding
/XF (exclude files) and
/XD (exclude directories) can reduce the load on your storage system. However, be cautious when excluding files during a mirror operation, as this can lead to inconsistencies if the exclusions are not applied consistently across all five targets.
It is also advisable to check the exit codes returned by Robocopy. A standard success code is 0, but codes 1-7 indicate various states of success with warnings (e.g., some files were skipped). Monitoring these codes allows you to detect failures early. For deeper insights into error handling, refer to
Understanding Robocopy's /PURGE and /MOVE Options.
Scheduling the Synchronization
Manual execution is prone to human error. Use Windows Task Scheduler to run your batch script at regular intervals. Create a new task that triggers either on a schedule (e.g., every hour) or on system startup. Ensure the task runs under an account with sufficient permissions to read the source and write to all five backup destinations.
When configuring the task, specify the action as "Start a program" and point it to your batch file. In the "Add arguments" field, you can pass any additional parameters if your script requires them. Set the task to run whether the user is logged on or not to ensure background synchronization.
Remember that network latency can affect the speed of synchronization, especially if your backup drives are located on a different server. Using the
/MT:n switch (where
n is the number of threads) can significantly speed up large file transfers. For example,
/MT:8 uses eight threads to copy files in parallel. This feature is particularly useful when dealing with thousands of small files, as it reduces the overhead of opening and closing individual file connections.
Verifying Synchronization Integrity
After setting up your five copies, verify that they are truly synchronized. You can do this by creating a test file in the source folder and checking if it appears in all five backup locations within the expected timeframe. Conversely, delete a file from the source and confirm its removal from all backups.
If discrepancies arise, check the log files generated by Robocopy. Look for errors related to access permissions, disk space, or file locking. Ensure that no other processes are actively writing to the backup folders during the synchronization window, as this can cause transient errors. Regularly reviewing these logs helps maintain the integrity of your backup strategy over time.
Frequently Asked Questions
Can I use /MIR with a network share?
Yes, you can use
/MIR with network shares, but ensure you have proper read/write permissions on both the source and destination paths. Network latency may slow down the synchronization process, so consider increasing the retry count and wait time parameters.
What happens if a backup drive is offline?
If a destination drive is offline or disconnected, Robocopy will skip that specific copy operation and return an error code indicating failure. The other four backups will still be updated successfully. Check the logs to identify which backup failed and reconnect the drive before the next scheduled run.
Is there a way to sync only changed files instead of mirroring everything?
Yes, you can use the
/COPYALL switch combined with
/TEE and
/NP for a simpler output, but for true synchronization without deleting old files, avoid
/MIR. Instead, use
/E to copy subdirectories and let Robocopy handle updates naturally. However, this means deleted files in the source will remain in the backup.
How do I prevent accidental data loss during mirroring?
Always test the
/MIR command on a small subset of data first. Consider keeping one backup folder without the
/MIR switch (using only
/E) as a safety net to preserve historical versions of deleted files. Review the documentation on
Understanding Robocopy's /PURGE and /MOVE Options to understand the risks involved.
Can I use Robocopy to sync more than five copies?
Absolutely. The logic remains the same: execute the Robocopy command once for each target destination. Whether you need ten copies or twenty, simply add more lines to your batch script or scheduled task sequence, adjusting the destination paths accordingly.