ROBOCOPY Exit Codes

The return code from Robocopy.exe is a bitmap, defined as follows:

   Error    Meaning if set

    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. 

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

    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.

These can be combined, giving a few extra exit codes:

    3 (2+1) Some files were copied. Additional files were present. No failure was encountered.

    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.

An Exit Code of 0-7 is success and any value >= 8 indicates that there was at least one failure during the copy operation.
Many deployment tools like SCCM will default to assuming any Exit Code greater than 0 is an error.

You can use this in a batch file to report anomalies, as follows:

    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  
To capture the exit code of a non-powerShell process, wait for the process to finish (-wait) and then select the Exitcode:

$exitCode = (Start-Process -FilePath 'robocopy' -ArgumentList 'options' -PassThru -Wait).ExitCode

PowerShell also has an automatic $lastexitcode variable which may contain the same thing.

Error 0x800700DF: The file size exceeds the limit allowed and cannot be saved.
This error may appear when copying from a WEBdav drive, WEBdav ignores the robocopy/MAX setting.
See Q2668751 for WebDAV size/time limits (default=50 MB/30 minutes).

Bugs
Version XP026 returns a success errorlevel even when it fails.

Examples

Copy files from one server to another

ROBOCOPY \\Server1\reports \\Server2\backup *.*
IF %ERRORLEVEL% LSS 8 goto finish Echo Something failed & goto :eof :finish Echo All done, no fatal errors.

“Few men of action have been able to make a graceful exit at the appropriate time” ~ Malcolm Muggeridge

Related commands

Robocopy - Robust File and Folder Copy.
HowTo: Error Handling in a batch file
HowTo: Errorlevel - Errorlevel and Exit codes.
Q954404 - Robocopy Return codes in Windows 2008 R2.
Copy Open files - with VShadow.exe (Shadow copies).
Equivalent bash command: rsync - Remote file copy (Synchronize file trees).


 
Copyright © 1999-2024 SS64.com
Some rights reserved