A proper backup is the base for a well and relaxed administration of yout databases.What follows is a backup-script which I use for several customers. It’s backing up all in the same directory and I tested the restore frequently.

There’s however one drawback: I copied the script through word- or notepad apparently, so take care of the (double) quotes used in the script. You may have to re-type them.

#!/usr/bin/ksh
#
# file : /home/oracle/bin/backup.sh
# description : run rman backup to disk ……
#
# Author: Job Oprel
# Versie: 0.1
# ——-|————+——————-+———————————
# 0.1 | 11-06-2008 | Job Oprel | Initial
# 0.2 | 01-08-2008 | Job Oprel | An own oratab instead of /etc/oratab
#
#
##### Variables #######
##########################

LOGDIR=/home/oracle/log
RUNTIME=`date ‘+%H%M_%d%m%Y’`
RUNDATE=`date ‘+%d%m%Y’`
ORACLE_HOME=/software/oracle/product/10.2
ADDR='<mail-address>’
PATH=$ORACLE_HOME/bin:$PATH:/usr/local/bin
NLS_DATE_FORMAT=’DD-MM-YY HH24:MI:SS’
NODE_NAME=’node_x’
BACKUP_BASE=’/backup/oracle’
export ORACLE_HOME PATH NLS_DATE_FORMAT NODE_NAME BACKUP_BASE

# Which databases:
for ORACLE_SID in `cat /home/oracle/bin/oratab_backup | grep “:Y” | awk -F : ‘{ print $1 }’ `
do
export ORACLE_SID

# Specific settings #
#########################################

LOGFILE=${LOGDIR}/${ORACLE_SID}_${RUNDATE}_${RUNTIME}.log
BACKUPDIR=${BACKUP_BASE}/${ORACLE_SID}/rman

# Cleaning old files#
#############################

find ${LOGDIR}/${ORACLE_SID}_*.log -ctime +15 -exec rm -f {} \; > /dev/null 2>&1
find ${BACKUPDIR}/ctrlfile_${ORACLE_SID}_* -ctime +15 -exec rm -f {} \; > /dev/null 2>&1

#### Rman backup ##
##########################

exec >> ${LOGFILE} 2>&1
${ORACLE_HOME}/bin/rman msgno target / nocatalog <<EOF!
CONFIGURE RETENTION POLICY TO REDUNDANCY 2; # default 1
CONFIGURE BACKUP OPTIMIZATION OFF; # default OFF
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON; # default OFF
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘${BACKUPDIR}/ora_cf%F’; # default ‘%F’
CONFIGURE DEVICE TYPE DISK PARALLELISM 2; # default 1
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT ‘${BACKUPDIR}/ora_df%t_s%s_s%p’;
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘${BACKUPDIR}/snapcf_${ORACLE_SID}.f’;
SHOW ALL;

sql “alter system archive log current”;

DELETE FORCE NOPROMPT ARCHIVELOG ALL COMPLETED BEFORE ‘sysdate-14’;

BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL=0 DATABASE INCLUDE CURRENT CONTROLFILE PLUS ARCHIVELOG;

sql “alter database backup controlfile to trace as ”${BACKUPDIR}/ctrlfile_${ORACLE_SID}_${RUNDATE}_${RUNTIME}””;

CROSSCHECK BACKUP;
REPORT OBSOLETE;
DELETE FORCE NOPROMPT OBSOLETE;

LIST BACKUP OF DATABASE;
LIST BACKUP OF ARCHIVELOG ALL;
LIST BACKUP;

EOF!

echo “############################”
echo “# Database: ${ORACLE_SID}” >> ${LOGDIR}/mailmessage
echo “############################”

cat ${LOGFILE} >> ${LOGDIR}/mailmessage
done

grep RMAN-06273 ${LOGDIR}/mailmessage >>/dev/null

if [ $? -eq 0 ]
then
SUBJECTHEADER=”ATTENTION!: 1 or more backups of the ${NODE_NAME} has failed”
else
grep -i error ${LOGFILE} >>/dev/null
if [ $? -eq 0 ]
then
SUBJECTHEADER=”ATTENTION!: 1 or more backups of the ${NODE_NAME} has failed”
else
SUBJECTHEADER=”backup ${NODE_NAME} is OK!”
fi
fi

## Mail het resultaat ##
########################

cat ${LOGDIR}/mailmessage | /usr/bin/mailx -s “${SUBJECTHEADER}” ${ADDR}
rm ${LOGDIR}/mailmessage