Asia/Calcutta
Posts

Robocopy Cheat Sheet (Windows)

June 21, 2026
Robocopy (Robust File Copy) is a built-in Windows command-line tool for mirroring, copying, and migrating files. Unlike copy/xcopy, it's resilient (auto-retries), multithreaded, and preserves metadata.
robocopy <Source> <Destination> [files] [options]

robocopy C:\Source D:\Backup *.* /E
PartMeaning
SourceFolder to copy from (no trailing \)
DestinationFolder to copy to
*.*File filter (optional, default = all)
/EInclude subdirs, including empty ones

FlagDescription
/SCopy subdirectories, but not empty ones
/ECopy subdirectories, including empty ones
/LEV:nOnly copy top n levels of the tree
/MIRMirror/E + /PURGE (dest becomes identical to source)
/PURGEDelete dest files/dirs that no longer exist in source
/MOVMove files (delete from source after copy)
/MOVEMove files and dirs (delete from source)
/CREATECreate dir tree + zero-length files only (structure scaffold)
⚠️ /MIR deletes. Anything in the destination not in the source gets removed. Always dry-run first.

FlagCopies
/COPY:DATData, Attributes, Timestamps (default)
/COPY:DATSOUAdds Security (ACLs), Owner, aUditing
/COPYALLEverything = /COPY:DATSOU
/DCOPY:DATCopy directory timestamps too
/SECCopy with security (= /COPY:DATS)
/NOCOPYCopy nothing (used with /PURGE to only clean dest)
Flag letters: D=Data, A=Attributes, T=Timestamps, S=NTFS ACLs, O=Owner info, U=Auditing info.
FlagEffect
/MT[:n]Multithreaded copy, n = 1–128 threads (default 8). Huge speedup on many small files
/JUnbuffered I/O — best for large files (VMs, ISOs, DBs)
/NOOFFLOADDisable Windows copy offload (for some SAN/NAS edge cases)
/COMPRESSSMB compression during transfer (Win11/Server 2022+)
/IPG:nInter-packet gap (ms) — throttle bandwidth on slow links
robocopy \\src\share D:\local /E /MT:32 /J
Tip: /MT and logging — multithreaded output interleaves, so always pair with /LOG for clean records.

FlagMeaning
/XF file [file]...eXclude Files (supports wildcards: *.tmp)
/XD dir [dir]...eXclude Directories (e.g. node_modules)
/XOExclude older — skip src files older than dest
/XNExclude newer
/XCExclude changed
/XXExclude extra (dest-only) files — protects them from /MIR
/XLExclude lonely (src-only) files
/ISInclude same — recopy identical files
/ITInclude tweaked files
/MAX:n / /MIN:nMax/min file size in bytes
/MAXAGE:n / /MINAGE:nMax/min file age (n days, or YYYYMMDD)
/MAXLAD / /MINLADFilter by last access date
/ACopy only files with Archive attribute set
/MSame as /A but clears the Archive bit (incremental backups)
/IA:RASHCNETO / /XA:...Include/exclude by attribute

FlagDescription
/R:nRetry count on failed copies (default 1 million — set low!)
/W:nWait seconds between retries (default 30)
/ZRestartable mode (resume interrupted large copies)
/BBackup mode — uses backup privileges to bypass ACLs
/ZBTry restartable; fall back to backup mode (best for migrations)
/TBDWait for share names to be defined
/EFSRAWCopy encrypted (EFS) files in raw mode
🔑 Always set /R:3 /W:5. Defaults (/R:1000000 /W:30) can hang for weeks on a single locked file.

