The return code from Robocopy is a bit map, defined as follows:
Hex Decimal Meaning if set
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.
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×04 4 Some Mismatched files or directories were detected.
Examine the output log. Some housekeeping may be needed.
0×02 2 Some Extra files or directories were detected.
Examine the output log for details.
0×01 1 One or more files were copied successfully (that is, new files have arrived).
0×00 0 No errors occurred, and no copying was done.
The source and destination directory trees are completely synchronized.
You can use this in a batch file to report anomalies, as follows:
if errorlevel 16 echo ***FATAL ERROR*** & goto end
if errorlevel 15 echo OKCOPY + FAIL + MISMATCHES + XTRA & goto end
if errorlevel 14 echo FAIL + MISMATCHES + XTRA & goto end
if errorlevel 13 echo OKCOPY + FAIL + MISMATCHES & goto end
if errorlevel 12 echo FAIL + MISMATCHES& goto end
if errorlevel 11 echo OKCOPY + FAIL + XTRA & goto end
if errorlevel 10 echo FAIL + XTRA & goto end
if errorlevel 9 echo OKCOPY + FAIL & goto end
if errorlevel 8 echo FAIL & goto end
if errorlevel 7 echo OKCOPY + MISMATCHES + XTRA & goto end
if errorlevel 6 echo MISMATCHES + XTRA & goto end
if errorlevel 5 echo OKCOPY + MISMATCHES & goto end
if errorlevel 4 echo MISMATCHES & goto end
if errorlevel 3 echo OKCOPY + XTRA & goto end
if errorlevel 2 echo XTRA & goto end
if errorlevel 1 echo OKCOPY & goto end
if errorlevel 0 echo No Change & goto end
:end
Example:
Copy files from one server to another
ROBOCOPY \\Server1\reports \\Server2\backup *.*
if errorlevel 8 GOTO sub_fail
if errorlevel 4 GOTO sub_housekeeping
if errorlevel 1 GOTO :eof
goto :eof :sub_fail
echo Something failed & goto :eof
:sub_housekeeping
echo Some housekeeping may be needed! & goto :eof
Bugs
Version XP026 returns a success errorlevel even when it fails.
“Few men of action have been able to make a graceful exit at the appropriate time” ~ Malcolm Muggeridge
Related:
Robocopy -
Robust File and Folder Copy
Copy Open files - with VShadow.exe (Shadow copies)
Equivalent bash command:
rsync - Remote file copy (Synchronize file trees)
© Copyright SS64.com 1999-2013
Some rights reserved