我正在努力处理有时在robocopy
期间返回2的部署脚本。命令和输出如下。
它返回2,表示“额外文件”。
总体看来,这是成功的。我应该接受2作为成功吗?
-------------------------------------------------- -----------------------------
ROBOCOPY::Windows的强大文件复制
-------------------------------------------------- -----------------------------
开始时间:2017年1月24日星期二晚上11:53:40
来源:C:\ Download \ Temp \\
目的地:C:\ Inetpub \\
文件:*。*
选项:*。* / S / E / DCOPY:DA / COPY:DAT / PURGE / MIR / MT:8 / R:1000000 / W:30
-------------------------------------------------- ----------------------------
* EXTRA文件689351 C:\ Inetpub \\ admin \ dynamicfile2.zip
-------------------------------------------------- ----------------------------
总计跳过的不匹配的复制失败的额外费用
Dirs:510510 0 0 0 0 0
文件:3564 0 3564 0 0 1
字节:606.15 m 0 606.13 m 0 0 673.1 k
时间:0:00:00 0:00:00 0:00:00 0:00:00
截至:2017年1月24日星期二晚上11:53:40
最佳答案
如有疑问,请阅读documentation(尽管在这种情况下SS64可能是更好的来源):
The following table lists and describes the return codes that are used by the Robocopy utility.
0 No files were copied. No failure was encountered. No files were mismatched. The files already exist in the destination directory; therefore, the copy operation was skipped.
1 All files were copied successfully.
2 There are some additional files in the destination directory that are not present in the source directory. No files were copied.
3 Some files were copied. Additional files were present. No failure was encountered.
5 Some files were copied. Some files were mismatched. No failure was encountered.
6 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 Files were copied, a file mismatch was present, and additional files were present.
8 Several files did not copy.Note Any value greater than 8 indicates that there was at least one failure during the copy operation.
退出代码,最多7个(包括7个)指示无错误运行状态。退出代码8及以上表示错误。
就像Mathias已经说过的一样,您是否愿意将多余的文件视为错误取决于您。如果您不关心多余或不匹配的文件/文件夹,只需检查退出代码是否大于7:
& robocopy ...
if ($LastExitCode -gt 7) {
# an error occurred
exit $LastExitCode
}
exit 0
否则,请检查退出代码是否大于1:
& robocopy ...
if ($LastExitCode -gt 1) {
# an error occurred
exit $LastExitCode
}
exit 0
关于powershell - 如何真正了解robocopy返回码2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41844717/