Tutorial 10 min read by syncopio Team

Robocopy for IT Admins: Scheduled Backups, Mirroring & Beyond

Master Robocopy's key flags, Task Scheduler integration, SMB considerations, and common pitfalls for Windows file server migrations.

Robocopy (Robust File Copy) ships with every Windows installation and is the go-to tool for Windows file server migrations. This guide covers the flags you’ll actually use, Task Scheduler automation, and the pitfalls that cost admins hours.

Essential Robocopy Flags

The Big Three

robocopy \\source\share \\dest\share /MIR /MT:16 /LOG:C:\logs\migration.log
FlagWhat It Does
/MIRMirror mode — copies new files AND deletes files from dest that aren’t on source
/MT:16Multi-threaded — 16 concurrent copy threads (default is 8)
/LOG:fileWrite output to a log file instead of console

/MIR deletes files

/MIR = /E + /PURGE. It will delete files on the destination that don’t exist on the source. Always run a test with /L (list-only) first.

Copy Options

FlagPurpose
/ECopy subdirectories, including empty ones
/SCopy subdirectories, excluding empty ones
/ZRestartable mode — resumes interrupted copies
/BBackup mode — uses backup semantics (requires backup privileges)
/ZBRestartable first, falls back to backup mode
/COPY:DATSOUWhat to copy: Data, Attributes, Timestamps, Security, Owner, aUditing
/SECCopy NTFS security info (equivalent to /COPY:DATS)
/COPYALLCopy all file info (/COPY:DATSOU)
/DCOPY:DATCopy directory timestamps and attributes

Performance Flags

FlagPurpose
/MT:nMulti-threaded (1-128 threads). 8-32 is the sweet spot
/JCopy using unbuffered I/O — better for very large files
/IPG:nInter-packet gap in milliseconds — throttles bandwidth
/R:3Retry count on failed copies (default is 1,000,000!)
/W:5Wait time between retries in seconds (default is 30)

Always set /R and /W

Robocopy’s default is 1 million retries with 30-second waits. That’s ~347 days of retrying a single file. Set /R:3 /W:5 to fail fast and move on.

Filtering

FlagPurpose
/XF fileExclude specific files (supports wildcards)
/XD dirExclude specific directories
/MAXAGE:nExclude files older than n days (or YYYYMMDD date)
/MINAGE:nExclude files newer than n days
/MAX:nExclude files larger than n bytes
/MIN:nExclude files smaller than n bytes

Common Workflows

1. Full Server Mirror

robocopy \\oldserver\data \\newserver\data /MIR /MT:16 /COPY:DATSOU /DCOPY:DAT /R:3 /W:5 /LOG:C:\logs\full-mirror.log /TEE /NP
  • /COPY:DATSOU — preserves all metadata including security and ownership
  • /DCOPY:DAT — preserves directory timestamps
  • /TEE — output to console AND log file simultaneously
  • /NP — no percentage progress (cleaner logs)

2. Incremental Sync (Pre-Cutover)

robocopy \\oldserver\data \\newserver\data /MIR /MT:16 /COPY:DATSOU /DCOPY:DAT /R:3 /W:5 /LOG+:C:\logs\incremental.log /TEE /NP

Note the /LOG+: (with plus sign) — appends to the existing log instead of overwriting.

3. List-Only Dry Run

robocopy \\source\share \\dest\share /MIR /L /LOG:C:\logs\dryrun.log

The /L flag shows what would happen without copying anything. Always use this before a production mirror.

4. Copy Only New and Changed Files

robocopy \\source\share \\dest\share /E /XO /MT:16 /R:3 /W:5 /LOG:C:\logs\newonly.log

/XO excludes older files — only copies files newer on the source. No deleting.

Task Scheduler Integration

For automated daily syncs:

Step 1: Create a batch script

@echo off
set LOGDIR=C:\logs\robocopy
set LOGFILE=%LOGDIR%\sync-%date:~10,4%%date:~4,2%%date:~7,2%.log

if not exist %LOGDIR% mkdir %LOGDIR%

robocopy \\source\share \\dest\share /MIR /MT:16 /COPY:DATSOU /R:3 /W:5 /LOG:%LOGFILE% /NP

REM Robocopy exit codes: 0-3 = success, 4+ = errors
if %ERRORLEVEL% GEQ 4 (
    echo FAILED: Robocopy returned %ERRORLEVEL% >> %LOGFILE%
    exit /b 1
)
exit /b 0

Step 2: Create a scheduled task

$action = New-ScheduledTaskAction -Execute "C:\scripts\robocopy-sync.bat"
$trigger = New-ScheduledTaskTrigger -Daily -At "2:00 AM"
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest

Register-ScheduledTask -TaskName "Daily File Server Sync" `
  -Action $action -Trigger $trigger -Principal $principal `
  -Description "Mirror source to destination using Robocopy"

Understanding Exit Codes

Robocopy uses non-standard exit codes that confuse Task Scheduler:

Exit CodeMeaningAction
0No files copied, no errorsSuccess (no changes)
1Files copied successfullySuccess
2Extra files/dirs detectedSuccess (with extras)
3Files copied + extras detectedSuccess
4Mismatched files or dirsWarning — investigate
8Some files failed to copyError
16Fatal error — no files copiedCritical error

Exit codes are bitwise

Robocopy exit codes are bitmasks. Code 5 = 1 (files copied) + 4 (mismatches). Any code less than 4 is generally success. Code 4+ means something needs attention.

SMB Considerations

When copying between SMB shares:

  1. Authentication — ensure the service account has read on source and full control on destination
  2. Long paths — use \\?\UNC\server\share\path prefix for paths exceeding 260 characters
  3. Open files — Robocopy can’t copy files locked by other processes. Use VSS snapshots or schedule during off-hours
  4. DFS namespaces — specify the actual server path, not the DFS namespace, for consistent performance
  5. SMB signing — if enabled, expect 20-30% throughput reduction. Consider disabling during migration windows

Common Errors and Solutions

ErrorCauseFix
”Access Denied”Insufficient permissionsRun as Domain Admin or use /B for backup mode
”The file name is too long”Path > 260 charsUse \\?\ prefix or set LongPathsEnabled registry key
”Sharing violation”File locked by another processSchedule off-hours or use VSS
”Insufficient resources”Too many threads with /MTReduce thread count (try /MT:8)
Stalled on one fileNetwork timeout on large fileAdd /Z for restartable mode

Limitations

For all its strengths, Robocopy has real limitations:

  • Windows only — no Linux or macOS support
  • No NFS — can’t access NFS exports without third-party NFS client
  • No checksumming — no built-in verification that files copied correctly
  • No centralized monitoring — each Robocopy job is independent; no dashboard view
  • Log parsing is painful — extracting meaningful metrics requires PowerShell scripting
  • No pause/resume across sessions — /Z restarts individual files, not the job

Need cross-platform or better visibility?

syncopio provides a web dashboard for monitoring all migrations in one place, with built-in checksum verification and multi-protocol support (NFS + SMB + S3). See syncopio vs Robocopy for a detailed comparison.

Further Reading

Ready to simplify your migrations?

See how syncopio can save you hours on every migration project.

Request a Demo