Robocopy is a feature-rich and powerful file migration tool in Windows. The built-in help system (robocopy /?) provides the basic usage of each option, but it doesn’t thoroughly explain why and how to use these options.
Recently I discovered a best Robocopy guide (robocopy.doc) in Windows Server 2003 Resource Kit Tools. To access this document without installing, use 7-Zip to extract the rktools.exe file, then extract the rktools.msi file. Even this document is for Version XP010, it is still applicable to the version built-in Windows 10.
I summarize some key information from this Robocopy document along with my usage experience below. It is highly recommended to read the full document if you have time.
What does Newer, Orlder or Extra mean?
File Class | In Source | In Destination | Source/Dest File Time | Source/Dest File Size | Source/Dest Attribute |
Lonely | Yes | No | n/a | n/a | n/a |
Tweaked | Yes | Yes | Equal | Equal | Different |
Same | Yes | Yes | Equal | Equal | Equal |
Changed | Yes | Yes | Equal | Different | n/a |
Newer | Yes | Yes | Source > Dest | n/a | n/a |
Older | Yes | Yes | Source < Dest | n/a | n/a |
Extra | No | Yes | n/a | n/a | n/a |
Mismatched | Yes (file) | Yes (Directory) | n/a | n/a | n/a |
- By default, Changed, Newer, and Older files are candidates for copying (subject to further filtering, as described later)
- Same files are not copied
- Extra and Mismatched files and directories are only reported in the output log
- Tweaked files are neither identified nor copied - they are usually identified as Same files by default. Only when /IT is used, then Tweaked files will be copied
Use /L option to test Robocopy command
After building a Robocopy command with the options I want, I append /L option at the end of the command.
/L option lists files without copying, deleting, or applying a time stamp to any files.
Running the Robocopy command with the /L option, I can analyze the output to confirm the outcome before the real execution.
Should I use /Z, /B, or /ZB option?
- /B – copy all files in Backup Mode. Enable you to copy some files as a Backup Operator that you would not be able to copy as a normal user. Backup mode copies are not restartable.
- /ZB – try to copy files in Restartable Mode (for greater resiliency), and automatically switch to Backup Mode if the Restartable copy fails with an “Access Denied” error.
- /Z, /B, or /ZB restart from close to the point of failure rather than the beginning of the files. This can decrease Robocopy performance and throughput significantly, as these options involve extra overhead. These options are only recommended when experience indicates you really need them.
My comment: not to use them unless you are not able to copy a file or the network connectivity is unstable.
Robocopy reports the file timestamp is different, even they look the same in Windows Explorer.
This usually happens when copying files between a Windows NTFS volume and a third-party storage system.
FAT file system stores its timestamp for files (modified date, etc) with 2-second granularity
NTFS file system stores its timestamp for files in a 100-nanosecond granularity
File-time granularity is 100 nanoseconds on NTFS, and two seconds on FAT. So copying a file from NTFS to FAT causes file times to be rounded to a value that file FAT file system can manage. When both the source and destination volumes are NTFS, file times are compared exactly. When either the source or destination volume is not an NTFS volume, Robocopy considers file times to be identical if they are within two seconds of each other.
Some third-party operating systems declare that their volumes are NTFS, but only implement FAT-style file times with a 2-second granularity. When copying to such a destination from a true NTFS volume, file time rounding may occur, along with unnecessary copying of file data in subsequence jobs. In this situation, use /FFT (FAT File Time) to tell Robocopy to consider file times to be identical if they are within 2 seconds of each other, even though both source and destination appear to be NTFS. This eliminates unnecessary copying in this scenario.
/FFT is useful for copying to third-party storage systems (when copying from Windows-to-Windows NTFS storage, this option is not needed) that declare a volume to be NTFS but only implement file time with a 2-second granularity.
/FFT forces Robocopy to use FAT file-time granularity so that the utility uses a 2-second standard for comparing files. As long as files are time-stamped within a 2-second interval, Robocopy considers them identical and doesn’t copy them. (Source: WindowsITPro Robocopy FAQ)
Two-way file change synchronization
/XO excludes “Older” files.
To synchronize two directory trees so that they can be updated simultaneously in separate areas (ensure that the latest files are present in both directory trees). First copy with /XO in one direction, and then in the other.
Exclude File or Directory by name
- /XF file [file] excludes Files matching given names/paths/wildcards
- /XD dirs [dirs] excludes Directories matching given names/paths
- My comment: to exclude multiple directories, simply list them with spaces in between. If the path contains spaces, wrap it in double-quotes (“ ”). The most important thing is DO NOT EVER include a trailing “\” in the excluded paths.
- /XF and /XD exclude files and directories before all other processing
Refresh security information without copying file data
- /IS /COPY:SOU refreshes all security information for all selected files, without copying any file data
Directory fragementation for large directories
/CREATE – Robocopy creates only the directory tree and zero-length files as placeholders for the actual files. No file data is copied.
By default (without /CREATE), for the first time copy, the directory entry for each file is created first, and then the file data is copied. If the directory tree contains large directories, however, this sequence can cause fragmentation of the directory structure.
Minimize directory fragmentation for large directories
Run Robocopy with /CREATE (along with whatever the options supposed to be) first, then run the same command again without /CREATE to copy the file data to the destination.
When using this technique, the zero-length files created by the initial /CREATE command are tagged as “Changed” files on the second run.
My comment: The Robocopy version XP010 document states the files are tagged as “Older” files on the second run. When I tested on Windows 7 Pro, it shows “Changed” instead. The “Changed” matches the description in the File Classes for Changed - Source & Destination file times are equal, but file sizes are different.
Install hotfix for Windows 7 and Server 2008 R2 build-in Robocopy
Install the hotfix in KB2639043 to fix the Discretionary Access Control Lists (DACLs) for files issue.