skip to content

Search

Syspirit
EN

Robocopy

Essential Robocopy commands for Windows backups and synchronization!

Windows
Published on

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
/ECopy everything, including empty subdirectories
/SCopy everything, except empty directories
/MIRMirror: source = destination (warning: can delete in dest folder)
/ZRestartable mode (in case of network interruption)
/COPY:DATCopy data, attributes, timestamps
/DCOPY:TCopy folder timestamps
/R:5Retry 5 times on failure (default = 1 million)
/W:5Wait 5 seconds between each retry
/MT[:n]Enable multi-threading (e.g. /MT:16)
/LOG:log.txtSave output to a log file
/TEEDisplay in console and log (useful with /LOG)
/NPDon’t display progress (%)
/XOExclude files newer in destination
/XXExclude directories that don’t exist in source

🎯 Filtering Options

🧩 Option🧠 Description
/XD "folder"Exclude specific folders
/XF "*.tmp"Exclude file types
/MAXAGE:nFiles modified within last n days maximum
/MAX:nLimit file size (in bytes)
/ACopy only files with Archive attribute
/MCopy and remove Archive attribute (incremental backup)

🔐 Security Options

🧩 Option🧠 Description
/SECCopy security permissions (NTFS)
/COPYALLCopy everything: data, attributes, timestamps, NTFS ACL, owner info
/BBackup mode (uses backup privileges)
/SECFIXFix security on all files, even skipped ones
/TIMFIXFix 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:3

Multi-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 successfully
  • 2 = Extra files in destination
  • 4 = Mismatched files detected
  • 8 = Failed or skipped files
  • 16 = 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