September 21, 2010 at 1:51 pm
In SMSS you can only specify a single exit code, so you could just pick one say 8 then in your batch file test for %errorlevel% and if it's an 8 or 16 just "Exit 8". Then the SQLAgent will fail the job on either 8 or 16. You would have to have a separate log to place the real error if you need the detail.
September 23, 2010 at 4:21 am
Thanks for that - it kind of put me on the right track - i think. Although this is what my final solution looks like:
call c:\robocopy\robocopy c:\Source\ \\SomeShare\Destination\ /NP /MAXAGE:1 /R:1 /PURGE
IF ERRORLEVEL 16 GOTO LabelErr
IF ERRORLEVEL 8 GOTO LabelErr
IF ERRORLEVEL 0 GOTO Label0
:LabelErr
SET ERRORLEV=1
ECHO ERRORLEVEL = %ERRORLEV%
EXIT 1
:Label0
SET ERRORLEV=0
ECHO %ERRORLEV%
I then leave the agent job with Process Exit Code of Successful Command as 0. This seems to work OK. Any serious faults such as permission issues cause the SQL agent job to fail (I write out to a log for specific error details) and if the job copies a new file or does nothing if the dest file is as recent as the source, the job reports as successful.
If any one sees any flaws with this please let me know - for the moment it seems to work how i need it to.
Thanks
Doodles
January 19, 2012 at 12:16 pm
Thanks for posting this. It's exactly what I needed today.
November 19, 2013 at 7:15 am
I'm having the exact same issue!
My problem is that I've got round the exit code issue by this:
ROBOCOPY D:\filetocopy E:\filetocopyto ^& IF %ERRORLEVEL% LEQ 1 exit 0 /MAXAGE:1
The problem which I'm having now is that the '/MAXAGE:1' part of the syntax is being ignored when ran, this is important part of the syntax for me but I also need Robocopy to exit with a code 0 when successful! What am I missing?
November 20, 2013 at 12:37 pm
I put the following into a bat file and then execute that from my SQL Server Agent job...
rem RoboCopyErrors.bat
robocopy %*
rem suppress successful robocopy exit statuses, only report genuine errors (bitmask 16 and 8 settings)
set/A errlev="%ERRORLEVEL% & 24"
rem exit batch file with errorlevel so SQL job can succeed or fail appropriately
exit/B %errlev%
I found this here: http://weblogs.sqlteam.com/robv/archive/2010/02/17/61106.aspx
September 26, 2014 at 9:47 am
I don't think this works - bat file seems to always return code 0. Just try to remove everything (or REM) in the file but the actual robocopy command....
Viewing 6 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply