现在的位置: 首页 > 综合 > 正文

db2 online backup shell

2018年01月16日 ⁄ 综合 ⁄ 共 1842字 ⁄ 字号 评论关闭

#!/bin/sh

usage()

{

    echo "usage: $0 <DatabaseName>"

    exit 1;

}

 

log_message()

{

    message=$1

    timestamp=`date "+%m/%d/%Y %H:%M:%S"`

    echo "$timestamp $message" >> $LOG

}

 

# Database name is the first argument.

if [ $# -eq 0 ]

then

    usage

fi

 

# Set DB2 environment

. $HOME/sqllib/db2profile

 

DBNAME=$1

BACKUPDIR=/home/db2inst1/db2backup

LOG=/home/db2inst1/db2backup/db2backup.log

 

log_message "*********************************************************************************************************";

log_message "********************************Begin********************************************************************";

log_message "*********************************************************************************************************";

# Make sure there are no active applications

 

NUM=`db2 get db cfg for $DBNAME | grep '(LOGRETAIN) = RECOVERY' | wc -l`

if [ $NUM -ne "1" ]

then

   log_message "The value of LOGRETAIN is 'OFF'. Terminate 30 seconds for changing it's value to 'RECOVERY'"

   db2 update db cfg for $DBNAME using LOGRETAINON  >> $LOG 2>&1

   sleep 30

fi

 

NUM=`db2 get db cfg for $DBNAME | grep 'TRACKMOD = ON' | wc -l`

 

if [ $NUM -ne "1" ]

then

            log_message "The value of TRACKMOD is 'OFF'. Terminate 30 seconds for changing it's value to 'ON'"

            db2 update db cfg for $DBNAME using TRACKMODON

            sleep 30

fi

 

# Connect to database

log_message "Connecting to database $DBNAME"

db2 connect to $DBNAME >> $LOG 2>&1

 

# Take Backup

log_message "Backing up database to $LOG (online incremental)....This will take a while";

db2 backup database $DBNAME online incremental to $BACKUPDIR compress include logs without prompting >> $LOG 2>&1

 

 

log_message "*********************************************************************************************************";

log_message "********************************End**********************************************************************";

log_message "*********************************************************************************************************";

抱歉!评论已关闭.