Robocopy
Robocopy, or "Robust File Copy", is a command-line folder replication tool. It was available as part of the Windows Resource Kit, and introduced as a standard feature of Windows Vista.
Robocopy is designed for reliable mirroring of folders or folder trees. It has features to ensure all NTFS attributes and properties are copied, and includes additional restart code for network connections subject to disruption.
Robocopy is notable for capabilities above and beyond the built-in Windows COPY and XCOPY commands, including the following:
- Ability to tolerate network outages and resume copying where it previously left off (incomplete files are noted with a date stamp of 1/1/1980 and contain a recovery record so Robocopy knows where to continue)
- Ability to correctly copy attributes, owner information, alternate data streams, auditing information, and timestamps by default, without the need for numerous oft-forgotten command line switches
- Ability to correctly copy NTFS ACLs, (when /COPYALL provided), and to assert the Windows NT "backup right" (/B) so an administrator may copy an entire directory, including files denied readability to the administrator
- Persistence by default, with a programmable number of automatic retries if a file cannot be opened
- A "mirror" mode, which keeps trees in sync by optionally deleting files out of the destination that are no longer present in the source
- Ability to copy large numbers of files that would otherwise crash the built-in XCOPY utility.
- A progress indicator on the command line that updates continuously.
Notably, Robocopy cannot copy open files that are in use by other users or applications. The so-called Backup mode is an administrative privilege that allows Robocopy to override permissions settings (specifically, NTFS ACLs) for the purpose of making backups. The Windows Volume Shadow Copy service is the only Windows subsystem that can open files while they are in use. Robocopy does not implement accessing the Volume Shadow Copy service in any way, inhibiting its usefulness as a backup utility for volumes that may be in use.
Although Robocopy itself is a command-line tool, Microsoft Technet has also provided a GUI front-end.[1]
Folder copier, not file copier
The syntax of Robocopy is markedly different from that of standard copy commands, in that it only accepts the names of folders, not files, as its source and destination arguments. Names of files and wild-card designations (such as "*.*") are not acceptable as source or destination. Files may be selected or excepted with the filespec optional filtering argument. Filespecs can only refer to the filenames relative to the folders already selected for copying, and fully-qualified path names are not accepted.
In order to copy the file foo.txt from directory c:\bar to c:\baz, you could use the following syntax: robocopy c:\bar c:\baz foo.txt
Partial list of command line switches
Common options
- /MIR
- Activates mirror mode, deleting any files in the destination that aren't present in the source (equivalent to /E and /PURGE).
- /Z
- Copy files in restartable mode. "Restartable" means Robocopy should write a recovery record inside an incomplete file so if the operation is interrupted or aborted, a future run of Robocopy can resume copying where the previous one left off, instead of starting over at the beginning. This is useful for reliably copying large files or many files over an unreliable network such as a VPN or the Internet. An incomplete file has the same file size as the complete file, and is noted with a date stamp in the file system being within 24 hours of 1/1/1980 00:00.
- /COPYALL
- Makes sure NTFS security information is copied.
- /B
- Opens files in backup mode. Backup mode allows files to be opened without security restrictions, but requires additional rights on both the source and destination systems.
- /ZB
- Use restartable mode; if access denied use backup mode.
Specialized options
- /S
- Copies subdirectories unless they're empty (like XCOPY).
- /E
- Copies subdirectories, even empty ones (like XCOPY).
- /MOV
- Moves the files, removing them from the source folder. /MOVE removes the source folder as well if empty.
- /MON:n
- This will monitor and trigger a copy after n changes (and MOT minutes).
- /MOT:n
- This will set the minimum monitor interval (n minutes) before another copy is triggered.
- /XF filespec
- Excludes files indicated by filespec. Wildcards are accepted. Example: /XF *.bak will skip copying any file with an extension of .bak.
- /XD dirspec
- Excludes directories indicated by dirspec by name/path. Wildcards work (i.e. /XD BKUP* skips copying all directories whose name starts with "BKUP", regardless of where in the source tree they are found).
- /XC
- Exclude changed files.
- /XN
- Exclude newer files.
- /XO
- Exclude older files (Please note that the Robocopy GUI (3.1.1) does not use this switch correctly, meaning it still copies older files over newer ones. Version 3.1.2 corrects this problem.)
- /XX
- Exclude extra files and directories.
- /XL
- Exclude lonely files and directories.
- /IS
- Include same files.
- /IT
- Include tweaked files.
- /XJ
- Exclude junctions. When copying user accounts to another place in Windows Vista, it's important to exclude junctions. There is a junction in '\Users\...\AppData\Local' named 'Application Data' which points to its parent folder, creating a loop which will break Robocopy.
- /R:n
- Tells Robocopy to retry 'n' times before giving up in the event of error (default is 1 million).
- /IPG:n
- Tells Robocopy to pause 'n' milliseconds between packets for network transfers. Useful to preserve bandwidth on slow lines.
- /L
- pretends to do the copy without actually doing it, which is useful for testing a command line without being committed to the results.
- /W:n
- Wait time between retries (default is 30 seconds).
- /PURGE
- Deletes files no longer in the source location.
Logging options
- /NFL
- No file list – don't log file names.
- /NDL
- No directory list – don't log directory names.
- /NS
- No size – don't log file sizes.
- /NC
- No class – don't log file classes.
- /X
- Report all extra files, not just those selected.
- /V
- Produce verbose output, showing skipped files.
- /TS
- Include source file time stamps in the output.
- /FP
- Include full pathname of files in the output.
- /NP
- No progress – don't display % copied.
- /ETA
- Show estimated time of arrival of copied files.
- /LOG:file.txt
- Replace file.txt with the status of the run.
- /LOG+:file.txt
- Append the status of the run to file.txt.
- /TEE
- Output to console window, as well as the log file.
- /NJH
- No job header.
- /NJS
- No job summary.
Known Flaws
Robocopy will not copy folder timestamps from the source folder. Instead, it will use the current date and time when creating new folders. To match the timestamps to the original, another file utility must be used.
See also
References
- Robocopy.exe, Microsoft Windows Server 2003 Resource Kit, help output when run with /? command line switch. Complete help with /??? command line switch.
External links
- ROBOCOPY GUI Robocopy GUI from Microsoft Tech-Net
- XXCOPY A freeware (and paid 'Pro' version) 3rd-party Robocopy equivalent.
- TeraCopy A freeware Robocopy analog with graphical interface, can replace Explorer copy/move functions.
- HoboCopy Volume Shadow Copy capable semi-replacement, to consistently copy files that are locked and in use.
- Windows Server 2003 Resource Kit Tools: [2]