简体   繁体   English

xcopy 和 robocopy 之间的区别

[英]Difference between xcopy and robocopy

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 之间的主要区别是什么?

Robocopy replaces XCopy in the newer versions of windows Robocopy 在较新版本的 Windows 中替换了 XCopy

  1. Uses Mirroring, XCopy does not使用镜像,XCopy 不
  2. Has a /RH option to allow a set time for the copy to run有一个 /RH 选项来允许复制运行的设定时间
  3. Has a /MON:n option to check differences in files有一个 /MON:n 选项来检查文件中的差异
  4. Copies over more file attributes than XCopy比 XCopy 复制更多的文件属性

Yes i agree with Mark Setchell, They are both crap.是的,我同意 Mark Setchell 的观点,他们都是废话。 (brought to you by Microsoft) (由微软提供)


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

The most important difference is that robocopy will (usually) retry when an error occurs, while xcopy will not.最重要的区别是robocopy会(通常)在发生错误时重试,而xcopy不会。 In most cases, that makes robocopy far more suitable for use in a script.在大多数情况下,这使得robocopy更适合在脚本中使用。

Addendum: for completeness, there is one known edge case issue with robocopy;附录:为了完整性,robocopy 存在一个已知的边缘情况问题; it may silently fail to copy files or directories whose names contain invalid UTF-16 sequences. 它可能会默默地无法复制名称包含无效 UTF-16 序列的文件或目录。 If that's a problem for you, you may need to look at third-party tools, or write your own.如果这对您来说是个问题,您可能需要查看第三方工具,或编写自己的工具。

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. robocopy 的另一个有趣/令人失望的事情是,如果副本确实失败,默认情况下它会重试 1,000,000 次,每次尝试之间有 30 秒的延迟。 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. /R 和 /W 开关可让您更改此行为。

  • With /R you can tell it how many times to retry,使用 /R 你可以告诉它重试多少次,
  • /W let's you specify the wait time before retries. /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.我还在我的测试中包含了 FastCopy 和 Windows Copy,并且每个测试都运行了 10 次。 Note, the differences were pretty significant.请注意,差异非常显着。 The 95% confidence intervals had no overlap. 95% 置信区间没有重叠。

Its painful to hear people are still suffering at the hands of *{COPY} whatever the version.听到人们仍然在 *{COPY} 的手中受苦,无论版本如何,这令人痛苦。 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 .我是一个经验丰富的批处理和 Bash 脚本编写者,我推荐 rsync ,你可以在 cygwin (cygwin.org) 中运行它,或者你可以找到一些浮动的二进制文件。 and you can redirect output to 2>&1 to some log file like out.log for later analysing.并且您可以将输出重定向到 2>&1 到一些日志文件,例如 out.log 以供以后分析。 Good luck people its time to love life again .好运的人是时候重新热爱生活了。 =M. =M。 Kaan=卡恩=

I have written lot of scripts to automate daily backups etc. Previously I used XCopy and then moved to Robocopy.我写了很多脚本来自动执行日常备份等。以前我使用 XCopy,然后转移到 Robocopy。 Anyways Robocopy and XCopy both are frequently used in terms of file transfers in Windows.无论如何,Robocopy 和 XCopy 都经常用于 Windows 中的文件传输。 Robocopy stands for Robust File Copy. Robocopy 代表强大的文件复制。 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.使用所有类型的大文件复制这两个命令,但 Robocopy 添加了选项,使复制更容易以及用于调试目的。

Having said that lets talk about features between these two.话虽如此,让我们谈谈这两者之间的功能。

  • Robocopy becomes handy for mirroring or synchronizing directories. Robocopy 对于镜像或同步目录变得很方便。 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.就像我自己一样,如果您喜欢自动化进行日常备份等,“运行时间 - / RH”在没有任何交互的情况下变得非常有用。 This is supported by Robocopy.这是由 Robocopy 支持的。 It allows you to set when copies should be done rather than the time of the command as with XCopy.它允许您设置何时应该完成复制,而不是像 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.exe 进程,因为它会在后台运行以监视时钟以在合适的时间复制时执行。

  • Robocopy supports file and directory monitoring with the "/MON" or "/MOT" commands. Robocopy 支持使用“/MON”或“/MOT”命令进行文件和目录监视。

  • 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. Robocopy 为复制文件的“存档”属性提供了额外的支持,它支持复制所有属性,包括时间戳、安全性、所有者和审计信息。

Hope this helps you.希望这对你有帮助。

They are both rubbish!他们两个都是垃圾! XCOPY was older and unreliable, so Microsoft replaced it with ROBOCOPY , which is still rubbish. XCOPY较旧XCOPY可靠,因此微软将其替换为ROBOCOPY ,这仍然是垃圾。

http://answers.microsoft.com/en-us/windows/forum/windows_8-files/robocopy-appears-to-be-broken-in-windows-8/9a7634c4-3a9d-4f2d-97ae-093002a638a9 http://answers.microsoft.com/en-us/windows/forum/windows_8-files/robocopy-appears-to-be-broken-in-windows-8/9a7634c4-3a9d-4f2d-97ae-093002a638a9

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开关才能使其真正正确复制!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM