Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › backup safety

How to Mirror Folders with Robocopy Without Accidentally Deleting Files

By Freedom251 Team · · 12 min read

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Robocopy’s /MIR switch can delete files. It creates a destination tree that matches the source by combining recursive copy with purge behavior, so destination-only files and folders are removed. To mirror safely, verify both paths, preview the exact command with /L, inspect the log, and only then remove /L for the live run. If files at the destination must be retained, use a non-purging copy such as /E instead of /MIR.

What Robocopy “mirror” actually does

Robocopy is the Windows command-line utility for copying directory trees. A mirror is stricter than an ordinary copy: after the operation, the destination is intended to contain the same files and directories as the source. That requires removing destination items that have no counterpart in the source.

As an Amazon Associate I earn from qualifying purchases.

Microsoft documents /MIR as equivalent to /E plus /PURGE. /E copies all subdirectories, including empty ones; /PURGE deletes destination files and directories that no longer exist in the source. Consequently, a command such as robocopy "C:Source" "D:Backup" /MIR can delete an item from D:Backup when that item is absent from C:Source. The deletion is expected mirror behavior, not a Robocopy error.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The authoritative option definitions and syntax are in Microsoft’s Robocopy command reference. Treat every example below as a template: replace the example paths with paths from your own computer and verify them before pressing Enter.

#1 Best Overall
WD 2TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBYVG0020BBK-WESN
  • Slim durable design to help take your important files with you
  • Vast capacities up to 6TB[1] to store your photos, videos, music, important documents and more
  • Back up smarter with included device management software[2] with defense against ransomware
  • Help secure your important files with password protection and hardware encryption
  • 3-year limited warranty

Choose the operation that matches your intent

Switch or combination What it does Can it delete destination-only items? Best use
/MIR Directory-tree mirror; equivalent to /E and /PURGE. Yes. Files and directories absent from the source are purged. A deliberate exact mirror where the destination may be made identical to the source.
/PURGE Deletes destination files and directories that are missing from the source. Yes. Only when removal of destination-only content is intentional.
/E Copies subdirectories, including empty directories, without adding purge behavior. Not by itself. Recursive copying or updating while retaining extra destination content.
/E /XX Recursively copies and excludes destination-only extra files and directories from deletion. No for those excluded extras. Updating a destination that must keep its own files; the result is not a strict mirror.
/L Lists the planned actions only. Microsoft says files are not copied, deleted, or timestamped in this mode. No. Previewing a command before a live run.
/XD Excludes named directories from the operation. Excluded directories are omitted from the operation; they are not evaluated for copying or purging. Leaving cache, temporary, or other selected directories out of scope.
/XF Excludes matching files from the operation. Excluded files are omitted from the operation. Skipping file types or named files that should not be synchronized.
/XJ Excludes junction points, which Robocopy normally includes by default. Junctions are left out of the operation. Avoiding traversal of selected NTFS junctions.

/XX changes the meaning of “mirror”: destination-only items remain, so the destination can contain more than the source. That is often the right trade-off for a backup or working folder, but it is not an exact replica.

Before you type a command: establish the two paths

  1. Write down the authoritative source. Decide which folder contains the files you want to preserve. In a normal backup workflow, this is the current working folder; the destination is the backup location.
  2. Write down the destination separately. Check the drive letter, share name, and every parent folder. A mistyped destination can point the command at a different disk or network share.
  3. Check that the source is the intended root. Mirroring C:UsersAlexDocuments is very different from mirroring C:UsersAlex. Do not remove a parent folder from the path merely to make the command shorter.
  4. Decide what destination-only content means. If the destination contains older versions, manually placed files, or folders from another job that must remain, an exact /MIR operation is the wrong choice. Use /E, optionally with /XX, and preview that plan instead.
  5. Confirm access. The account running the command needs to read the source and write the destination. Permissions, locked files, offline network shares, and filesystem rules can cause failures even when the paths are correct.

