Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2002
    Location
    Hamilton
    Posts
    150

    Unanswered: db2 backups and verification

    I am looking for help in creating a shell script that will back up the db to a filesystem but also will verify it, any help would be appreciated?

    thanks

    Mark

  2. #2
    Join Date
    Feb 2002
    Posts
    33
    Mark,
    When you say "backup the db to a filesystem" do you mean using the "db2 backup db <dbname>..." command or a filesystem level backup command?

    If its a database backup created via db2, you can verify by checking the list history output. This will provide details on the backup completion time or if there was a problem.

  3. #3
    Join Date
    Feb 2002
    Location
    Hamilton
    Posts
    150
    thank you this is the command that I used:

    list history backup since :timestamp" for "DB"

  4. #4
    Join Date
    Feb 2002
    Posts
    33
    Looks good! Remember that list history can also be used to track other things such as loads, runstats, reorgs etc. Just issue "db2 ? list history" for more details.

  5. #5
    Join Date
    Feb 2002
    Location
    Hamilton
    Posts
    150
    We will be using those parameters shortly as we go into production. It looks as though we will be doing some HouseKeeping type of scripts daily and log cleanup as well

  6. #6
    Join Date
    Feb 2002
    Posts
    33
    Hi. When you say log cleanup... is that transaction logs or db2diag.log?

  7. #7
    Join Date
    Feb 2002
    Location
    Hamilton
    Posts
    150
    This is a snippet of the housekeeping script that we have:

    # Process DB2 Maintanence Command Request

    case "$1" in

    db2archivelogclean )

    #
    # Clean up DB2 archive logs stored in TSM
    #

    # We need to query the logs and delete old logs.
    # This is done by querying the last log from last backup.
    # There is a risk here. The assumption is that the backups are listed
    # in chronological order (which has been true so far.)
    # We need to subtract 1 from the oldest log file to keep the last backup valid.
    #
    let OLDEST_LOG=$($DB2HOME/adsm/db2adutl query full db $2 | tail -2 | awk '{print $3}' | cut -c2-8)
    let OLDEST_LOG=$OLDEST_LOG-1
    OLD_LOG=$(printf "%-7.7d" $OLDEST_LOG)
    OLD_LOG="S$OLD_LOG.LOG"
    # Now delete the oldest logs
    #
    $DB2HOME/adsm/db2adutl delete logs between S0000000.LOG and $OLD_LOG db $2 without prompting >$DB2MAINTOUT 2>&1

    RC=$?

    ;;

    db2backupclean )

    #
    # Clean up DB2 backup images stored in TSM
    #

    $DB2HOME/adsm/db2adutl delete full older than $BACKUP2KEEP days db $2 without prompting >$DB2MAINTOUT 2>&1

    RC=$?

    ;;

    db2diaglogclean )

    #
    # Clean up DB2 diagnostics log. Rename it and clean up any old ones.
    #
    mv $DB2HOME/db2dump/db2diag.log $DB2HOME/db2dump/db2diag.log.$CURDATE > $DB2MAINTOUT 2>&1
    /usr/bin/find $DB2HOME/db2dump -name db2diag.log* -mtime +$DIAGFILES2KEEP exec /usr/bin/rm -f {} \;

    RC=$?

    ;;

    * )
    print "Usage: $0 db2archivelogclean|db2backupclean|db2diaglogclean DBNAME"
    logger -p alert "DB2_MAINT_ALERT: DB2 Maintanence Cannot Run .. Incorrect Parameter $1"
    exit 1
    esac

    if [ $RC -eq 0 ]; then

    logger -p info "DB2_MAINT_INFO: Successful Execution Of $1"
    print "DB2_MAINT_INFO: Successful Execution Of $1"

  8. #8
    Join Date
    Feb 2002
    Posts
    33
    # We need to query the logs and delete old logs.
    # This is done by querying the last log from last backup.
    # There is a risk here. The assumption is that the backups are listed
    # in chronological order (which has been true so far.)
    # We need to subtract 1 from the oldest log file to keep the last backup valid.



    List history does put them in chronological order. You might want to check up on the History Retention and Number History records parameters to make sure they/the script agree with each other.
    Raj

  9. #9
    Join Date
    Jan 2003
    Location
    Arizona
    Posts
    7

    REORG not in History File

    Is there any way a reorg could be run without the information showing up in the History file. The operator at one of our sites told me that the last reorg they ran was on 12/02/2002. However when I do a 'List History REORG ALL' for the database it shows the last reorg was run on 10/31/2002. There doesn't appear to be any problem with the history file (space) as there are other messages for backups after 12/02. Is it most likely that the operator is wrong? This happened one other time, which is why I am curious. Thanks for your replies.

  10. #10
    Join Date
    Jun 2008
    Posts
    1
    Hello,

    I was searching for a script that can delete archive logs from TSM backup - but not from the oldest one (S0000000.LOG) but from the oldest one existing in TSM backup. Since I couldn't find it - I wrote it ;-) It works on AIX 5.3 with DB2 V9.5.

    Here it is:

    Code:
    #!/bin/ksh
    #set -x
    
    DB=DD1
    DAYS_KEEP_FULL=30
    DATA=$(date)
    
    echo -------- Backup and Archive Log Deleting from TSM -------
    echo --- $DATA
    echo --- DB: $DB
    echo --- Copyright Kornel Karwasiński 2008 :-)
    echo ---------------------------------------------------------
    
    # ------------------------------------------------------
    # Deleting backups older than $DAYS_KEEP_FULL days
    # ------------------------------------------------------
    
    db2adutl delete full older than $DAYS_KEEP_FULL days db $DB without prompting
    
    # ----------------------------------------------------------
    # Geting the name of a last valid log from TSM backup
    # ----------------------------------------------------------
    OLDEST_VALID_LOG=$(db2adutl query full db $DB | grep Time: | tail -n1 | awk '{ print $6 }')
    echo Oldest valid log:  $OLDEST_VALID_LOG
    
    # ------------------------------------------------------------
    # Geting the name of an oldest log from TSM backup
    # ------------------------------------------------------------
    OLDEST_LOG=$(db2adutl query logs db $DB | grep file: | head -1 | awk '{ print $3 }' | tr -d ",")
    echo Oldest log in TSM:  $OLDEST_LOG
    
    if [ "$OLDEST_LOG" = "$OLDEST_VALID_LOG" ]
     then
             echo --------------------------------------------------
             echo -------- There are no logs to delete ---------------
             echo --------------------------------------------------
          exit 0
    
     else
    
             # ---------------------------------------------
             # Geting the newest log to be deleted
             # ---------------------------------------------
    
             NEWEST_INVALID_LOG=$( echo $OLDEST_VALID_LOG | tr -d "S" | tr -d ".LOG" )
             NEWEST_INVALID_LOG=$( expr $NEWEST_INVALID_LOG - 1)
             NEWEST_INVALID_LOG=$( printf "%-7.7d" $NEWEST_INVALID_LOG)
             NEWEST_INVALID_LOG=S$NEWEST_INVALID_LOG.LOG
    
    
             echo Newest invalid log: $NEWEST_INVALID_LOG
             echo Oldest invalid log: $OLDEST_LOG
    
             # ----------------------------------
             # Deleting invalid logs
             # ----------------------------------
    
             db2adutl delete logs between  $OLDEST_LOG and $NEWEST_INVALID_LOG db $DB without prompting
     fi
    
    exit 0
    And that's it. Hope it helps.

    Regards, Kornel.
    Last edited by kornel_k; 06-05-08 at 05:21.

Posting Permissions

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