Migrating a file server is one of those tasks that seems straightforward until you realize you need to preserve permissions, attributes, timestamps, and handle large file sets without breaking anything. That's why robocopy is my go-to tool for file server migrations on Windows.
Robocopy (Robust File Copy) is built into Windows and handles file server migrations better than any other tool I've used. It preserves NTFS permissions, handles long paths, retries failures automatically, and gives you detailed logging. Here's the exact command I use and why each switch matters.
TL;DR
- Use robocopy:
robocopy source destination /E /Z /ZB /R:1 /W:1 /TBD /NP /V /A-:SH /XD /COPYALL - Preserves everything: Permissions, attributes, timestamps, and file ownership
- Key switches: /E (subdirectories), /COPYALL (all file info), /Z (resumable), /ZB (use backup mode)
- Run multiple times: First run copies everything, subsequent runs catch changes
- Test first: Always test on a small directory before full migration
- Switch users: After successful copy, update user shares and permissions as needed
The Robocopy Command
Here's the robocopy command I use for file server migrations:
robocopy source destination /E /Z /ZB /R:1 /W:1 /TBD /NP /V /A-:SH /XD /COPYALL
Let me break down what each switch does and why it's included in this command.
Understanding Each Switch
/E - Copy Subdirectories, Including Empty Ones
The /E switch copies all subdirectories, including empty ones. This ensures your entire directory structure is replicated, even folders that don't currently contain files. This is essential for maintaining the exact structure of your file server.
/Z - Copy Files in Restartable Mode
Restartable mode allows robocopy to resume an interrupted copy operation. If the migration gets interrupted (network issue, server restart, etc.), robocopy can pick up where it left off instead of starting over. This is crucial for large migrations that might take hours or days.
/ZB - Use Restartable Mode; If Access Denied, Use Backup Mode
The /ZB switch combines restartable mode with backup mode for access-denied files. If robocopy encounters a file it can't access normally (due to permissions), it will use backup mode, which requires backup operator privileges but can copy files that would otherwise be skipped. This ensures nothing gets left behind due to permission issues.
/R:1 - Retry Once on Failures
This sets the number of retries to 1 for failed copies. With /R:1, if a file fails to copy, robocopy will try once more before giving up. This handles transient network issues without wasting time on files that genuinely can't be copied.
/W:1 - Wait 1 Second Between Retries
This waits 1 second between retry attempts. Combined with /R:1, this gives the system a brief moment to recover from temporary issues without creating excessive delay. One second is usually enough for transient network hiccups.
/TBD - Wait for Share Names To Be Defined
The /TBD switch tells robocopy to wait for share names to be defined if they're not immediately available. This is useful when migrating between servers where network shares might not be immediately accessible or need to be established during the migration process.
/NP - No Progress
This suppresses the progress percentage display. For large migrations, the progress percentage can slow down the operation and create excessive log output. The /NP switch keeps the output cleaner and faster.
/V - Verbose Output
Verbose mode provides detailed output about what's being copied, including skipped files, errors, and extra file information. This is essential for troubleshooting and verifying that the migration completed successfully.
/A-:SH - Remove Archive, System, and Hidden Attributes
This removes the Archive (A), System (S), and Hidden (H) attributes from files after copying. This is useful because you often don't want to copy these attributes from the source server. Hidden files will be visible, archive bits will be cleared, and system attributes won't interfere with the destination files.
/XD - Exclude Directories
The /XD switch excludes specified directories from the copy operation. In the command shown, /XD appears without a directory name, which means no directories are excluded. However, you can use this switch to exclude specific folders like:
/XD "Recycle Bin" "System Volume Information" "$RECYCLE.BIN"
This is useful for excluding system directories or folders you don't want to migrate.
/COPYALL - Copy All File Information
The /COPYALL switch is equivalent to /COPY:DATSOU and copies all file information:
- Data - File data
- Attributes - File attributes
- Timestamps - File timestamps
- Security - NTFS security information (ACLs)
- Owner - File ownership information
- Unauditing - File auditing information
This is the most important switch for file server migrations because it preserves all NTFS permissions, ownership, and timestamps. Without /COPYALL, you'll lose permissions and have to restore them manually.
How to Use This Command
Step 1: Open Command Prompt as Administrator
Robocopy works best when run with administrator privileges, especially with the /ZB switch which may need backup operator rights. Right-click Command Prompt and select "Run as administrator."
Step 2: Replace Source and Destination Paths
Replace "source" and "destination" with your actual paths. You can use UNC paths, mapped drives, or local paths:
robocopy "\\SourceServer\ShareName" "\\DestinationServer\ShareName" /E /Z /ZB /R:1 /W:1 /TBD /NP /V /A-:SH /XD /COPYALL
Or with local paths:
robocopy "C:\SourceFolder" "D:\DestinationFolder" /E /Z /ZB /R:1 /W:1 /TBD /NP /V /A-:SH /XD /COPYALL
Step 3: Add Logging (Recommended)
For production migrations, add logging to capture the output:
robocopy "\\SourceServer\ShareName" "\\DestinationServer\ShareName" /E /Z /ZB /R:1 /W:1 /TBD /NP /V /A-:SH /XD /COPYALL /LOG:"C:\MigrationLog.txt"
The /LOG switch saves all output to a file. You can also use /LOG+ to append to an existing log file if you're running multiple passes.
Step 4: Run a Test Copy First
Before running the full migration, test with the /L switch (list only mode) to see what would be copied without actually copying:
robocopy "\\SourceServer\ShareName" "\\DestinationServer\ShareName" /E /Z /ZB /R:1 /W:1 /TBD /NP /V /A-:SH /XD /COPYALL /L
This gives you a preview of the operation and helps identify any issues before starting the actual migration.
Multi-Pass Migration Strategy
For production file servers that users are actively accessing, I recommend a multi-pass approach:
Pass 1: Initial Copy
Run the full robocopy command to copy all files. This establishes the baseline on the destination server.
Pass 2: Differential Copy
After the initial copy, run the same command again. Robocopy will only copy files that have changed since the first pass, making subsequent passes much faster.
Pass 3: Final Sync (During Maintenance Window)
During your maintenance window, run one final pass to capture any changes made during Pass 2. Then update DNS, shares, or DFS paths to point to the new server.
Understanding Robocopy Exit Codes
Robocopy returns exit codes that tell you the result of the operation:
- 0-7: Success (files were copied)
- 8: Some files or directories could not be copied
- 16: Serious error occurred
Exit codes 0-7 are normal - they indicate how many files were copied. Exit code 8 means some files failed, and you should review the log. Exit code 16 indicates a serious problem that needs investigation.
Common Issues and Solutions
Long Path Names
If you encounter "Path too long" errors, enable long path support in Windows:
reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1 /f
You'll need to restart the server for this to take effect.
Access Denied Errors
The /ZB switch should handle most access denied issues by using backup mode. If you still encounter problems, ensure the account running robocopy has backup operator privileges on both source and destination servers.
Network Interruptions
The /Z switch ensures robocopy can resume after network interruptions. If the copy is interrupted, simply run the same command again and robocopy will resume where it left off, only copying files that haven't been transferred yet.
Verification After Migration
After completing the migration, verify the results:
- Check file counts match between source and destination
- Verify folder sizes match
- Spot-check file permissions on a sample of files and folders
- Verify timestamps are preserved
- Test file access with a test user account
You can use robocopy with the /L switch to generate a comparison report, or use PowerShell scripts to compare file counts and sizes.
Final Thoughts
This robocopy command is the foundation I use for every file server migration. The combination of switches ensures all files, permissions, and attributes are preserved while handling errors gracefully and providing detailed logging for verification.
Remember to test with the /L switch first, use logging for production migrations, and run multiple passes for servers that can't have downtime. With proper planning and this command, file server migrations become predictable and reliable.