How to really understand robocopy return code of 2

∥☆過路亽.° 提交于 2019-12-11 06:08:04

问题


I am struggling with how to handle a deploy script that sometimes returns a 2 during robocopy. The command and output are below.

It returns 2, which means "extra file".

It appears, overall, to be a success. Should I just accept 2 as being success?

-------------------------------------------------------------------------------

   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------

  Started : Tuesday, January 24, 2017 11:53:40 PM
   Source : C:\Download\Temp\\
     Dest : C:\Inetpub\\

    Files : *.*

  Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /MT:8 /R:1000000 /W:30 

------------------------------------------------------------------------------

      *EXTRA File         689351    C:\Inetpub\\admin\dynamicfile2.zip

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :       510       510         0         0         0         0
   Files :      3564         0      3564         0         0         1
   Bytes :  606.15 m         0  606.13 m         0         0   673.1 k
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : Tuesday, January 24, 2017 11:53:40 PM

回答1:


When in doubt, read the documentation (although in this case SS64 might be a better source):

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.

Exit codes up to and including 7 indicate non-error operational status. Exit codes of 8 and above indicate errors.

Like Mathias already said, whether you do or don't want to treat extra files as an error is up to you. If you don't care about extra or mismatched files/folders just check for exit codes greater than 7:

& robocopy ...
if ($LastExitCode -gt 7) {
    # an error occurred
    exit $LastExitCode
}
exit 0

otherwise check for exit codes greater than 1:

& robocopy ...
if ($LastExitCode -gt 1) {
    # an error occurred
    exit $LastExitCode
}
exit 0


来源:https://stackoverflow.com/questions/41844717/how-to-really-understand-robocopy-return-code-of-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!