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
| Flag | What It Does |
|---|---|
/MIR | Mirror mode — copies new files AND deletes files from dest that aren’t on source |
/MT:16 | Multi-threaded — 16 concurrent copy threads (default is 8) |
/LOG:file | Write 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
| Flag | Purpose |
|---|---|
/E | Copy subdirectories, including empty ones |
/S | Copy subdirectories, excluding empty ones |
/Z | Restartable mode — resumes interrupted copies |
/B | Backup mode — uses backup semantics (requires backup privileges) |
/ZB | Restartable first, falls back to backup mode |
/COPY:DATSOU | What to copy: Data, Attributes, Timestamps, Security, Owner, aUditing |
/SEC | Copy NTFS security info (equivalent to /COPY:DATS) |
/COPYALL | Copy all file info (/COPY:DATSOU) |
/DCOPY:DAT | Copy directory timestamps and attributes |
Performance Flags
| Flag | Purpose |
|---|---|
/MT:n | Multi-threaded (1-128 threads). 8-32 is the sweet spot |
/J | Copy using unbuffered I/O — better for very large files |
/IPG:n | Inter-packet gap in milliseconds — throttles bandwidth |
/R:3 | Retry count on failed copies (default is 1,000,000!) |
/W:5 | Wait 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
| Flag | Purpose |
|---|---|
/XF file | Exclude specific files (supports wildcards) |
/XD dir | Exclude specific directories |
/MAXAGE:n | Exclude files older than n days (or YYYYMMDD date) |
/MINAGE:n | Exclude files newer than n days |
/MAX:n | Exclude files larger than n bytes |
/MIN:n | Exclude 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 Code | Meaning | Action |
|---|---|---|
| 0 | No files copied, no errors | Success (no changes) |
| 1 | Files copied successfully | Success |
| 2 | Extra files/dirs detected | Success (with extras) |
| 3 | Files copied + extras detected | Success |
| 4 | Mismatched files or dirs | Warning — investigate |
| 8 | Some files failed to copy | Error |
| 16 | Fatal error — no files copied | Critical 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:
- Authentication — ensure the service account has read on source and full control on destination
- Long paths — use
\\?\UNC\server\share\pathprefix for paths exceeding 260 characters - Open files — Robocopy can’t copy files locked by other processes. Use VSS snapshots or schedule during off-hours
- DFS namespaces — specify the actual server path, not the DFS namespace, for consistent performance
- SMB signing — if enabled, expect 20-30% throughput reduction. Consider disabling during migration windows
Common Errors and Solutions
| Error | Cause | Fix |
|---|---|---|
| ”Access Denied” | Insufficient permissions | Run as Domain Admin or use /B for backup mode |
| ”The file name is too long” | Path > 260 chars | Use \\?\ prefix or set LongPathsEnabled registry key |
| ”Sharing violation” | File locked by another process | Schedule off-hours or use VSS |
| ”Insufficient resources” | Too many threads with /MT | Reduce thread count (try /MT:8) |
| Stalled on one file | Network timeout on large file | Add /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 —
/Zrestarts 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
- rsync vs rclone vs Robocopy: Which Tool in 2026? — head-to-head comparison
- syncopio vs Robocopy — detailed feature comparison
- NFS vs SMB: Performance, Security & When to Use Each — protocol deep-dive
- Data Migration: The Complete Guide