robocopy 批处理文件给出错误代码 2 和 3

robocopy 批处理文件给出错误代码 2 和 3

我有一个批处理文件,用于从不同的地方获取 rar 文件的 robocopy,它以前工作得很好,但最近它给了我错误代码 2 和 3,但 robocopy 工作正常,我甚至没有在批处理文件中更改任何内容,它只是突然开始这样做

Net USE T: \\IP-Address\C$ Password /USER:hqadmin /PERSISTENT:YES 
if not errorlevel 1 set /A C0nnection_Success+=1 && echo "\\Connected Succesfully" >C:\LogSchoolXp.txt
if errorlevel 1 set /A C0nnection_Failed+=1 && echo "\\Failed To Connect" >>C:\LogSchoolXp.txt
psexec \\Ip-Address cmd /s /c "set path=D:\WinRAR\; && del c:\TempSchoolxp\*.* /s /q  && rar a -dh -ep1  c:\TempSchoolxp\XXX.rar c:\schoolxp\xxx.mdb"
timeout 5
robocopy \\IP-Address\c$\TempSchoolxp\ C:\backup\schoolxp\20\ /mov /NJS /NFL /NDL /NJH /nc /ns /np /r:2 /w:2 
if %ERRORLEVEL% EQU 1 set /A C0py_Success+=1 && echo "----- Done             Date: %date%   ------     Time: %time%" >>C:\LogSchoolXp.txt
if not %ERRORLEVEL% EQU 1 set /A C0py_Failed+=1 && set  Arr[0]= School && echo "----- Failed             Date: %date%   ------     Time: %time% ======= <<ERRORLEVEL IS EQUAL TO %ERRORLEVEL%>>" >>C:\LogSchoolXp.txt
NET USE T: /DELETE

答案1

最近它给我错误代码 2 和 3

这些是警告(并且没有发生错误):

Robocopy 的返回代码是一个位图,定义如下:

Hex   Decimal  Meaning if set

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×03   3       (2+1) Some files were copied. Additional files were present. No failure was encountered.

...

您可以更改批处理文件以仅报告实际错误:

任何大于 7 的值都表示复制操作期间至少发生一次失败

您可以在批处理文件中使用它来报告异常,如下所示:

if %ERRORLEVEL% EQU 16 echo ***FATAL ERROR*** & goto end
if %ERRORLEVEL% EQU 15 echo OKCOPY + FAIL + MISMATCHES + XTRA & goto end
if %ERRORLEVEL% EQU 14 echo FAIL + MISMATCHES + XTRA & goto end
if %ERRORLEVEL% EQU 13 echo OKCOPY + FAIL + MISMATCHES & goto end
if %ERRORLEVEL% EQU 12 echo FAIL + MISMATCHES& goto end
if %ERRORLEVEL% EQU 11 echo OKCOPY + FAIL + XTRA & goto end
if %ERRORLEVEL% EQU 10 echo FAIL + XTRA & goto end
if %ERRORLEVEL% EQU 9 echo OKCOPY + FAIL & goto end
if %ERRORLEVEL% EQU 8 echo FAIL & goto end
if %ERRORLEVEL% EQU 7 echo OKCOPY + MISMATCHES + XTRA & goto end
if %ERRORLEVEL% EQU 6 echo MISMATCHES + XTRA & goto end
if %ERRORLEVEL% EQU 5 echo OKCOPY + MISMATCHES & goto end
if %ERRORLEVEL% EQU 4 echo MISMATCHES & goto end
if %ERRORLEVEL% EQU 3 echo OKCOPY + XTRA & goto end
if %ERRORLEVEL% EQU 2 echo XTRA & goto end
if %ERRORLEVEL% EQU 1 echo OKCOPY & goto end
if %ERRORLEVEL% EQU 0 echo No Change & goto end
:end

来源Robocopy 退出代码 - Windows CMD - SS64.com

相关内容