FlagDescription
/LList only — dry run, copies nothing (test /MIR here!)
/LOG:fileWrite log (overwrite)
/LOG+:fileWrite log (append)
/UNILOG:fileUnicode log
/TEEOutput to console and log
/NPNo progress % (cleaner logs)
/NDLNo directory list
/NFLNo file list
/NSNo size info
/NCNo file class
/VVerbose (shows skipped files)
/ETAShow estimated completion time
/BYTESSizes in bytes
/XReport all extra files (not just selected)
Clean-log combo: /NP /NDL /NFL /NC /NS then check the summary table only.
Dry-run a mirror (do this first, always):
robocopy C:\Data D:\Backup /MIR /L /NP
True mirror with safe retries + log:
robocopy C:\Data D:\Backup /MIR /R:3 /W:5 /MT:16 /LOG:C:\logs\backup.log /TEE /NP
Server migration preserving all permissions:
robocopy \\OLD\Share \\NEW\Share /E /ZB /COPYALL /DCOPY:DAT /R:2 /W:5 /MT:32 /LOG:migrate.log
Incremental backup (only changed files, clears archive bit):
robocopy C:\Source D:\Dest /M /E /R:2 /W:5
Move files older than 30 days to archive:
robocopy C:\Active D:\Archive /MOV /MINAGE:30 /E /R:1 /W:1
Copy only large files (>100 MB), unbuffered:
robocopy C:\VMs D:\VMs *.vhdx /J /MIN:104857600 /R:2 /W:5
Sync but protect destination-only files from deletion:
robocopy C:\Src D:\Dst /E /XX /R:2 /W:5

Robocopy returns a bitmask, not the usual 0=success. Anything < 8 is success.
CodeMeaning
0No change — source & dest identical
1Files copied successfully
2Extra files/dirs in dest (not in source)
31+2 — copied + extras present
4Mismatched files/dirs
8Some files failed to copy (real error)
16Fatal error — no copy occurred
Treat as failure only if code ≥ 8. In batch/PowerShell:
robocopy C:\Src D:\Dst /MIR /R:3 /W:5
if ($LASTEXITCODE -ge 8) { Write-Error "Robocopy failed: $LASTEXITCODE" }
else { Write-Host "OK ($LASTEXITCODE)" }
:: Batch equivalent
robocopy C:\Src D:\Dst /MIR
if %ERRORLEVEL% GEQ 8 echo FAILED & exit /b 1
exit /b 0
⚠️ In CI/scheduled tasks, a naive if %ERRORLEVEL% NEQ 0 flags normal successful copies as failures. Always compare with GEQ 8.

  • Job files: Save complex command sets and reuse them.
    robocopy /SAVE:mybackup    :: writes mybackup.RCJ
    robocopy /JOB:mybackup     :: run it
    robocopy /JOB:mybackup /QUIT  :: parse & quit (validate without running)
    
  • Long paths (>260 chars): Robocopy supports them natively — one of its biggest advantages over Explorer/copy.
  • /MIR vs /E /PURGE: identical. The danger is the PURGE half — if you point Source at the wrong/empty folder, you wipe the destination. Dry-run with /L guards against this.
  • /MT + /Z conflict: Restartable mode (/Z) is significantly slower and partially negated by multithreading — pick /MT for many small files, /Z (or /J) for big files over flaky links.
  • Timestamps drift: Without /DCOPY:T (or /DCOPY:DAT), folder timestamps reset to "now." Add it for true fidelity.
  • Mirroring junctions/symlinks: Robocopy follows them by default and can cause infinite loops. Use /XJ to exclude junction points; /SL to copy symlinks as links rather than targets.
  • Permissions need elevation: /COPYALL, /B, /ZB, and /SEC typically require an admin prompt; otherwise ACL/owner copy silently degrades.
  • Bandwidth throttling: No native rate limit, but /IPG:n (inter-packet gap in ms) approximates one for WAN copies.
  • Empty-dir behavior: /S skips empty folders; /E keeps them. Mirroring a structure-only tree needs /E (or /CREATE).

robocopy "SOURCE" "DEST" /E /R:3 /W:5 /MT:16 /COPY:DAT /DCOPY:DAT /XJ ^
  /LOG:"C:\logs\robocopy_%date:~-4%%date:~3,2%%date:~0,2%.log" /TEE /NP
Drop /E/MIR only after you've verified with /L.
Reference cheat sheet — Windows built-in robocopy. Run robocopy /? for the full inline help.