Solved

robocopy errorlevel script not working

Posted on 2011-09-09
7
3,109 Views
Last Modified: 2012-05-12

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
0
Comment
Question by:GoHuskers
  • 4
  • 3
7 Comments
 
LVL 8

Accepted Solution

by:
pwust earned 500 total points
ID: 36513462
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
 

Author Comment

by:GoHuskers
ID: 36523110
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
 
LVL 8

Expert Comment

by:pwust
ID: 36525548
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:GoHuskers
ID: 36525641
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
 
LVL 8

Expert Comment

by:pwust
ID: 36525897
yes, confirmed
0
 

Author Comment

by:GoHuskers
ID: 36529121
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
 

Author Comment

by:GoHuskers
ID: 36529659
i figured out the exit code issue.
I had to revert back to an earlier version of Robocopy  XP010
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Are you looking to recover an email message or a contact you just deleted mistakenly? Or you are searching for a contact that you erased from your MS Outlook ‘Contacts’ folder and now realized that it was important.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now