robocopy 退出代码 ... robocopy 只是有问题还是我遗漏了什么?

ant*_*red 5 windows robocopy

我们正在使用 robocopy(文件版本 5.1.10.1027)来镜像目录树。robocopy 由 python 脚本调用,而不是手动调用。我们依靠 robocopy 的退出代码来确定操作是否成功。如果成功,我们的脚本会继续做很多其他花哨的事情。否则它会立即中止。

据称,robocopy 的退出代码是一个带有以下标志的位字段(https://ss64.com/nt/robocopy-exit.html):

十六进制十进制含义如果设置

0×00   0       No errors occurred, and no copying was done.
               The source and destination directory trees are completely synchronized. 

0×01   1       One or more files were copied successfully (that is, new files have arrived).

0×02   2       Some Extra files or directories were detected. No files were copied
               Examine the output log for details. 

0×04   4       Some Mismatched files or directories were detected.
               Examine the output log. Housekeeping might be required.

0×08   8       Some files or directories could not be copied
               (copy errors occurred and the retry limit was exceeded).
               Check these errors further.

0×10  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.
Run Code Online (Sandbox Code Playgroud)

根据这些信息,任何大于 7 的退出代码都可以被认为意味着至少发生了一个错误,因此这是我们的脚本用来确定 robocopy 是否成功的标准。

现在我们遇到了一个问题,由于访问被拒绝问题,robocopy 无法删除目标中不再存在于源中的文件:

  *EXTRA File            661    AdminTable_version.h
  2017/06/13 02:38:08 ERROR 5 (0x00000005) Deleting Extra File E:\fw_cu\build\output\AdminTable_version.h
Run Code Online (Sandbox Code Playgroud)

访问被拒绝。

但无论如何都会以退出代码 3 返回。换句话说,设置了标志 0x01 和 0x02,意思是:

One or more files were copied successfully (that is, new files have arrived).
Run Code Online (Sandbox Code Playgroud)

Some Extra files or directories were detected. No files were copied
Examine the output log for details.
Run Code Online (Sandbox Code Playgroud)

我们使用以下命令行:

robocopy.exe M:\fw_cu E:\fw_cu /MIR /FFT /W:5 /NP
Run Code Online (Sandbox Code Playgroud)

现在,除非我遗漏了什么,否则这些退出代码标志要么没有传达足够的信息来可靠地判断操作是否 100% 成功,要么 robocopy 根本没有一致地使用它们。我觉得在镜像操作期间未能删除至少一个文件将保证 0x08 或 0x10 标志。