DB2 log file archiving script db2uext2's bashshell Implements user exit USEREXIT

Source: Internet
Author: User

I haven't sent any text for a long time. Send one!

See the official documentation: http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp? Topic=%2Fcom.ibm.db2.luw.admin.ha.doc%2Fdoc%2Fc0024701.html

Use the user exit program to automatically archive and retrieve log files

By creating DB2? The database manager calls the user exit program to perform archiving or retrieval operations, and can automatically perform log file archiving and retrieval.

When the DB2 database manager calls the user exit program, it performs the following operations:

  • The database manager gives control to the user's exit program;

  • The Database Manager passes the parameters to the user exit program.

  • Upon completion, the user exit program sends the return code back to the Database Manager.


    The DB2 system itself carries the C language and is complex. However, it cannot be compiled. After studying the parameters, I tried to write a simple bash shell script.

    Copy the script db2uext2 to the/home/db2inst1/sqllib/bin/directory under root.

    And modify the permission. I don't know if it can be used without modification. Change it anyway.

    Chown bin: bin db2uext2

    Chmod 755 db2uext2

    Then modify the Database Configuration

    Db2 get db cfg for DBNAME | grep LOGARCH

    Db2 update db cfg for DBNAME using LOGARCHMETH1 USEREXIT

    Then restart the database to take effect.


    Currently, the ARCHIVE function is only implemented, and the Restoration function is not implemented. You can restore the database by specifying the Log Path.


    Content of the db2uext2 script file

    #!/bin/bash#db2uext2 -OSLinux -RLSQL07020 -RQARCHIVE -DBDBNAME -NN0 -LP/data/archlog/ -LNS0000123.LOG#copy archived log file to remote host, do not delete local log file!!!#do not delete local log file!!!RHOST=192.168.0.180RROOT=/data/backup/LROOT=/data/archlog/DIR=/opt/admin/db2LOG=$DIR/log/archive-log.logRQ=""DB=""LP=""LN=""for arg in "$@"do    opt=${arg:1:2}    val=${arg:3}    if   [ "$opt" = "RQ" ]; then        RQ="$val"    elif [ "$opt" = "DB" ]; then        DB="$val"    elif [ "$opt" = "LP" ]; then        LP="$val"    elif [ "$opt" = "LN" ]; then        LN="$val"    fidonenow=`date +'%Y-%m-%d %H:%M:%S'`today=`date +%Y-%m-%d`LPATH=$LROOT$DB/archlog/LFILE=$LPATH$LNif [ "$RQ" = "ARCHIVE" ]; then    if [ ! -d $LPATH ]; then        echo create local archive log path $LPATH        mkdir -p $LPATH >> $LOG    fi    scp $LP$LN $LPATH  >> $LOG    RPATH=$RROOT$DB/$today/archlog    message="$now move $LFILE -> $RHOST:$RPATH"    ssh $RHOST mkdir -p $RPATH >> $LOG    rsync -q -auPv $LFILE $RHOST:$RPATH >> $LOG    rm $LFILE    #echo $message    echo $message >> $LOGelse    echo RESTOREfi


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.