robocopy
{{Short description|Windows command-line component specialized in file transfer}}
{{Infobox software
| name = Robocopy
| other_names = Robust File Copy for Windows
| logo =
| screenshot =
| caption =
| developer = Microsoft
| operating_system = Windows NT 4 and later
| included with = Windows Vista and later
| released = {{Release year|df=yes|1996}}
| genre = Command
| latest release version = {{Latest stable software release/Windows 11}}
| license = Freeware
| website = {{URL|https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy}}
}}
Robocopy is a command-line file transfer utility for Microsoft Windows. Robocopy is functionally more comprehensive than the COPY command and XCOPY, but replaces neither. Created by Kevin Allen{{cite web |title=AMA with Dave Plummer, creator of Task Manager |url=https://www.reddit.com/r/IAmA/comments/kfpjhg/i_am_dave_plummer_author_of_windows_task_manager/ggdh12l?context=3 |website=Reddit.com |date = 18 December 2020|access-date=19 December 2020}} 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.
Features
Robocopy provides features not found in the built-in Windows COPY and XCOPY commands, including the following:
- Recovering from temporary loss of network connectivity (Incomplete files are marked with a date stamp of 1970-01-01 and contain a recovery record so Robocopy knows where to continue from).
- Detecting and skipping NTFS junction points, which, under certain circumstances, may cause copying failures because of infinite loops (with the
/XJ
switch). - Preserving any combination of the following: file contents, attributes, metadata (e.g., original timestamps), NTFS ACLs (DACLs, SACLs, and owner). For example, it is possible to copy ACLs from one file to another. Before version XP026, however, this capability was limited to files only, not folders.
- Utilizing the Windows NT "Backup Files and Directories" privilege (
SeBackupPrivilege
, normally not available to standard user accounts) to bypass NTFS ACLs that would otherwise impede transfer (requires the/B
switch).{{cite web | url = http://theether.net/download/Microsoft/Utilities/robocopy.pdf | title = Robocopy.exe - Robust File Copy Utility - Version XP010 | publisher = Microsoft | year = 2003 | quote = Backup mode copies [...] enable you to copy some files as a Backup Operator that you would not be able to copy as a normal user. }}
- Persistence by default, with a programmable number of automatic retries if a file cannot be copied.
- The mirror mode, which keeps two directory trees synchronized by also deleting files in the destination that are not present in the source.
- Skipping files already in the destination folder with identical size and timestamp.
- Progress indicator
- Support for paths exceeding 259 characters, up to a theoretical limit of about 32,000 characters.{{cite web|url=http://www.windowsitpro.com/content1/topic/robocopy-xp010-faq/catpath/migration/page/2|title=Robocopy XP010 FAQ|last=Lewis|first=Dick|date=15 November 2004|website=Windows IT Pro|publisher=Penton Media|page=2|archive-url=https://web.archive.org/web/20121009110523/http://www.windowsitpro.com/content1/topic/robocopy-xp010-faq/catpath/migration/page/2|archive-date=9 October 2012|url-status=dead}}
- Multithreaded copying (introduced with Windows 7 and Windows Server 2008 R2).{{cite web |last1=Holliday |first1=Grant |title=Multi-threaded robocopy for faster copies |url=https://blogs.msdn.microsoft.com/granth/2009/12/07/multi-threaded-robocopy-for-faster-copies/ |website=Grant Holliday's Blog |publisher=Microsoft |archive-url=https://web.archive.org/web/20180813013804/https://blogs.msdn.microsoft.com/granth/2009/12/07/multi-threaded-robocopy-for-faster-copies/ |archive-date=13 August 2018 |date=7 December 2009 |url-status=dead}}
- Return codes (used in automation).{{cite web|url=https://learn.microsoft.com/en-US/troubleshoot/windows-server/backup-and-storage/return-codes-used-robocopy-utility |title=Return codes that are used by the Robocopy utility in Windows Server 2008 or Windows Server 2008 R2 |website=Windows Server troubleshooting |via=Microsoft Learn |publisher=Microsoft |date=23 February 2023 |first1=Han |last1=Liang |first2=Lucy |last2=Zou |first3=Simonx |last3=Xu}}
=Compression=
Since Windows Server 2019 and Windows 10, Robocopy supports SMB compression for transferring files across a network. If the /compress
is specified, the destination computer supports SMB compression, and the files being copied are compressible, the operation enjoys significant performance improvements. 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.{{Cite web |title=RoboCopy supports Copying Files over SMB with Compression on Windows Server 2019, and beyond |first=Sander |last=Berkouwer |website=dirteam.com |date= 7 September 2020|access-date=14 February 2021 |url= https://dirteam.com/sander/2020/09/07/robocopy-supports-copying-files-over-smb-with-compression-on-windows-server-2019-and-beyond/ }}{{Cite web |title=SMB Compression Lowers Bandwidth and Improves Copy Times in Windows Server and Azure|last=Smith |first=Russell |work=Petri |date=27 November 2020 |url= https://petri.com/smb-compression-lowers-bandwidth-and-improves-copy-times-in-windows-server-and-azure}}
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.
;Example 1
:Copy directory contents of the source {{code|Directory A}} to the destination {{code|Directory B}} (including file data, attributes and timestamps), recursively with empty directories (/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.
;Example 2
: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):
:
;Example 3
: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:
:
:For the full reference, see the Microsoft TechNet Robocopy page.{{cite web|url=https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy|title=Robocopy |website=Microsoft Technet |date=7 June 2020}}
=Syntactic focus on copying folders=
Robocopy syntax is markedly different from its predecessors (copy and xcopy), in that it accepts only folder names, without trailing backslash, as its source and destination arguments. File names and wildcard characters (such as *
and ?
) are not valid as source or destination arguments; files may be selected or excluded using the optional "file" filtering argument (which supports wildcards) along with various other options.{{cite web |title=Robocopy |url=https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc733145(v=ws.11) |website=Microsoft Docs |publisher=Microsoft |access-date=14 January 2019 |date=31 October 2016}}
For example, to copy two files from folder c:\bar
to c:\baz
, the following syntax is used:
And to copy all PDF files from c:\bar
to c:\baz
:
The files named are copied only from the folder selected for copying; fully qualified path names are not supported.
CAUTION: A long-standing issue with Robocopy means that if you back up from the root folder of a drive [ e.g., {{code|robocopy d:\ b:\d-backup\ ....}}], the destination files will be given attributes including SH. This means that they will be invisible to normal access (including DIR in cmd.exe). To fix this, add {{code|/a-:SH}} to the robocopy command line - or do an ATTRIB command to remove them afterwards.
Output
Robocopy outputs to the screen, or optionally to a log file, the names of all the directories it encounters, in alphabetical order. Each name is preceded by the number of files in the directory that fulfill the criteria for being copied. If the directory does not yet exist in the target, it is marked "New Dir"; if the directory is empty and the /E option is not used, or it contains no files meeting the criteria, a new directory will not be created.
If the /NFL (no file names in log) option is not used, the files being copied will be listed after the name of the directory they are in.
At the end of the output is a table giving numbers of directories, files, and bytes. For each of these, the table gives the total number found in the source, the number copied (including directories marked "New Dir" even if they are not copied), the number skipped (because they already exist in the target), and the number of mismatches, FAILED, and extras. "Failed" can mean that there was an I/O error that prevented a file being copied, or that access was denied. There is also a row of time taken (in which the time spent on failed files seems to be in the wrong column).
Bandwidth throttling
Robocopy's "inter-packet gap" (IPG) option allows some control over the network bandwidth used in a session. In theory, the following formula expresses the delay ({{Mvar|D}}, in milliseconds) required to simulate a desired bandwidth ({{mvar|BD}}, in kilobits per second), over a network link with an available bandwidth of {{mvar|BA}} kbps:
:
In practice however, some experimentation is usually required to find a suitable delay, due to factors such as the nature and volume of other traffic on the network. The methodology employed by the IPG option may not offer the same level of control provided by some other bandwidth throttling technologies, such as BITS (which is used by Windows Update and BranchCache).
Limitations
- Robocopy does not copy open files. Any process may open files for exclusive read access by withholding the
FILE_SHARE_READ
{{cite web
| url = https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
| title = CreateFile function
| website = Windows App Development
| date = 9 February 2023
| via = Microsoft Learn
| publisher = Microsoft
| quote = FILE_SHARE_READ [...] Enables subsequent open operations on a file or device to request read access. Otherwise, other processes cannot open the file or device if they request read access.
}} flag during opening. Normally Volume Shadow Copy Service is used for such situations, but Robocopy does not use it. Consequently, Robocopy is not suitable for backing up live operating system volumes. However, a separate utility such as ShadowSpawn{{cite web
| url = https://github.com/candera/shadowspawn
| title = ShadowSpawn
| publisher = Craig Andera
| quote = ShadowSpawn.exe is an open source MIT licensed tool that creates and manages shadow copies.
| access-date = 2015-07-14
}} (under MIT License) or DiskShadow{{cite web
| url = http://technet.microsoft.com/library/cc772172(v=ws.10).aspx
| title = Diskshadow
| date = 18 April 2012
| publisher = Microsoft TechNet
| quote = DiskShadow.exe is a tool that exposes the functionality offered by the Volume Shadow Copy Service (VSS).
| access-date = 2013-03-06
}} (included with Windows Server 2008), can be used beforehand to create a shadow copy of a given volume, which Robocopy can then back up.
- Robocopy versions on systems older than Windows Vista do not mirror properly. They ignore changed security attributes of previously mirrored files.{{cite web|url=http://www.zdnet.com.au/blogs/snorage/soa/Microsoft-s-Robocopy-compromise/0,2000064373,339291041,00.htm|title=Microsoft's Robocopy compromise|date=2008-08-04|publisher=ZDNet|archive-url=https://web.archive.org/web/20100317020028/http://www.zdnet.com.au/blogs/snorage/soa/Microsoft-s-Robocopy-compromise/0,2000064373,339291041,00.htm|archive-date=March 17, 2010|url-status=dead|access-date=2012-11-11}}
- When specifying the
/MT[:n]
option to enable multithreaded copying, the/NP
option to disable reporting of the progress percentage for files is ignored. By default the MT switch provides 8 threads. The n is the number of threads you specify if you do not want to use the default.{{cite web|url=http://social.technet.microsoft.com/Forums/windows/en-US/e8c38fe1-df36-4dfc-8dd5-50613b1a7984/robocopys-mt-option-disables-np-option?forum=w7itprogeneral&prof=required|title=Robocopy's /MT option disables /NP option|date=2009-12-13|publisher=Microsoft TechNet|access-date=2014-02-26}}
GUI
Although Robocopy itself is a command-line tool, Microsoft TechNet provided a GUI front-end called Robocopy GUI. It was developed by Derk Benisch, a systems engineer with the MSN Search group at Microsoft, and required .NET Framework 2.0.{{cite news |author=Joshua Hoffman|title=Utility Spotlight Robocopy GUI|url=https://technet.microsoft.com/en-us/magazine/cc160891.aspx|work=TechNet Magazine|publisher=Microsoft Corporation and CMP Media, LLC|date= November 2006|access-date=2008-07-17 }} It included a copy of Robocopy version XP026. It is no longer available from Microsoft, but may be downloaded from the Internet Archive's Wayback Machine.{{cite web |title=Is Microsoft's Robocopy GUI still available |url=https://www.tenforums.com/software-apps/176362-microsofts-robocopy-gui-still-available.html |website=Windows TenForums |access-date=2 May 2022}}
Ken Tamaru of Microsoft developed a copying program with functionality similar to Robocopy, called RichCopy, this was discontinued in 2010. It is not based on Robocopy, and does not require .NET Framework.{{cite news |last=Hoffman |first=Joshua |date=November 2006 |title=Free Utility: RichCopy, an Advanced Alternative to RoboCopy |url=https://technet.microsoft.com/en-us/magazine/2009.04.utilityspotlight.aspx |access-date=2008-07-17 |work=TechNet Magazine |publisher=Microsoft Corporation and CMP Media, LLC}}
Versions
All versions of Robocopy store their version number and release date in their executable file header, viewable with File Explorer or PowerShell. Some of them (not all) report their version numbers in their textual output.
class="wikitable" | |||
Product version | File version | Year | Bundled with |
---|---|---|---|
1.54
| {{sdash}} | 1996 | Windows NT 4.0 Resource Kit | |
1.70
| {{sdash}} | 1997 | Windows NT Resource Kit | |
1.71
| 4.0.1.71 | 1997 | Windows NT Resource Kit | |
1.95
| 4.0.1.95 | 1999 | Windows 2000 Resource Kit | |
1.96
| 4.0.1.96 | 1999 | Windows 2000 Resource Kit | |
XP010
| 5.1.1.1010 | 2003 | Windows 2003 Resource Kit | |
XP026
| 5.1.2600.26 | 2005 | Robocopy GUI v.3.1.2 | |
XP027
| 5.1.10.1027 | 2008 | Windows Vista, Server 2008, 7, 2008 R2 | |
6.1
| 6.1.7601 | 2009 | [http://support.microsoft.com/kb/2639043 KB2639043] | |
colspan = 3 {{N/A|Same as Windows}}
| Windows 8 and later, Windows Server 2012 and later |
See also
- List of file copying software
- Command line
- List of DOS commands
- rsync
- GUI
- SyncToy
- Ultracopier
References
{{Reflist}}
External links
{{Wikibooks|Guide to Windows Commands}}
- [https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy Robocopy documentation] on Microsoft Learn
- [https://ss64.com/nt/robocopy.html RoboCopy documentation] on SS64.com
{{Windows commands}}