db2 offline backup shell

来源:互联网 发布:传奇霸业数据汇总 编辑:程序博客网 时间:2024/05/01 19:59

#!/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

 

if [ `db2 list applications | grep -vc SQL1611W` -gt 0 ]

then

   log_message "Active applications found! Terminating in 30 seconds";

   sleep 30

   db2 force applications all >> $LOG 2>&1

   # allow another 30 seconds for the applications to disconnect.

   sleep 30

fi

 

# Connect to database

log_message "Connecting to database $DBNAME"

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

 

# Quiesce the database

log_message "Quiescing database $DBNAME"

db2 quiesce database immediate force connections >> $LOG 2>&1

 

 

# Close the current connection

log_message "Disconnecting from database $DBNAME"

db2 connect reset >> $LOG 2>&1

 

# Wait few seconds

sleep 30

 

# Take Backup

log_message "Backing up database....This will take a while";

db2 backup database $DBNAME to $BACKUPDIR compress without prompting >> $LOG 2>&1

 

# Unquiesce

log_message "Backup complete..Return code is $?";

 

# Connect to database

log_message "Connecting to database $DBNAME"

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

 

log_message "Unquiescing database $DBNAME";

db2 unquiesce database >> $LOG 2>&1

 

 

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

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

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

原创粉丝点击