dbTalk Databases Forums  

Windows Batch file for backup and verify backup-image

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Windows Batch file for backup and verify backup-image in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
John Hopfield
 
Posts: n/a

Default Windows Batch file for backup and verify backup-image - 08-23-2010 , 10:29 AM






Hi ,

How db2 return codes works into a windows batch file?
I try to explain my needs: i want to write a batch file for
-make offline backup of db2 (version 8.2,9.5)
-check the backup image file with db2ckbkp utility
-copy the backup image on a network drive with a simple copy command

if an error occurred into any of these steps i want to send a message
or write something on the screen (or send an email with the problem to
a list of users)

my problem is that i'm unable to check the return code of every
command, it seems that errorlevel variable is not working.

ps: for me is ok also to use other script languages available on
windows, if this solve the problem.

can you help me?
JH

Reply With Quote
  #2  
Old   
Luuk
 
Posts: n/a

Default Re: Windows Batch file for backup and verify backup-image - 08-23-2010 , 01:58 PM






Op 23-08-10 17:29, John Hopfield schreef:
Quote:
Hi ,

How db2 return codes works into a windows batch file?
I try to explain my needs: i want to write a batch file for
-make offline backup of db2 (version 8.2,9.5)
-check the backup image file with db2ckbkp utility
-copy the backup image on a network drive with a simple copy command

if an error occurred into any of these steps i want to send a message
or write something on the screen (or send an email with the problem to
a list of users)

my problem is that i'm unable to check the return code of every
command, it seems that errorlevel variable is not working.

Try next bacth-file, and see that errorlevel is working just fine.

@echo off
del test.txt
copy test.txt test.bak
echo The value of ERRORLEVEL after a unsuccesfull copy: %ERRORLEVEL%

dir >test.txt
copy test.txt test.bak
echo The value of ERRORLEVEL after a succesfull copy: %ERRORLEVEL%



Quote:
ps: for me is ok also to use other script languages available on
windows, if this solve the problem.

can you help me?
JH
If you dont know how to write a simple batchfile, than ...
i wont be able to help

sorry...


--
Luuk

Reply With Quote
  #3  
Old   
John Hopfield
 
Posts: n/a

Default Re: Windows Batch file for backup and verify backup-image - 08-25-2010 , 10:04 AM



On 23 Ago, 20:58, Luuk <L... (AT) invalid (DOT) lan> wrote:
Quote:
Try next bacth-file, and see that errorlevel is working just fine.

@echo off
del test.txt
copy test.txt test.bak
echo The value of ERRORLEVEL after a unsuccesfull copy: %ERRORLEVEL%

dir >test.txt
copy test.txt test.bak
echo The value of ERRORLEVEL after a succesfull copy: %ERRORLEVEL%

ps: for me is ok also to use other script languages available on
windows, if this solve the problem.

can you help me?
JH

If you dont know how to write a simple batchfile, than ...
i wont be able to help

sorry...
ok...your batch file is working, and errorlevel for a "copy" command
returns the correct value...
now: try to add a "db2 backup db xxxx........" in the same batch file
and to test the errorlevel variable when the backup fails, and tell me
if its working.
In my environment (win xp-pro + db2 express-c 9.5) the errorlevel
variable is not working for db2 commands...

JH

Reply With Quote
  #4  
Old   
cynocmam
 
Posts: n/a

Default Re: Windows Batch file for backup and verify backup-image - 08-25-2010 , 04:16 PM



On Aug 25, 11:04*am, John Hopfield <Hopfi... (AT) freemail (DOT) it> wrote:

Quote:
now: try to add a "db2 backup db xxxx........" in the same batch file
and to test the errorlevel variable when the backup fails, and tell me
if its working.
In my environment (win xp-pro + db2 express-c 9.5) the errorlevel
variable is not working for db2 commands...
Not sure why it does not work for you. db2.exe, the DB2 command line
processor, returns 4 for errors, 2 for warning, and 0 for successful
commands.

D:\>cat test\t.cmd
db2 backup db nonexistent to c:\temp
echo %errorlevel%
if errorlevel 4 echo errorlevel 4 & goto :eof
if errorlevel 2 echo errorlevel 2 & goto :eof
if errorlevel 1 echo errorlevel 1 & goto :eof
echo no error

D:\>test\t.cmd

D:\>db2 backup db nonexistent to c:\temp
SQL0104N An unexpected token "nonexistent" was found following "DB".
Expected tokens may include: "<database-alias>". SQLSTATE=42601

D:\>echo 4
4

D:\>if errorlevel 4 echo errorlevel 4 & goto :eof
errorlevel 4

Reply With Quote
  #5  
Old   
Luuk
 
Posts: n/a

Default Re: Windows Batch file for backup and verify backup-image - 08-26-2010 , 02:57 PM



Op 25-08-10 23:16, cynocmam schreef:
Quote:
On Aug 25, 11:04 am, John Hopfield<Hopfi... (AT) freemail (DOT) it> wrote:

now: try to add a "db2 backup db xxxx........" in the same batch file
and to test the errorlevel variable when the backup fails, and tell me
if its working.
In my environment (win xp-pro + db2 express-c 9.5) the errorlevel
variable is not working for db2 commands...

Not sure why it does not work for you. db2.exe, the DB2 command line
processor, returns 4 for errors, 2 for warning, and 0 for successful
commands.

D:\>cat test\t.cmd
db2 backup db nonexistent to c:\temp
echo %errorlevel%
if errorlevel 4 echo errorlevel 4& goto :eof
if errorlevel 2 echo errorlevel 2& goto :eof
if errorlevel 1 echo errorlevel 1& goto :eof
echo no error

D:\>test\t.cmd

D:\>db2 backup db nonexistent to c:\temp
SQL0104N An unexpected token "nonexistent" was found following "DB".
Expected tokens may include: "<database-alias>". SQLSTATE=42601

D:\>echo 4
4

D:\>if errorlevel 4 echo errorlevel 4& goto :eof
errorlevel 4


thanks for the answer....

i have DB2 installed on my Windows7 machine, but i did not do a backup,
so i did not check if DB2 returns correct errorlevels...

But is seems it does, like expected from IBM

--
Luuk

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.