Listing 1 rman_backup script: This script performs a
full or incremental hot backup of an Oracle database using RMAN.
It is compatible with any version of Oracle that supports RMAN
#!/bin/sh
# Define where to send administrative messages
email=dba@company.com
. $HOME/oracle_env
USAGE="Usage: backup_rman <SID> <DEST> [INC_LVL]"
# Check for proper parameter usage.
if [ "$1" = "" ]
then
echo "Backup error - No \$1 parameter specified."
echo "$USAGE" 1>&2
exit 2
fi
if [ -r /etc/oratab ]
then
ORATAB=/etc/oratab
else
if [ -r /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
else
echo "Can't find any oratab file to read..."
exit 2
fi
fi
for ORACLE_SID in `grep -v "^#" $ORATAB | grep -v "^$" | cut -d: -f1`
do
# Proceed only if first field matches specified database SID
if [ "$ORACLE_SID" = "$1" ] ; then
mysid=$1
fi
done
if [ "$mysid" = "" ]
then
echo "Backup error - Invalid database specified: $1"
exit 2
fi
if [ "$2" = "" ]
then
echo "Backup error - No \$2 parameter specified."
echo "$USAGE" 1>&2
exit 2
fi
budest=$2
if [ "$budest" = "TAPE" ]
then
channel1="allocate channel c1 type 'SBT_TAPE';"
channel2="allocate channel c2 type 'SBT_TAPE';"
format="rman_%d_%t_%U"
else
channel1="allocate channel c1 type disk;"
channel2="allocate channel c2 type disk;"
format="${budest}/rman_%d_%t_%U"
fi
# Default settings
inclevel=0
# Check for valid incremental level.
if [ "$3" != "" ]
then
ucval=`echo $3 | tr '[a-z]' '[A-Z]'` # Set $3 to uppercase.
case $ucval in
0|1|2|3|4) inclevel=$3
;;
FULL) inclevel=0
;;
*) inclevel="INVALID"
;;
esac
fi
if [ $inclevel = "INVALID" ]
then
echo "Backup error - Invalid incremental backup level: $3"
echo "$USAGE" 1>&2
exit 1
fi
ORAENV_ASK=NO; export ORAENV_ASK;
ORACLE_SID=$mysid; export $ORACLE_SID;
. oraenv
now=`date '+%m/%d/%y %H:%M:%S'`
echo "********** Starting Backup for $mysid at $now **********"
case $inclevel in
0) echo "***** Full database backup ******"
;;
*) echo "***** Incremental level $inclevel backup ******"
;;
esac
# Display list of any users which may be in the database.
echo ""
echo "User processes which are in the $mysid database:"
ps $PS_OPTIONS | grep -v grep | grep oracle$mysid
# Display list of any database processes running.
echo ""
echo "Database processes which are running for the $mysid database:"
ps $PS_OPTIONS | grep -v grep | grep ora_ | grep $mysid
# Display ipcs debug information
echo ""
echo "Displaying ipcs debug information before backup:"
ipcs
if [ "$budest" != "TAPE" ]
then
echo "Displaying free space information before backup:"
df -k $budest
echo "Displaying directory listing before backup:"
ls -lt $budest
fi
# Perform the database backup
now=`date '+%m/%d/%y %H:%M:%S'`
echo ""
if [ "$inclevel" = "0" ]
then
echo "Performing full backup of database $mysid at $now." else
echo "Performing level $inclevel backup of database $mysid as $now."
fi
$ORACLE_HOME/bin/rman target / nocatalog <<EOF
run {
${channel1}
${channel2}
backup incremental level ${inclevel}
filesperset 5
tag full_backup
format
'${format}.bus' database include current controlfile;
sql 'alter system archive log current';
backup filesperset 50
archivelog all
format
'${format}.bar';
release channel c1;
release channel c2;
}
EOF
exit_status=$?
now=`date '+%m/%d/%y %H:%M:%S'`
if [ "$inclevel" = "0" ]
then
message="Full backup of database $mysid complete at $now." else
message="Incremental level $inclevel backup of $mysid complete at $now."
fi
exit_status=$?
if [ $exit_status -ne 0 ]
then
message="Backup error - Error $error_status during RMAN \
backup of $mysid"
echo $message
echo "$message" | mail -s "RMAN Error" $email
else
echo $message
fi
echo ""
echo "User processes which are in the $mysid database:"
ps $PS_OPTIONS | grep -v grep | grep oracle$mysid
echo ""
echo "Database processes which are running for the $mysid database:"
ps $PS_OPTIONS | grep -v grep | grep ora_.*_$mysid
# Display ipcs debug information
echo ""
echo "Displaying ipcs debug information after backup:"
ipcs
if [ "$budest" != "TAPE" ]
then
echo "Displaying free space information after backup:"
df -k $budest
echo "Displaying directory listing after backup:"
ls -lt $budest
fi
# Validate and list backups
echo ""
echo "Listing pieces and validating status of backups for $mysid database."
$ORACLE_HOME/bin/rman target / nocatalog <<EOF
list backup;
run {
${channel1}
${channel2}
restore database validate;
release channel c1;
release channel c2;
}
EOF
exit_status=$?
if [ $exit_status -ne 0 ]
then
message="Backup error - Error $exit_status during backup list \
and validation."
echo $message
echo "$message" | mail -s "RMAN Error" $email
fi
now=`date '+%m/%d/%y %H:%M:%S'`
echo ""
echo "Backup of database $mysid is complete at $now" |