windows xcopy 和 robocopy 之间的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24121046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between xcopy and robocopy
提问by tourist
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?
我是批处理脚本的新手。作为新手,我发现它们在编写脚本时都很有用 xcopy 和 robocopy 之间的主要区别是什么?
回答by Nicolas Tyler
Robocopy replaces XCopy in the newer versions of windows
Robocopy 在较新版本的 Windows 中替换了 XCopy
- 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
- 使用镜像,XCopy 不
- 有一个 /RH 选项来允许复制运行的设定时间
- 有一个 /MON:n 选项来检查文件中的差异
- 比 XCopy 复制更多的文件属性
Yes i agree with Mark Setchell, They are both crap. (brought to you by Microsoft)
是的,我同意 Mark Setchell 的观点,他们都是废话。(由微软提供)
UPDATE:
更新:
XCopy return codes:
XCopy 返回代码:
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:
Robocopy 返回代码:
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
这里有关于 Robocopy 返回值的更多详细信息:http: //ss64.com/nt/robocopy-exit.html
回答by Harry Johnston
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.
最重要的区别是robocopy
(通常)会在发生错误时重试,而xcopy
不会。在大多数情况下,这robocopy
更适合在脚本中使用。
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 存在一个已知的边缘情况问题;它可能会默默地无法复制名称包含无效 UTF-16 序列的文件或目录。如果这对您来说是个问题,您可能需要查看第三方工具,或编写自己的工具。
回答by SixSigmaGuy
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.
我能看到的不同之处在于 Robocopy 有更多的选择,但我没有发现它们中的任何一个特别有用,除非我正在做一些特别的事情。
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.
我对几个复制例程进行了一些基准测试,发现 XCOPY 和 ROBOCOPY 是最快的,但令我惊讶的是,XCOPY 始终领先于 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.
具有讽刺意味的是,robocopy 重试了一个失败的副本,但它在我的基准测试中也失败了很多,而 xcopy 从未这样做过。
I did full file (byte by byte) file compares after my benchmark tests.
在我的基准测试之后,我做了完整的文件(逐字节)文件比较。
Here are the switches I used with robocopy in my tests:
以下是我在测试中与 robocopy 一起使用的开关:
**"/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.
如果有人知道更快的组合(除了删除我需要的 /E 之外),我很想听听。
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.
robocopy 的另一个有趣/令人失望的事情是,如果副本确实失败,默认情况下它会重试 1,000,000 次,每次尝试之间有 30 秒的延迟。如果您在无人看管的情况下运行一个长批处理文件,当您在几个小时后回来发现它仍在尝试复制特定文件时,您可能会非常失望。
The /R and /W switches let you change this behavior.
/R 和 /W 开关可让您更改此行为。
- With /R you can tell it how many times to retry,
- /W let's you specify the wait time before retries.
- 使用 /R 你可以告诉它重试多少次,
- /W 让您指定重试前的等待时间。
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.
- 我的测试都是在同一台电脑上完成的
- 将文件从一个外部驱动器复制到另一个外部驱动器,
- 都在 USB 3.0 端口上。
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.
我还在我的测试中包含了 FastCopy 和 Windows Copy,并且每个测试都运行了 10 次。请注意,差异非常显着。95% 置信区间没有重叠。
回答by Haji M. Kaan
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=
听到人们仍然在 *{COPY} 手中受苦,无论版本如何,这令人痛苦。我是一个经验丰富的批处理和 Bash 脚本编写者,我推荐 rsync ,你可以在 cygwin (cygwin.org) 中运行它,或者你可以找到一些浮动的二进制文件。并且您可以将输出重定向到 2>&1 到一些日志文件,例如 out.log 以供以后分析。好运的人是时候重新热爱生活了。=M。卡恩=
回答by Mark Setchell
They are both rubbish! XCOPY
was older and unreliable, so Microsoft replaced it with ROBOCOPY
, which is still rubbish.
他们两个都是垃圾!XCOPY
旧且不可靠,因此微软将其替换为ROBOCOPY
,这仍然是垃圾。
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
命令开始的长期传统,直到今天,仍然需要/B
切换才能让它真正正确复制!