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