Do not paste a command from an example and run it unchanged. In particular, never assume that a drive letter shown in a guide refers to the same disk on your computer.

Preview a mirror without copying or deleting

Add /L to the command to obtain a list-only run. The following is a preview template for a mirror:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
robocopy "C:Source" "D:Backup" /MIR /L /LOG:"C:LogsRobocopy-preview.log"

With /L present, Robocopy reports what it would copy, what it considers extra at the destination, and what it would remove, but it does not copy files, delete files, or update timestamps. The log path is also an example; make sure the log directory already exists or choose a location that your account can create.

For a non-purging recursive copy, preview this instead:

robocopy "C:Source" "D:Backup" /E /L /LOG:"C:LogsRobocopy-preview.log"

Do not describe a preview as a backup. It is a plan, not a second copy of your data and not a rollback mechanism. If the source changes after the preview, the live run can produce a different plan, so perform the preview close to the time of the real operation.

Rank #2
Kosbees 500 GB External Hard Drives,Portable Hard Drive for Windows,Ultra Slim External HDD Store Compatible with PC, MAC,Laptop,PS4, Xbox one, Xbox 360;Plug and Play Ready
  • 【Plug-and-Play Expandability】 With no software to install, just plug it in and the drive is ready to use in Windows(For Mac,first format the drive and select the ExFat format.
  • 【Fast Data Transfers 】The external hard drives with the USB 3.0 cable to provide super fast transfer speed. The theoretical read speed is as high as 110MB/s-133MB/s, and the write speed is as high as 103MB/s.
  • 【High capacity in a small enclosure 】The small, lightweight design offers up to 500GB capacity, offering ample space for storing large files, multimedia content, and backups with ease. Weighing only 0.35 Lbs, it's easy to carry "
  • 【Wide Compatibility】Supports PS4 5/xbox one/Windows/Linux/Mac and other operating systems, ensuring seamless integration with game consoles,various laptops and desktops .
  • Important Notes for PS/Xbox Gaming Devices: You can play last-gen games (PS4 / Xbox One) directly from an external hard drive. However, to play current-gen games (PS5 / Xbox Series X|S), you must copy them to the console's internal SSD first. The external drive is great for keeping your library on hand, but it can't run the new games.

How to inspect the preview and log

Read the console output and the log from the top down. First confirm that the source and destination roots shown by Robocopy are exactly the two paths you intended. Then inspect each category of change:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • New files and directories: items present in the source that would be added to the destination.
  • Changed or mismatched items: files whose size, timestamp, attributes, or other comparison details indicate that the destination would be updated.
  • Extra files and directories: items found only in the destination. Under /MIR or /PURGE, these are candidates for deletion.
  • Excluded items: files or directories omitted because of /XD, /XF, or /XJ. Exclusion means Robocopy will not synchronize that content.

Open the log in a text editor and search for the names of any destination-only files you care about. If a single unexpected folder appears as extra, stop and correct the source, destination, or exclusion list before running without /L. A clean-looking summary is not enough; an incorrect root can make every listed action appear internally consistent while still targeting the wrong data.

If destination files must stay, avoid purge behavior

Use /E for a recursive update

/E copies the complete source tree, including empty subdirectories, but it does not itself purge destination-only content. This makes it the safer starting point when the goal is “copy and update” rather than “make identical.” Preview it first with /E /L, then remove only /L after reviewing the output.

Add /XX when extras must be explicitly protected

/XX excludes extra files and directories at the destination from deletion. A template that combines recursive copying, list-only preview, and logging is:

robocopy "C:Source" "D:Backup" /E /XX /L /LOG:"C:LogsRobocopy-preview.log"

Use /XX when keeping destination-only items is a requirement, and understand the consequence: the destination will not be a strict mirror. If a destination-only item should be removed, delete it through a separately reviewed process rather than adding /MIR casually to this command.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not combine conflicting expectations

There is no switch that makes /MIR an exact mirror while also guaranteeing that destination-only files survive. Purging and retaining extras are opposite policies. Choose one deliberately and record that choice in the job’s notes or script comments.

Rank #3
WD 4TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBPKJ0040BBK-WESN
  • Slim durable design to help take your important files with you
  • Vast capacities up to 6TB[1] to store your photos, videos, music, important documents and more
  • Back up smarter with included device management software[2] with defense against ransomware
  • Help secure your important files with password protection and hardware encryption
  • 3-year limited warranty

Limit the scope with exclusions

Exclusions are useful when a source tree contains content that should not be synchronized, but they can also create gaps that are mistaken for successful backup. Verify every pattern in a list-only run.

  • /XD for directories: specify directories such as a cache or temporary workspace that should be outside the operation. An excluded directory and everything under it is omitted.
  • /XF for files: specify file names or patterns that should be skipped. Confirm that the pattern does not also match documents you need.
  • /XJ for junctions: use this when you do not want Robocopy to follow junction points. Junctions can make a tree appear to contain locations outside the apparent source root, so decide whether following them is appropriate.

When using exclusions with /MIR, remember that excluded content is not evaluated as part of the mirror. Keep a written list of exclusions and review it whenever the folder layout changes.

Run the live operation only after the plan is approved

  1. Make a final path check. Compare the source and destination in the command with the roots you approved in the preview log.
  2. Remove /L and keep logging enabled. For an intentional mirror, the live template is:
robocopy "C:Source" "D:Backup" /MIR /LOG:"C:LogsRobocopy-run.log"
  1. Use /LOG+: when appending to an existing log. For example, /LOG+:"C:LogsRobocopy-history.log" preserves earlier entries instead of replacing the file.
  2. Wait for the command to finish. Do not close the console or disconnect a network destination while files are still being processed.
  3. Read the completed log. Look for failures, skipped items, unexpected extras, and the final summary. A command returning to the prompt does not by itself prove that every file was copied.
  4. Record the return code. Robocopy communicates the result through its process exit code; interpret it together with the log.

Microsoft recommends logging so that you can review the operation’s integrity after it runs. A log is evidence of what Robocopy attempted and reported; it does not preserve deleted destination files.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set bounded retries for real-world interruptions

Robocopy’s default retry count is 1,000,000 and its default wait interval is 30 seconds. Those defaults can make a job appear hung when a file is locked or a network share is unavailable. They affect how long Robocopy keeps trying, not whether destination-only files are deleted.

Set deliberate values with /R:n for the number of retries and /W:n for the wait in seconds. For example:

robocopy "C:Source" "D:Backup" /E /XX /R:3 /W:5 /LOG:"C:LogsRobocopy-run.log"

This example makes three retries with a five-second wait and retains destination extras through /E /XX. Select values appropriate to the reliability of the local disk or network share. A low retry count can leave transiently unavailable files uncopied; a high count can delay detection of a permanent permission or connectivity problem.

Rank #4
ModusTech Facet 500GB External Hard Drive Portable USB-C/USB 3.1 Plug & Play Ultra- Slim HDD Hard Drive for Backup, Gaming, PC, Mac, Laptop, PS4, Xbox, Smart TV (Black)
  • High-capacity external hard drive with up to 2TB of storage The ModusTech Facet portable external hard drive gives you dependable HDD storage in a slim 2.5-inch design. Multiple capacities available up to 2TB — back up photos, videos, music, documents, and game libraries with room to grow. A trusted external storage solution for everyday backup, media archives, and creative work.
  • USB-C and USB 3.1 connectivity with included 2-in-1 cable The Facet ships with a USB-C to USB-C cable and tethered USB-A adapter, so this external hard drive connects to modern laptops, USB-C iPhones, tablets, and older USB-A computers without buying an extra cable. USB 3.1 Gen 1 (5Gbps) interface delivers real-world transfer speeds up to 100MB/s — fast enough to back up 50GB of files in about 8 minutes.
  • Plug-and-play external hard drive for PC, Mac, and laptops Preformatted in exFAT and ready to use the moment you plug it in. The Facet works out of the box with Windows PCs, macOS Macs, MacBooks, Chromebooks, and laptops — no drivers, no software, no setup required. A true plug-and-play external hard drive built for everyday use across every major operating system.
  • External hard drive for PS4, Xbox One, and Smart TV gaming The Facet is compatible with PlayStation 4, Xbox One, and Smart TVs with USB support. PS4 and Xbox One games run directly from the drive — plug it in, format through the console, and add to your storage. Also works with Smart TVs that support USB recording or external media playback.
  • Slim, shock-resistant portable external hard drive — 160g At 2.5 inches and just 160g, this portable external hard drive is bus-powered through a single USB-C cable — no separate power adapter, no extra cables. Slim enough for a laptop bag, jacket pocket, or camera bag, with a shockresistant casing and faceted diamond-texture top panel that resists fingerprints and everyday wear. Backed by a 1-year limited warranty from ModusTech, a consumer electronics brand specializing in external storage.

Interpret Robocopy’s return codes

Robocopy’s exit code is not a simple “zero means success, nonzero means failure” convention. The documented meanings combine copied, extra, and mismatched states. Codes 8 and above indicate that at least one failure occurred.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Code Documented meaning What to do
0 No files were copied, and there was no failure or mismatch. Confirm that “nothing to copy” was expected.
1 All files copied successfully. Review the log for the expected file count and scope.
2 Extra files or directories exist at the destination. Decide whether extras are intentional. Do not assume they were deleted.
3 Files were copied and extra files or directories exist. Check whether the selected switches were meant to retain extras.
5 Files were copied and mismatches were detected. Inspect mismatched entries and the comparison criteria in the log.
6 Extras and mismatches exist, with no files copied or failure reported. Review the destination state and determine whether the differences are expected.
7 Files were copied, with mismatches and extras. Inspect all three categories before treating the run as complete.
8 or higher At least one failure occurred. Read the error lines, correct permissions, paths, locks, or connectivity, then rerun a preview.

The command’s purpose changes how you judge a lower code. For example, code 2 can be acceptable after an /E /XX update because retaining destination extras is intentional, while the same result may signal an incomplete exact mirror.

Security settings and root-level edge cases

Microsoft documents a security-setting difference between /E with /PURGE and /MIR when the destination directory already exists. With /E and a destination directory, destination directory security settings are not overwritten; /MIR, which combines /E and /PURGE, overwrites those settings. If permissions on the destination are important, review them separately and test the chosen command on a noncritical folder.

Microsoft also notes a volume-root edge case involving System Volume Information. Current behavior skips that named top-level item when /MIR or /PURGE is used at a volume root. This does not remove the need to verify paths: root-level mirroring still has a much wider scope than mirroring a dedicated data folder.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failure scenarios and safe fixes

The preview lists files you expected to keep as “extra”

Stop before the live run. Confirm that the source is the authoritative folder. If those files belong only at the destination, change the command to /E, optionally add /XX, and preview again. Do not try to protect them by running /MIR and hoping the deletion list is ignored.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The destination is empty or unexpectedly small

Check the source path, drive letter, and spelling in both the command and the log. A valid but wrong source can produce a valid-looking mirror that removes most of the destination. Correct the paths, run with /L, and inspect the new listing before copying.

Best Value
Sale
WD 5TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBPKJ0050BBK-WESN
  • Slim durable design to help take your important files with you
  • Back up smarter with included device management software[2] with defense against ransomware
  • Help secure your important files with password protection and hardware encryption
  • 3-year limited warranty

Files remain uncopied after the run

Look for access-denied, locked-file, offline-share, or path errors in the log. Check that the account can read each source item and write the destination. If the problem is transient, use bounded /R: and /W: values and rerun after correcting connectivity or locks. A return code of 8 or higher requires investigation rather than being treated as a successful backup.

An exclusion removed too much from the plan

Review every /XD, /XF, and /XJ pattern. Remove or narrow the matching exclusion, then run another list-only preview. Excluded data is not synchronized, so its absence from the output is not proof that it was safely copied elsewhere.

The log cannot be written

Choose a log directory that exists and is writable, or create it before running Robocopy. Keep the log outside a folder that the mirror could purge, such as a separate logging directory or drive. If the log location is inside the destination tree and you use /MIR, a destination-only log can itself become a purge candidate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a second copy if deletion would be costly

A mirror is synchronization, not versioned backup. If a file is accidentally deleted from the source and you run /MIR, the corresponding destination file is eligible for deletion during the next run. Keep an independent copy, snapshot, or versioned backup when recovery from accidental source deletion, corruption, or ransomware matters. A separate physical destination drive is one possible arrangement; it is not required for Robocopy and does not by itself make /MIR safe.

For network or cloud-backed destinations, verify that the provider preserves the permissions, timestamps, path lengths, and file semantics your workload needs. Microsoft’s Azure Files migration guidance shows Robocopy being used with that service, but the same preview-and-review discipline still applies: a network destination does not change what /MIR means.

Two complete decision examples

Exact mirror of a disposable staging destination

You want D:StagingMirror to contain exactly the current contents of C:Staging, and anything left only in the destination is disposable.

  1. Preview with robocopy "C:Staging" "D:StagingMirror" /MIR /L /LOG:"C:Logsstaging-preview.log".
  2. Verify both roots and review every destination-only item in the output.
  3. If the deletion list is correct, run robocopy "C:Staging" "D:StagingMirror" /MIR /LOG:"C:Logsstaging-run.log".
  4. Review the final log and return code, paying particular attention to code 8 or higher.

Update a backup folder that contains manually retained files

You want new and changed files from C:Projects copied to D:BackupProjects, but a manually saved archive in the destination must remain.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
WD 2TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBYVG0020BBK-WESN
WD 2TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBYVG0020BBK-WESN
Slim durable design to help take your important files with you; Help secure your important files with password protection and hardware encryption
$132.10
Bestseller No. 3
WD 4TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBPKJ0040BBK-WESN
WD 4TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBPKJ0040BBK-WESN
Slim durable design to help take your important files with you; Help secure your important files with password protection and hardware encryption
$180.00
SaleBestseller No. 5
WD 5TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBPKJ0050BBK-WESN
WD 5TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBPKJ0050BBK-WESN
Slim durable design to help take your important files with you; Help secure your important files with password protection and hardware encryption
$219.95
  1. Preview with robocopy "C:Projects" "D:BackupProjects" /E /XX /L /LOG:"C:Logsprojects-preview.log".
  2. Confirm that the archive appears as an excluded extra rather than a deletion candidate.
  3. Run the same command without /L, retaining /E /XX and the log.
  4. Review the return code and log. The destination will contain the copied project tree plus the retained archive, so it is intentionally not an exact mirror.

Final safety checklist

  • The source path is the authoritative folder, and the destination path is the intended target.
  • You understand whether destination-only files may be deleted.
  • You selected /MIR only for an intentional exact mirror; otherwise you selected /E, with /XX when extras must remain.
  • You previewed the exact paths and switches with /L.
  • You read the preview and log, including the list of extras and exclusions.
  • You removed /L only after approving the planned changes.
  • You kept /LOG: or /LOG+: for the live operation.
  • You chose deliberate /R: and /W: values when retries could otherwise take a long time.
  • You reviewed the completed log and interpreted the return code.
  • You maintain an independent recovery copy when deletion or corruption would be unacceptable.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

backup safetyCommand Linefile synchronizationROBOCOPYWindows

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.