Hot Backup using RMAN
oracle@eu1pdbu006:/home/oracle $cat /home/oracle/scripts/backup/ hotback_rman.ksh
#!/bin/ksh
# Hot Backup using RMAN
# APDBA DBA Team - Aug. 01, 2011
# Must be run by user belonging to DBA group
# 3 parameters are passsed to the script:
# 1. User name
# 2. SID of the database
# 3. Days to keep archived logs (defaults to 1 if not set)
# Example: hotback_rman.sh oracle PROD 2
# Created : HV - Aug. 01, 2011
. $HOME/.profile
USR=$1
ORACLE_SID=$2
DAYS_KEEP_ARCHLOGS=$3
EGREP=/usr/bin/egrep
DBA_EMAIL="apdba@ blog.com,apdba_blog@ blog.com"
echo "============================= ============================== ==================="
echo "---ORACLE ONLINE BACKUP PROCESS FOR $ORACLE_SID STARTED AT:"
echo " `date`"
# Checking parameters passed to the script
if [[ $# -lt 2 || $# -ge 4 ]]; then
echo "---ERROR: Wrong number of parameters have been passed to the script"
echo "---Backup aborted !!!"
exit 1
fi
ls /home | $EGREP $USR > /dev/null
if [[ $? != 0 ]]; then
echo "---ERROR: Parameter '$USR' is not a valid user.......................... ......."
echo "---Backup aborted !!!"
exit 2
fi
ps -ef | $EGREP ora_arc0_$ORACLE_SID | $EGREP -v egrep > /dev/null
if [[ $? != 0 ]]; then
echo "---ERROR: Parameter '$ORACLE_SID' is not a valid ORACLE SID or not in archived log mode."
echo "---Backup aborted !!!"
exit 3
fi
if [[ $# -eq 2 ]]; then
DAYS_KEEP_ARCHLOGS=1
fi
[[ $DAYS_KEEP_ARCHLOGS = +([0-9]) ]]
if [[ $? != 0 ]]; then
echo "---ERROR: Parameter '$DAYS_KEEP_ARCHLOGS' is not a valid number of retention days............."
echo "---Backup aborted !!!"
exit 4
fi
BACKUP_DEST=/backup/$ORACLE_ SID/hotbackup
if [ ! -d $BACKUP_DEST ]; then
mkdir -p $BACKUP_DEST
fi
SCRIPTS_DIR=/home/$USR/ scripts/backup/rman
if [ ! -d $SCRIPTS_DEST ]; then
echo "---ERROR: Hotbackup setup is not correct ........... "
echo "---Backup aborted !!!"
exit 5
fi
RMAN_FILE_1=$SCRIPTS_DIR/rman_ hot_backup.rcv
RMAN_FILE_2=$SCRIPTS_DIR/rman_ list.rcv
RMAN_FILE_3=$SCRIPTS_DIR/rman_ obsolete.rcv
RMAN_FILE_4=$SCRIPTS_DIR/rman_ unrecoverable.rcv
LOG_DEST=/home/$USR/logs/ backup/$ORACLE_SID
if [ ! -d $LOG_DEST ]; then
mkdir -p $LOG_DEST
fi
RMAN_LOG_1=$BACKUP_DEST/rman_$ ORACLE_SID.log
RMAN_LOG_2=$BACKUP_DEST/list_$ ORACLE_SID.txt.`date +%Y%m%d`
RMAN_LOG_3=$BACKUP_DEST/ obsolete_$ORACLE_SID.txt.`date +%Y%m%d`
RMAN_LOG_4=$BACKUP_DEST/ unrecoverable_$ORACLE_SID.txt. `date +%Y%m%d`
### Should be uncommented if multiple databases are on same server.
# if [[ -f $HOME/.profile${ORACLE_SID} ]]; then
# . $HOME/.profile${ORACLE_SID}
# fi
# ****************************** ****************************** **********
# Variables for creating Rman and Sql scripts for redirected restore
# ****************************** ****************************** **********
SQL_DIR=$SCRIPTS_DIR/sql
SQL_FILE_1=$SQL_DIR/generate_ rman_restore_redirect.sql
SQL_FILE_2=$SQL_DIR/generate_ sql_rename_logs.sql
SQL_FILE_3=$SQL_DIR/generate_ sql_rename_temp.sql
SQL_FILE_4=$SQL_DIR/backup_ control_file.sql
SQL_LOG_1=$BACKUP_DEST/rman_ restore_redirect_$ORACLE_SID. rcv.`date +%Y%m%d`
SQL_LOG_2=$BACKUP_DEST/rename_ logs_$ORACLE_SID.sql.`date +%Y%m%d`
SQL_LOG_3=$BACKUP_DEST/rename_ temp_$ORACLE_SID.sql.`date +%Y%m%d`
# ****************************** ****************************** **********
# Variables for creating Rman script for deleting old archived logs
# ****************************** ****************************** **********
SQL_ARCH=$SQL_DIR/generate_ delete_arch_logs.sql
RMAN_ARCH=$SCRIPTS_DIR/rman_ delete_arch_logs_$ORACLE_SID. rcv
RMAN_ARCH_LOG=$LOG_DEST/rman_ delete_arch_logs_$ORACLE_SID. log
echo "---Generating a script for archived logs deletion...................... ........"
sqlplus -s /nolog @$SQL_ARCH $RMAN_ARCH $DAYS_KEEP_ARCHLOGS 2>&1 > /dev/null
if [[ $? != 0 ]]; then
echo "\n---!!!---ERROR while Generating a script for archived logs deletion..."
echo "---!!!---Backup aborted....................... ........................"
exit 3
else
echo "---Script for archived logs deletion successfully created......................"
fi
echo "---Deleting files older than 1 day .............................. ............"
if [ -a $BACKUP_DEST/* ]; then
rm $BACKUP_DEST/*
fi
echo "---Backing up database with RMAN command....................... ................"
rman target=/ nocatalog cmdfile=$RMAN_FILE_1 msglog=$RMAN_LOG_1
if [[ $? != 0 ]]; then
echo "\n---!!!---ERROR: RMAN backup command FAILED........................ ..........."
echo "---!!!---Backup aborted....................... ........................"
mailx -s "$ORACLE_SID on $(uname -n): Hot backup failed" $DBA_EMAIL < /dev/null
exit 5
fi
# ****************************** ****************************** **********
# Check if backup was successful
# ****************************** ****************************** **********
$EGREP -i "ERROR MESSAGE" $RMAN_LOG_1 2>&1 > /dev/null
if [[ $? = 0 ]]; then
echo "\n---!!!---ERROR detected:"
echo "\n---See error in the log:\n`$RMAN_LOG_1`"
echo "---!!!!---Backup aborted....................... ........................"
mailx -s "$ORACLE_SID on $(uname -n): Hot backup failed" $DBA_EMAIL < /dev/null
exit 6
else
echo "\n---Backup successfully completed at:"
echo " `date`"
fi
# ****************************** ****************************** **********
# If backup was successful, perform post backup tasks
# ****************************** ****************************** **********
echo "---Deleting old archived logs.......................... ........................"
#rman target=/ nocatalog cmdfile=$RMAN_ARCH msglog=$RMAN_ARCH_LOG
echo "\n---Creating lists and reports in: $BACKUP_DEST"
#rman target=/ nocatalog cmdfile=$RMAN_FILE_2 msglog=$RMAN_LOG_2
#rman target=/ nocatalog cmdfile=$RMAN_FILE_3 msglog=$RMAN_LOG_3
#rman target=/ nocatalog cmdfile=$RMAN_FILE_4 msglog=$RMAN_LOG_4
echo "\n---Creating RMAN and SQL scripts to use for redirected restore................."
# sqlplus -s /nolog @$SQL_FILE_1 $SQL_LOG_1 > /dev/null
# sqlplus -s /nolog @$SQL_FILE_2 $SQL_LOG_2 > /dev/null
# sqlplus -s /nolog @$SQL_FILE_3 $SQL_LOG_3 > /dev/null
echo "---Backing up control file.......................... ..........................."
sqlplus -s /nolog @$SQL_FILE_4 $BACKUP_DEST/control${ORACLE_ SID}.`date +%Y%m%d` > /dev/null
echo "---Backing up INIT file(s)....................... .............................. "
if [ -a $ORACLE_HOME/dbs/spfile$ ORACLE_SID.ora ]; then
cp $ORACLE_HOME/dbs/spfile$ ORACLE_SID.ora $BACKUP_DEST/spfile$ORACLE_ SID.ora
fi
if [ -a $ORACLE_HOME/dbs/init$ORACLE_ SID.ora ]; then
cp $ORACLE_HOME/dbs/init$ORACLE_ SID.ora $BACKUP_DEST/init$ORACLE_SID. ora
fi
echo "---Backing up Password file.......................... ..........................."
if [ -a $ORACLE_HOME/dbs/orapw$ORACLE_ SID ]; then
cp $ORACLE_HOME/dbs/orapw$ORACLE_ SID $BACKUP_DEST/orapw$ORACLE_SID
fi
uuencode $RMAN_LOG_1 $RMAN_LOG_1 | mailx -s "$ORACLE_SID on $(uname -n): Hot backup completed successfully ... " $DBA_EMAIL
echo "---ORACLE ONLINE BACKUP PROCESS FOR $ORACLE_SID FINISHED AT:"
echo " `date`"
oracle@apdba006:/home/oracle $
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment
Note: only a member of this blog may post a comment.