Robocopy (Robust File Copy) is the robust Windows copy tool for synchronizing, backing up, and migrating data with advanced error handling.
Basic Syntax
robocopy <source> <destination> [options]🧩 Essential Options
| 🧩 Option | 🧠 Description |
|---|---|
/E | Copy everything, including empty subdirectories |
/S | Copy everything, except empty directories |
/MIR | Mirror: source = destination (warning: can delete in dest folder) |
/Z | Restartable mode (in case of network interruption) |
/COPY:DAT | Copy data, attributes, timestamps |
/DCOPY:T | Copy folder timestamps |
/R:5 | Retry 5 times on failure (default = 1 million) |
/W:5 | Wait 5 seconds between each retry |
/MT[:n] | Enable multi-threading (e.g. /MT:16) |
/LOG:log.txt | Save output to a log file |
/TEE | Display in console and log (useful with /LOG) |
/NP | Don’t display progress (%) |
/XO | Exclude files newer in destination |
/XX | Exclude directories that don’t exist in source |
🎯 Filtering Options
| 🧩 Option | 🧠 Description |
|---|---|
/XD "folder" | Exclude specific folders |
/XF "*.tmp" | Exclude file types |
/MAXAGE:n | Files modified within last n days maximum |
/MAX:n | Limit file size (in bytes) |
/A | Copy only files with Archive attribute |
/M | Copy and remove Archive attribute (incremental backup) |
🔐 Security Options
| 🧩 Option | 🧠 Description |
|---|---|
/SEC | Copy security permissions (NTFS) |
/COPYALL | Copy everything: data, attributes, timestamps, NTFS ACL, owner info |
/B | Backup mode (uses backup privileges) |
/SECFIX | Fix security on all files, even skipped ones |
/TIMFIX | Fix timestamps on all files, even skipped ones |
🔥 Practical Examples
🗃️ Simple backup of all files & folders (including empty)
robocopy "C:\MyDocs" "E:\Backup" /E /Z /R:3 /W:5 /LOG:C:\Logs\backup.log🪞 Exact synchronization
robocopy "D:\Source" "F:\Mirror" /MIR /Z /R:2 /W:3Multi-thread (faster)
robocopy "C:\Source" "D:\Target" /E /MT:16 /R:2 /W:2📜 Backup with log and silent progress
robocopy "C:\Project" "Z:\Backup" /E /LOG:"C:\Logs\Project.log" /NP /TEE🚫 Copy without overwriting newer files already in place
robocopy "X:\Import" "Y:\Data" /E /XO💾 Incremental backup with Archive attribute
robocopy "C:\Work" "E:\Backup" /E /M /R:2 /W:3 /LOG+:"C:\Logs\incremental.log"📋 Exit Codes
Robocopy returns a code to indicate how the copy went:
Common codes:
0= No files copied (already up to date)1= Files copied successfully2= Extra files in destination4= Mismatched files detected8= Failed or skipped files16= Serious errors (disk space, permissions…)
Example verification in a script:
robocopy "C:\Source" "D:\Dest" /E
if %ERRORLEVEL% LEQ 7 (
echo Copy successful (code: %ERRORLEVEL%)
) else (
echo Problem detected (code: %ERRORLEVEL%)
)Note: Codes 0-7 are considered successful, 8+ indicate problems