cancel
Showing results for 
Search instead for 
Did you mean: 

Job runs despite pre-command failure

Francis_Favorin
Level 4
Hi,

I am running Backup Exec 10.0.5520 with SP1 and Hotfixes 15 and 17 on Windows 2000 SP4. I have a job with a simple pre-command batch file. Even if the batch file doesn't return 0, the job still runs. The job has the following settings:

Pre-command: D:\archive.bat
Allow pre- and post-commands to be successful only if completed with a return code of zero = checked
Run job only if pre-command is successful = checked
Cancel command if not completed within 30 minutes
Run these commands = On this media server

Contents of D:\archive.bat
---cut here---
exit /b 1
---cut here---

This batch file always returns ERRORLEVEL 1 as shown here:

D:\>D:\archive.bat
D:\>exit /b 1
D:\>if errorlevel 1 echo %errorlevel%
1
D:\>

I see in the job log that the batch file is being run. It gives no indication of the return code. Here is an excerpt from the job log:
---
Starting Pre Job Command < D:\archive.bat >
Server - BACKUP
Set Information - D: Data
Backup Set Information
Family Name: "A1 Test"
Backup of "D: Data"
Backup set #7 on storage media #1
Backup set description: "A1 Test Simple"
Backup Type: Full - Back Up Files - Reset Archive Bit

Backup started on 10/21/2005 at 4:35:12 PM.
Backup completed on 10/21/2005 at 4:35:27 PM.
Backup Set Summary
Backed up 1 file in 2 directories.
Processed 684 bytes in 15 seconds.
Throughput rate: 0.002 MB/min
---

Why is this not working the way it is supposed to?

-Francis
10 REPLIES 10

Francis_Favorin
Level 4
Does anyone out there use this functionality? Does it work?

Frank_Reichstei
Not applicable
I use Post-command in 10.1 for unlock Library and it works.

Greetings
Frank

Simon_Armstrong
Level 6
Hehe nice try, however there's a flaw in your plan. Your pre job runs, sets the errorlevel to 1, however the bat file completes successfully, therefore Backup Exec changes the errorlevel back to 0 and continues with the backup Try the following:

Batch file for the Pre-command:
set errorlevel=1
echo %errorlevel% > C:\Temp\tes1t.txt

Batch file for the Post-command:
echo %errorlevel% > C:\Temp\test2.txt

Results:
test1.txt = 1
test2.txt = 0

Francis_Favorin
Level 4
That explanation doesn't make any sense to me. There is only one way to have a return code for a batch file, and that is to cause the ERRORLEVEL to be set to some value. Based on the Backup Exec options I have set, the definition of a "successful" batch file execution is returning an ERRORLEVEL of 0. My batch file does not return 0. Therefore it has failed. I don't know how else Backup Exec could determine that a batch file succeeded anyway, unless it doesn't finish in the allotted time (or crashes, which is unlikely).

Your example is flawed, by the way. Calling "set errorlevel=1" is not the same as having ERRORLEVEL set to 1. All you did is create an environment variable called "errorlevel", which is entirely separate from the implicit variable ERRORLEVEL. (Note that I am not saying that uppercase vs. lowercase matters. I am just doing that for clarity.) Run the test that I did above, i.e., run my batch file and then execute "if errorlevel 1 @echo yes" at the command line. It will echo "yes". Now run your example pre-command batch file (with "set errorlevel=1" in it) and then execute "if errorlevel 1 @echo yes" at the command line. It will not echo anything.

Furthermore, the pre- and post-command batch files are almost certainly launched in separate processes, so there would be no preservation of ERRORLEVEL between them. In any case, Backup Exec just needs to check the ERRORLEVEL as returned by the batch file and then if it isn't 0, fail the backup job. This is they way it is documented, and it doesn't work that way.

Francis_Favorin
Level 4
Frank, I am not having a problem with the command running (it does), but Backup Exec does not detect that the pre-command failed and therefore does not fail the backup job, like it should.

Does anyone have an example of a pre-command batch file which, when it fails, causes Backup Exec to then fail the backup job (i.e., behave as documented)?

Simon_Armstrong
Level 6
Francis, yep my bad :(

However you've seemed to come across a good point.

So it looks like if the batch file completes backup exec will set the errorlevel to 0, even if the batch script actually returns an error code.

For the record I have had the pre batch script fail and the backup job fails as well. The script was to shutdown SAP and oracle on a cluster before a cold backup. However the backup did fail as the script did not complete in time (timed out).

Hhmm, it's very interesting what you've discovered, I've never actually come across this with backup exec before. I'll keep on looking into this.

Simon_Armstrong
Level 6
I was playing around a little and found the following command fails the backup job if it's in the pre command.

batch file for pre:
color 77

Since you cannot set the background and foreground to the same colour it sets the errorlevel to 1. It's weird that the backup is canceled with this but it doesn't with the exit /b command.

Simon_Armstrong
Level 6
I've been testing the "exit /b 1" command (in a batch file) on my home pc (win xp), I just tried it here at work on a win 2003 server and it works, the backup cancels as the pre command "returned an error".

Francis_Favorin
Level 4
Interesting. I am running Backup Exec on Win2000 Server SP4. When I run the batch file with "exit /b 1" at the command line on Win2000, it does correctly set the errorlevel. I wonder if the way BE creates processes or checks their return codes is different on different OS's.

Simon_Armstrong
Level 6
Yeah you might be right. I just ran the same test backup on a Win 2000 server, and guess what happened..... the pre job was successful, so it didn't recognise the errorlevel. Looks like there's an issue here with different OS. I might call Veritas (Symantec) about it tomorrow to see if they are aware of it. Have you searched the knowledge base yet? I haven't, I might do that later on.