Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2009
    Posts
    43

    Unanswered: Return codes from backup command

    AIX - DB2 v9

    I have inherited a script that does online backups to TSM for our DB2 databases.

    Code:
        db2 backup db ${DB} online use TSM
        ret=$?
        if [ ${ret} != 0 ]; then
            exit 2
        fi
    Which sometimes returns this:

    Code:
    db2_online_maint[28] db2 backup db dp2 online use TSM
    
    Backup successful. The timestamp for this backup image is : 20101111233051
    
    SQL2425W  The log file for the online backup was not truncated.
    db2_online_maint[29] ret=2
    db2_online_maint[30] [ 2 != 0 ]
    db2_online_maint[31] exit 2
    According to SQL2425W explanation I don't have to do anything.

    The script however currently sees this as an error, and I would like to catch this particular message and not let the script exit 2 in the if statement.

    This line, db2_online_maint[29] ret=2 is catching 2 from the db2 online backup (it would be 0 if there were no messages) but I don't know if it is returning 2 just for SQL2425W or it returns 2 for a number of different messages of a similar nature / warning level, some of which I may want to act upon and some I don't.

    So, I'm not sure I want to change the script to ignore any messages that return the value 2. It would help if I knew what messages that get returned from db2 backup command map to what numeric values.

    E.g.

    no message - 0
    SQL2425W - 2

    etc.

    Thank you for taking the time to have a look.

  2. #2
    Join Date
    Jan 2010
    Posts
    335
    Hmm,

    i'ld do it like this

    MSG=$(db2 backup db dp2 online use TSM)
    echo $MSG
    echo $MSG | grep "Backup successful" > /dev/null
    if [ $? != 0 ]; then
    exit 2
    fi
    exit 0

  3. #3
    Join Date
    Dec 2009
    Posts
    43
    Yes! I like that. That is just the sort of thing that will fix this. I am going to give that a go on one of our dev environments.

    Thank you for showing me some scripting in a DB2 forum!


  4. #4
    Join Date
    Nov 2005
    Location
    IL
    Posts
    557
    When you check for !=0 you are not only picking up errors, you are also picking up warning msg's. To avoid picking warning msg's add a check for !=2 2 is a warning msg
    --
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows

    DB2 v9.7.0.6 os 6.1.0.0

  5. #5
    Join Date
    Dec 2009
    Posts
    43
    Quote Originally Posted by Cougar8000 View Post
    When you check for !=0 you are not only picking up errors, you are also picking up warning msg's. To avoid picking warning msg's add a check for !=2 2 is a warning msg
    I changed the script to do this in the end. I tried the MSG option but for some reason the syntax wouldn't work on our server. I won't forget it though, there are plenty of other maintenance scripts that could use some polish!

    Thank you both for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •