robocopy errorlevel script not working


I received an error last night but it didn't notify me.
Below is the script that I run and tested.

prior: To test I changed errorlevel 0 to notify then reran the job and it generated an email as expected so the email portion of the script I believe is working.

error: the log shows error 21 (0x0000000015).

Is that errorlevel 21 or 15?
Did it not work right or do I need to create an errorlevel 21?
I'm not much of a programmer so any insight would be greatly appreciated.
thanks

LOG:
2011/08/30 20:02:43 ERROR 21 (0x00000015) Accessing Source Directory D:\data\
The device is not ready.
ERROR: RETRY LIMIT EXCEEDED.
2011/08/30 20:02:44 ERROR 21 (0x00000015) Accessing Source Directory D:\data\
The device is not ready.

here is my script:
robocopy "D:\data" "\nas-2\BranchDataBackUp\XXX\data" /S /PURGE /V /XO /NP /LOG:"\\nas-2\BranchDataBackUp\XXXdata.txt" /B /R:10 /W:15
if errorlevel 16 echo ***FATAL ERROR*** & goto notify
if errorlevel 15 echo OKCOPY + FAIL + MISMATCHES + XTRA & goto notify
if errorlevel 14 echo FAIL + MISMATCHES + XTRA & goto notify
if errorlevel 13 echo OKCOPY + FAIL + MISMATCHES & goto notify
if errorlevel 12 echo FAIL + MISMATCHES & goto notify
if errorlevel 11 echo OKCOPY + FAIL + XTRA & goto notify
if errorlevel 10 echo FAIL + XTRA & goto notify
if errorlevel 9 echo OKCOPY + FAIL & goto notify
if errorlevel 8 echo FAIL & goto notify
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
:Notify
C:\WINDOWS\system32\blat -install exchange.<name>.com BackUp
C:\WINDOWS\system32\blat \\Nt-nas-2\BranchDataBackUp\XXXdata.txt -subject "XXX data BackUpConcerns" -to sysmon@<domain>.com
Goto End
:End
GoHuskersAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
pwustConnect With a Mentor Commented:
The if statement only takes the first command. The rest will be executed in every case.

In order to execute a group of commands, put them in parentheses:
...
if errorlevel 16 (echo ***FATAL ERROR*** & goto notify)
if errorlevel 15 (echo OKCOPY + FAIL + MISMATCHES + XTRA & goto notify)
if errorlevel 14 (echo FAIL + MISMATCHES + XTRA & goto notify)
if errorlevel 13 (echo OKCOPY + FAIL + MISMATCHES & goto notify)
if errorlevel 12 (echo FAIL + MISMATCHES & goto notify)
if errorlevel 11 (echo OKCOPY + FAIL + XTRA & goto notify)
if errorlevel 10 (echo FAIL + XTRA & goto notify)
if errorlevel 9 (echo OKCOPY + FAIL & goto notify)
if errorlevel 8 (echo FAIL & goto notify)
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)
...

Open in new window

0
 
GoHuskersAuthor Commented:
I have added the parentheses but it echos  no change even though there is an error still.
I do erase the log file so it has to create a new one each time.
it seems to go to errorlevel 0 regardless
any ideas?
I have attached the script and the log

logfile:
-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP026
-------------------------------------------------------------------------------

  Started : Mon Sep 12 09:19:32 2011

2011/09/12 09:19:32 ERROR 21 (0x00000015) Getting File System Type of Source d:\data\
The device is not ready.


   Source - d:\data\
     Dest : \\nas\BranchDataBackUp\XXX\data\
    Files : *.*
   
  Options : *.* /V /S /COPY:DAT /PURGE /B /NP /XO /R:1 /W:15
------------------------------------------------------------------------------

2011/09/12 09:19:32 ERROR 21 (0x00000015) Accessing Source Directory d:\data\
The device is not ready.

Waiting 15 seconds... Retrying...
2011/09/12 09:19:48 ERROR 21 (0x00000015) Accessing Source Directory d:\data\
The device is not ready.


ERROR: RETRY LIMIT EXCEEDED.

2011/09/12 09:19:48 ERROR 21 (0x00000015) Accessing Source Directory d:\data\
The device is not ready.

script:
robocopy "d:\data" "\\nas\BranchDataBackUp\xxx\data" /S /PURGE /V /XO /NP /LOG:"\\nas\BranchDataBackUp\xxxdata.txt" /B /R:1 /W:15
if errorlevel 16 (echo ***FATAL ERROR*** & goto notify)
if errorlevel 15 (echo OKCOPY + FAIL + MISMATCHES + XTRA & goto notify)
if errorlevel 14 (echo FAIL + MISMATCHES + XTRA & goto notify)
if errorlevel 13 (echo OKCOPY + FAIL + MISMATCHES & goto notify)
if errorlevel 12 (echo FAIL + MISMATCHES & goto notify)
if errorlevel 11 (echo OKCOPY + FAIL + XTRA & goto notify)
if errorlevel 10 (echo FAIL + XTRA & goto notify)
if errorlevel 9 (echo OKCOPY + FAIL & goto notify)
if errorlevel 8 (echo FAIL & goto notify)
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 good)
if errorlevel 0 (echo No Change & goto good)

:Notify
C:\WINDOWS\system32\blat -install ntexchange.domain.com BackUp
C:\WINDOWS\system32\blat \\nas\BranchDataBackUp\HUDdata.txt -subject "xxx data BackUpConcerns" -to sysmon@domain.com
Goto End

:GOOD
C:\WINDOWS\system32\blat -install ntexchange.domain.com BackUp
C:\WINDOWS\system32\blat \\nas\BranchDataBackUp\xxxdata.txt -subject "xxx data It's all good!!!" -to sysmon@domain.com
GOTO END

:End
0
 
pwustCommented:
Does it change its output if you put in the complete path and filename of your robocopy.exe?

you also can add a line
echo exit code is %errorlevel%.

Open in new window

just between the "robocopy" line and the "if" series of lines, just to see what you have just before starting the error handling.

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
GoHuskersAuthor Commented:
just to clarify. Is this what you meant?
C:\WINDOWS\system32\robocopy.exe "c:\Profiles" "\\nas\BranchDataBackUp\..................
echo exit code is %errorlevel%
if errorlevel16 (echo ***FATAL ERROR*** & goto notify)
....................
0
 
pwustCommented:
yes, confirmed
0
 
GoHuskersAuthor Commented:
well it keeps returning an exit code of 0 eventhough it gives an error code in the log.
I purposely change the source drive letter to create an error.
Is error 21 not a valid exit code to be using how I am trying?
or is there a bug in robocopy?
see below for log

error log:
2011/09/13 07:32:37 ERROR 21 (0x00000015) Accessing Source Directory d:\Profiles\
The device is not ready.

Waiting 15 seconds... Retrying...
2011/09/13 07:32:53 ERROR 21 (0x00000015) Accessing Source Directory d:\Profiles\
The device is not ready.


ERROR: RETRY LIMIT EXCEEDED.

2011/09/13 07:32:53 ERROR 21 (0x00000015) Accessing Source Directory d:\Profiles\
The device is not ready.

0
 
GoHuskersAuthor Commented:
i figured out the exit code issue.
I had to revert back to an earlier version of Robocopy  XP010
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.