Robocopy - Robust Command Line File-Folder Copy-Replace
Robocopy - Copying files the right way in Windows -- Chris Titus -- https://christitus.com/robocopy/
I am sure most windows users will not be knowing about ROBOCOPY, the windows command-line robust copy/replace command. Teracopy has been said to be using this functionality for ages, and windows has included it since before Windows NT 4.0, in different ways, and as a stable one since 4.0, in its resource pack.
Created by Kevin Allen and first released as part of the Windows NT 4.0 Resource Kit, it has been a standard feature of Windows since Windows Vista and Windows Server 2008. The command is robocopy
.
The secret dirt is that Robocopy was first written by MS colleague Kevin Allen, and he started sharing copies around in 1994ish. From there, and after many iterations and heavy-duty real-world feedback, robocopy ended up in the Windows Resource Kit, and then later merged into the core Windows package. In the beginning, Kevin was a very experienced programmer, but new to the Win32 API; so robocopy was one of his projects to educate himself about Windows programming. Later on, ITG used robocopy to routinely transfer many gigabytes of data around MS global offices, every night; it became very robust and battle-hardened. It is a long time now since Kevin was involved in the robocopy source code at all; it is maintained by the Windows team.
Syntax
By default Robocopy will only copy a file if the source and destination have different time stamps or different file sizes.
Syntax
ROBOCOPY Source_folder Destination_folder [files_to_copy] [options]
Key
file(s)_to_copy : A list of files or a wildcard.
(defaults to copying *.*)
cmd
robocopy <source> <destination> [<file>[ ...]] [<options>]
For example, to copy a file named yearly-report.mov from c:reports to a file share marketingvideos while enabling multi-threading for higher performance (with the /mt parameter) and the ability to restart the transfer in case it's interrupted (with the /z parameter), type:
dos
robocopy c:reports 'marketingvideos' yearly-report.mov /mt /z
Features
Robocopy is noted for capabilities above and beyond the built-in Windows copy and xcopy commands, including the following, some requiring appropriate command-line options:
- Ability to tolerate network interruptions and resume copy (incomplete files are marked with a date stamp of 1970-01-01 and contain a recovery record so Robocopy knows where to continue from).
- Ability to skip NTFS junction points which can cause copying failures because of infinite loops (/XJ)
- Ability to copy file data and attributes correctly, and to preserve original timestamps, as well as NTFS ACLs, owner information, and audit information using the /COPYALL or /COPY: command line switches.
- Beginning with the XP026 version, the ability to copy folder (or directory) date and timestamps (/DCOPY:T), even with the ability to update folder timestamps (copied from existing folders) on folders already created from previous versions (that did not copy the folder date and timestamps).
- Ability 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 copied.
- A "mirror" mode, which keeps trees synchronised by also deleting files in the destination that are not present in the source.
- Ability to skip files already in the destination folder with identical size and timestamp.
- A continuously updated command-line progress indicator.
- Ability to copy paths exceeding 259 characters — up to a theoretical limit of about 32,000 characters — without errors.
- Multithreaded copying introduced with Windows 7 and Windows Server 2008 R2.
- Return code on program termination for batch file usage.
Compression
Since Windows Server 2019 and Windows 10, a compression option is available in robocopy when copying across a network. With this switch, if the destination computer supports SMB compression and the files being copied are very compressible, there may be significant improvements to performance. The SMB compression adds inline whitespace compression to file transfers. Compression is also available with the xcopy command and Hyper-V Live Migration with SMB.
Examples of use
Here are some examples of usage, which is not case-sensitive. If more than one option is specified, they must be separated by spaces.
Copy directory contents of the source Directory A to the destination Directory B (including file data, attributes and timestamps), recursively with empty directories (/E):
Robocopy "C:Directory A" "C:Directory B" /E
If directory names have non-standard characters, such as spaces, they must be enclosed in double quotes, as is usual in the command line.
Copy directory recursively (/E), copy all file information (/COPYALL, equivalent to /COPY:DATSOU, D=Data, A=Attributes, T=Timestamps, S=Security=NTFS ACLs, O=Owner info, U=Auditing info), do not retry locked files (/R:0) (the number of retries on failed copies default value is 1 million), preserve original directories' Timestamps (/DCOPY:T - requires version XP026 or later):
Robocopy C:A C:B /COPYALL /E /R:0 /DCOPY:T
Mirror A to B, destroying any files in B that are not present in A (/MIR), copy files in resume mode (/Z) in case network connection is lost:
Robocopy C:A backupserverB /MIR /Z
I was able to gather a video guide courtesy of Adam Bertram from his thread.
Few example images as well from his thread:
For the full reference, see the Microsoft TechNet Robocopy page.
More information can be found at: SS64 Manpage | Wikipedia | Windows Docs