Cold database backup in RAC environment

We can use following routine to perform a cold backup in RAC environment.

#!/bin/sh
# $Header: cold_database_backup.sh,v 1.0 2008/04/24 00:00:00 $
#

# —————————————————————————
# Determine the user which is executing this script.
# —————————————————————————

CUSER=`id cut -d”(” -f2 cut -d “)” -f1`

# —————————————————————————
# Log output file
# Note: output directory requires write permission.
# —————————————————————————

RMAN_LOG_FILE=/database_backup/log/testdb_cldbkp.out

# —————————————————————————
# Delete Old backup log file
# —————————————————————————

if [ -f “$RMAN_LOG_FILE” ]
then
rm -f “$RMAN_LOG_FILE”
fi

# —————————————————————–
# Initialize the log file.
# —————————————————————–

echo >> $RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE

# —————————————————————————
# Log the start of this script.
# —————————————————————————

echo Script $0 >> $RMAN_LOG_FILE
echo ==== started on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE

ORACLE_HOME=/u01/app/oracle/product/10.2.0; export ORACLE_HOME
ORACLE_SID=TESTDB2; export ORACLE_SID
ORACLE_USER=oracle
TARGET_CONNECT_STR=sys/manager
CMD=”$ORACLE_HOME/bin/sqlplus /nolog”
RMAN=$ORACLE_HOME/bin/rman
NLS_DATE_FORMAT=dd-MON-YYYY:hh24:mi:ss; export NLS_DATE_FORMAT
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1; export NLS_LANG

# —————————————————————————
# Print out the value of the variables set by this script.
# —————————————————————————

echo >> $RMAN_LOG_FILE
echo “RMAN: $RMAN” >> $RMAN_LOG_FILE
echo “CMD: $CMD” >> $RMAN_LOG_FILE
echo “ORACLE_SID: $ORACLE_SID” >> $RMAN_LOG_FILE
echo “ORACLE_USER: $ORACLE_USER” >> $RMAN_LOG_FILE
echo “ORACLE_HOME: $ORACLE_HOME” >> $RMAN_LOG_FILE
echo “NLS_DATE_FORMAT: $NLS_DATE_FORMAT” >> $RMAN_LOG_FILE
echo “NLS_LANG: $NLS_LANG” >> $RMAN_LOG_FILE

# —————————————————————————
# Stop and mount the database for cold backup
# —————————————————————————

$ORACLE_HOME/bin/srvctl stop database -d TESTDB
$ORACLE_HOME/bin/srvctl start database -d TESTDB -o mount

# —————————————————————————
# Script for database backup
# —————————————————————————

CMD_STR=”
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
$RMAN target=$TARGET_CONNECT_STR nocatalog log=$RMAN_LOG_FILE append << EOF
RUN {
ALLOCATE CHANNEL ch00 TYPE DISK;
ALLOCATE CHANNEL ch01 TYPE DISK;
BACKUP
FORMAT ‘bk_u%u_s%s_p%p_t%t’
DATABASE;
RELEASE CHANNEL ch00;
RELEASE CHANNEL ch01;
}
EOF

echo $CMD_STR

# —————————————————————————
# Initiate the command string
# —————————————————————————

if [ “$CUSER” = “root” ]
then
su – $ORACLE_USER -c “$CMD_STR” >> $RMAN_LOG_FILE
RSTAT=$?
else
/usr/bin/sh -c “$CMD_STR” >> $RMAN_LOG_FILE
RSTAT=$?
fi

# —————————————————————————
# Log the completion of this script.
# —————————————————————————

if [ “$RSTAT” = “0” ]
then
LOGMSG=”ended successfully”
else
LOGMSG=”ended in error”
fi

echo >> $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE

# —————————————————————————
# Stop and start the database after cold backup
# This step is required, as $ORACLE_HOME/bin/srvctl start database -d TESTDB -o open
# does not open the database, if it is already mounted
# —————————————————————————

$ORACLE_HOME/bin/srvctl stop database -d TESTDB
$ORACLE_HOME/bin/srvctl start database -d TESTDB

# —————————————————————————
# Start the services based on database
# —————————————————————————

$ORACLE_HOME/bin/srvctl start service -s MSOG -d TESTDB -i TESTDB1
$ORACLE_HOME/bin/srvctl start service -s MSOG -d TESTDB -i TESTDB2
$ORACLE_HOME/bin/srvctl start service -s MSOG -d TESTDB -i TESTDB3

exit $RSTAT

Advertisements
This entry was posted in Oracle Database Backup, Oracle Recovery Manager and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s