I'm kind of new to batch scripting. As a newbie I find both both of them useful while scripting What are the key differences between xcopy and robocopy?
Robocopy replaces XCopy in the newer versions of windows
- Uses Mirroring, XCopy does not
- Has a /RH option to allow a set time for the copy to run
- Has a /MON:n option to check differences in files
- Copies over more file attributes than XCopy
Yes i agree with Mark Setchell, They are both crap. (brought to you by Microsoft)
UPDATE:
XCopy return codes:
0 - Files were copied without error.
1 - No files were found to copy.
2 - The user pressed CTRL+C to terminate xcopy. enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
5 - Disk write error occurred.
Robocopy returns codes:
0 - No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
1 - One or more files were copied successfully (that is, new files have arrived).
2 - Some Extra files or directories were detected. No files were copied Examine the output log for details.
3 - (2+1) Some files were copied. Additional files were present. No failure was encountered.
4 - Some Mismatched files or directories were detected. Examine the output log. Some housekeeping may be needed.
5 - (4+1) Some files were copied. Some files were mismatched. No failure was encountered.
6 - (4+2) Additional files and mismatched files exist. No files were copied and no failures were encountered. This means that the files already exist in the destination directory
7 - (4+1+2) Files were copied, a file mismatch was present, and additional files were present.
8 - Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further.
16 - Serious error. Robocopy did not copy any files. Either a usage error or an error due to insufficient access privileges on the source or destination directories.
There is more details on Robocopy return values here: http://ss64.com/nt/robocopy-exit.html and XCopy here: https://ss64.com/nt/xcopy.html
robocopy "." "D:\tmp\" /MOV
" (D:
is a physical hard drive). This work. Turn off the computer that shares that directory (while copying). This won't work with tons of errors, press CTRL-C and try again. robocopy
has tried to move all the files from the C:\Windows\System32
directory. True. You can't do that with xcopy
. –
Encaustic The most important difference is that robocopy
will (usually) retry when an error occurs, while xcopy
will not. In most cases, that makes robocopy
far more suitable for use in a script.
Addendum: for completeness, there is one known edge case issue with robocopy; it may silently fail to copy files or directories whose names contain invalid UTF-16 sequences. If that's a problem for you, you may need to look at third-party tools, or write your own.
robocopy
again. Never ever. Not safe at all. Microsoft should finish properly such programs before releasing it. You copy from the network, the network is down, then it tries to move files from where it is and... it's C:\Windows\System32
. Good job Microsoft, after 20 years still not able to make a program that moves properly files. I'll show this example to my students so they'll understand why they have to go to Linux. –
Encaustic xcopy
vs robocopy
... they talk by themselves. –
Encaustic The differences I could see is that Robocopy has a lot more options, but I didn't find any of them particularly helpful unless I'm doing something special.
I did some benchmarking of several copy routines and found XCOPY and ROBOCOPY to be the fastest, but to my surprise, XCOPY consistently edged out Robocopy.
It's ironic that robocopy retries a copy that fails, but it also failed a lot in my benchmark tests, where xcopy never did.
I did full file (byte by byte) file compares after my benchmark tests.
Here are the switches I used with robocopy in my tests:
**"/E /R:1 /W:1 /NP /NFL /NDL"**.
If anyone knows a faster combination (other than removing /E, which I need), I'd love to hear.
Another interesting/disappointing thing with robocopy is that if a copy does fail, by default it retries 1,000,000 times with a 30 second delay between each try. If you are running a long batch file unattended, you may be very disappointed when you come back after a few hours to find it's still trying to copy a particular file.
The /R and /W switches let you change this behavior.
- With /R you can tell it how many times to retry,
- /W let's you specify the wait time before retries.
If there's a way to attach files here, I can share my results.
- My tests were all done on the same computer and
- copied files from one external drive to another external,
- both on USB 3.0 ports.
I also included FastCopy and Windows Copy in my tests and each test was run 10 times. Note, the differences were pretty significant. The 95% confidence intervals had no overlap.
inline
code ` (its the squiggle/tilde key that looks like this: ~) and enter twice for a new paragraph. –
Karlotta Its painful to hear people are still suffering at the hands of *{COPY} whatever the version. I am a seasoned batch and Bash script writer and I recommend rsync , you can run this within cygwin (cygwin.org) or you can locate some binaries floating around . and you can redirect output to 2>&1 to some log file like out.log for later analysing. Good luck people its time to love life again . =M. Kaan=
robocopy
solves my speed issue (at the expense of missing copy verification, which I would blame for the speed difference except that under Linux it's still very fast). –
Lacker I have written lot of scripts to automate daily backups etc. Previously I used XCopy and then moved to Robocopy. Anyways Robocopy and XCopy both are frequently used in terms of file transfers in Windows. Robocopy stands for Robust File Copy. All type of huge file copying both these commands are used but Robocopy has added options which makes copying easier as well as for debugging purposes.
Having said that lets talk about features between these two.
Robocopy becomes handy for mirroring or synchronizing directories. It also checks the files in the destination directory against the files to be copied and doesn't waste time copying unchanged files.
Just like myself, if you are into automation to take daily backups etc, "Run Hours - /RH" becomes very useful without any interactions. This is supported by Robocopy. It allows you to set when copies should be done rather than the time of the command as with XCopy. You will see robocopy.exe process in task list since it will run background to monitor clock to execute when time is right to copy.
Robocopy supports file and directory monitoring with the "/MON" or "/MOT" commands.
Robocopy gives extra support for copying over the "archive" attribute on files, it supports copying over all attributes including timestamps, security, owner, and auditing information.
Hope this helps you.
I recently had a need to copy 12 TB of data to prepare for a RAID conversion. In my research and experience with the process, I winded-up using xcopy, utilizing the following parameters:
xcopy D: E: /C/H/E/R/Y/D /EXCLUDE:C:\EXCLUDE.TXT
The exclude file needed to be created by the PC administrator, otherwise, it will not be interpreted. Inside the Exclude file, add each directory one line at a time. Then, use a Command UI, as an Administrator to execute the xcopy command. Another thing, I needed to create a link to my other PC with "net use E:", etc... Otherwise, the Drive letter would not work if a Mapped Drive was created from a Right-Click, for instance.
As far as Speed is concerned, I found xcopy to me much faster than robocopy. I tried multiple parameters with robocopy, but it never seemed to take off like xcopy did during my sessions. Additionally, I can stop the copy session with the "CMD C" option at any time and return where I left off without issues. Robocopy exibited the same behavior; so there was no difference in that area.
They are both rubbish! XCOPY
was older and unreliable, so Microsoft replaced it with ROBOCOPY
, which is still rubbish.
Don't worry though, it is a long-standing tradition that was started by the original COPY
command, which to this day, still needs the /B
switch to get it to actually copy properly!
copy
defaults to /b
on binary files now. I'm not sure where you get your hatred of robocopy from... your link just shows that the archive
attribute is being utilised as it is designed. –
Cynar rsync
or cp
. –
Cicada hatred
. I see humor in it. And god knows why there have to be 3 versions of a command that does copy function. copy, xcopy & robocopy... why not build on the single copy? For any new block to windows world of scripting. this is making a steep learning curve unlike the shell programming. –
Volvulus copy
and xcopy
were part of DOS, and they had to be separate because copy
was an internal command and xcopy
an external one. Windows included them both for backwards compatibility. The robocopy
command was originally developed by a separate team, initially for internal use and later as part of the resource kit. It didn't become a built-in part of Windows until later on. (I'm also dubious about the claim that shell programming doesn't have a steep learning curve. The syntax is pretty darned abtruse!) –
Douglas cp file1.txt file1.txt.bak
- done. –
Ubald © 2022 - 2024 — McMap. All rights reserved.