Skip to content

Manage Robocopy Error Codes When .Bat Is Run In Scheduled Tasks

by on November 20, 2014

Task Scheduler does not easily handle error codes for robocopy. To send errors to the task scheduler only when there is an actual failure, use something like the below, where 0 is success and 1 is failure

robocopy_myfolder.bat

REM Robocopy.exe Location | source location (backups on drive) | destination location (SMS drive) | option/switch (/s – copy subdirectories excluding empty ones or /E copy empty folder for structure)
c:\robocopy\robocopy.exe C:\my\file\location\awd \\network-machine\ShareName\My\Copy\Location /E /log:c:\robocopy\robocopy_myfolder.log
if errorlevel 16  echo  ***FATAL ERROR***  & EXIT /b 1
if errorlevel 15  echo FAIL MISM XTRA COPY & EXIT /b 1
if errorlevel 14  echo FAIL MISM XTRA      & EXIT /b 1
if errorlevel 13  echo FAIL MISM      COPY & EXIT /b 1
if errorlevel 12  echo FAIL MISM           & EXIT /b 1
if errorlevel 11  echo FAIL      XTRA COPY & EXIT /b 1
if errorlevel 10  echo FAIL      XTRA      & EXIT /b 1
if errorlevel  9  echo FAIL           COPY & EXIT /b 1
if errorlevel  8  echo FAIL                & EXIT /b 1
if errorlevel  7  echo         MISM XTRA COPY & EXIT /b 0
if errorlevel  6  echo      MISM XTRA      & EXIT /b 0
if errorlevel  5  echo      MISM      COPY & EXIT /b 0
if errorlevel  4  echo      MISM           & EXIT /b 0
if errorlevel  3  echo           XTRA COPY & EXIT /b 0
if errorlevel  2  echo           XTRA      & EXIT /b 0
if errorlevel  1  echo                COPY & EXIT /b 0
if errorlevel  0  echo    –no change–    & EXIT /b 0
:end

Reference

http://support.microsoft.com/kb/954404

http://technet.microsoft.com/en-us/library/cc733145.aspx

http://weblogs.sqlteam.com/robv/archive/2010/02/17/61106.aspx

command line syntax key http://technet.microsoft.com/en-us/library/cc771080.aspx

Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: