SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


Sidebar

Sponsor:

Would you like to sponsor this site?
Or buy me a beer?:


Recently Changed Pages:

View All Pages
View All Q Pages


View All Tags


Sign up for Q to post comments.





WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.


Terms And Conditions for Q users


Pages with comments

PageDateDiscussionTags
2019/05/01 14:08 2 Comments
2019/03/15 16:02 1 Comment
2019/03/15 16:02 1 Comment
2019/03/15 16:02 3 Comments
2017/04/20 15:28 1 Comment
2017/04/20 15:23 1 Comment
2017/04/19 14:44 1 Comment
2017/04/17 20:10 1 Comment
2017/04/17 20:07 1 Comment
2017/04/17 19:58 1 Comment
2017/04/17 19:52 1 Comment

View All Comments

oraclerman

Script: Bash: AIX: Oracle RMAN Backup

This describes the way to handle Oracle backup and restore through rman.

#!/bin/bash
# set -x
 
### Script Variables
WHATAMI=`basename $0`
BASEDIR=`dirname $0`
 
### Oracle Variables
ORACLE_HOME=/opt/oracle/product/10.2
ORACLE_BASE=/opt/oracle
ORACLE_SID=<sid>
 
### Offsitecopy Variables
GZIP=/usr/bin/gzip
TAR=/usr/local/bin/tar
. "$BASEDIR/mail.txt"
. "$BASEDIR/offsitecopy.func"
HOSTNAME=`hostname`
HOSTNAME_SHORT=`hostname -s`
BCKROOT=/var/backup/oracle
BCKPDIR=${BCKROOT}/rman_backupdir
RMANDIR=${BCKROOT}/rman_workdir
RMANLOGDIR=${BCKROOT}/rman_logs
RMANLOGFILE=${RMANDIR}/rman_backup.log
RMANCROSSLOGFILE=${RMANDIR}/rman_crosscheck.log
BACKUPFILE="${BCKPDIR}/${HOSTNAME_SHORT}_${ORACLE_SID}-RMAN_`date +%Y%m%d%H%M`.tgz"
LOGFILE="$BCKPDIR/logfile_`date +%Y%m%d%H%M`.log"
TOUSER="syncuser"
TOHOST="syncserver.company.local"
TODIR="/srv/syncdata/Oracle/${HOSTNAME_SHORT}_${ORACLE_SID}"
DOCOPY="0"
RMANRESULT="0"
ZIPRESULT="0"
 
### Export Required Variables
export ORACLE_SID ORACLE_BASE ORACLE_HOME BCKROOT BCKPDIR RMANDIR BASEDIR
 
removeFunction() {
   echo "Removing old backup files from ${RMANDIR}"
   rm ${RMANDIR}/*
}
 
mailFunction() {
   if [ "$1" == "RMAN" ]; then
      echo "RMAN backup was not created succesfully, consult ${RMANLOGDIR}/rman_backup.log on ${HOSTNAME}" | mail -s "Failed $1 Backup" $MAILTOFAIL
   fi
   if [ "$1" == "ZIP" ]; then
      echo "Tar or zip was not created succesfully, consult ${BACKUPFILE}.log on ${HOSTNAME}" | mail -s "Failed $1 Backup" $MAILTOFAIL
   fi
   if [ "$1" == "SUCCESS" ]; then
      echo "RMAN backup was succesful, but the RMAN was not copied to the syncserver" | mail -s "RMAN Backup Succeedded, but not copied!" $MAILTOFAIL
   fi
   removeFunction
}
 
failFunction() {
   echo
   echo "RMAN Result = $RMANRESULT"
   echo "ZIP Result = $ZIPRESULT"
   echo
   if [ ! "$RMANRESULT" == "0" ]; then
      echo "RMAN backup was not created succesfully..."
      echo "Please consult `tput bold``tput smul`${RMANLOGDIR}/rman_backup.log`tput sgr0`."
      mailFunction RMAN
   fi
   if [ ! "$ZIPRESULT" == "0" ]; then
      echo "Tar or zip was not created succesfully..."
      echo "Please consult `tput bold``tput smul`${BACKUPFILE}.log`tput sgr0`"
      mailFunction ZIP
   fi
   removeFunction
   exit 1
}
 
copyFunction() {
   if [ "$ZIPRESULT" == "0" ]; then
      if [ "$DOCOPY" == "1" ]; then
         offsitecopy "${BACKUPFILE}" "$TOUSER" "$TOHOST" "$TODIR" "$LOGFILE" "$WHATAMI" "$HOSTNAME" "$MAILTOSUCCESS" "$MAILTOFAIL"
         removeFunction
      else
         echo
         echo "Copy to offsite location is not enabled."
         echo "Modify the script under Offsitecopy Variables to enable offsitecopy"
         echo
         mailFunction SUCCESS
      fi
   else
      failFunction;
   fi
}
 
zipRman() {
   if [ "$RMANRESULT" == "0" ]; then
      echo
      echo "Tar-zipping RMAN backup and logs..."
      $TAR -cf - ${RMANDIR} | $GZIP > ${BACKUPFILE}
      ZIPRESULT=$?
      copyFunction
   else
      failFunction
   fi
}
 
rmanBackup() {
   echo
   echo "Starting RMAN backup now for Oracle Database ${ORACLE_SID}..."
   echo "${ORACLE_HOME}/bin/rman target / "cmdfile=${BASEDIR}/oracle_rman_backup.cmd""
   ${ORACLE_HOME}/bin/rman target / cmdfile=\"${BASEDIR}/oracle_rman_backup.cmd\" > ${RMANLOGFILE}
   RMANRESULT=$?
   sleep 5
   mv $RMANLOGFILE $RMANLOGDIR
   zipRman
}
 
rmanCrosscheck() {
   echo
   echo "Starting RMAN crosscheck now for Oracle Database ${ORACLE_SID}..."
   echo "${ORACLE_HOME}/bin/rman target / "cmdfile=${BASEDIR}/oracle_rman_crosscheck.cmd""
   ${ORACLE_HOME}/bin/rman target / cmdfile=\"${BASEDIR}/oracle_rman_crosscheck.cmd\" > ${RMANCROSSLOGFILE}
   sleep 5
   mv $RMANCROSSLOGFILE $RMANLOGDIR
}
 
rmanCrosscheck
rmanBackup
 
echo
echo "INFO - RMAN backup finished"
echo

As you can see, there is an external reference to offsitecopy and mail.txt. Both are described in Script: Bash: Offsitecopy.

Crosscheck Commandfile

run {
crosscheck backup;
crosscheck backupset;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired backupset;
delete noprompt expired archivelog all;
delete noprompt obsolete;
}
Note: It's important to configure the RMAN setting below in the RMAN configuration so that cleanup actions do not delete valid files.
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;

This setting can be checked by the RMAN command 'show all':

bash-3.00$ rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Tue Nov 2 09:17:01 2010

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database: <sid>(DBID=71467001)

RMAN> show all;

using target database control file instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF;
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO COMPRESSED BACKUPSET;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/opt/oracle/product/10.2/dbs/snapcf_<sid>.f'; # default

RMAN> exit

Recovery Manager complete.

Backup Commandfile

run {
backup database format '/var/backup/oracle/rman_workdir/%d_%u_%s';
backup current controlfile format '/var/backup/oracle/rman_workdir/<sid>ctl_date%T%U';
sql 'alter system archive log current';
backup archivelog from time 'SYSDATE-1' format '/var/backup/oracle/rman_workdir/arch_%d_%u_%s';
}

Simple Commandfile

spool log to "/var/backup/oracle/rman_workdir/rman_backup.log"
run {
backup database format '/var/backup/oracle/rman_workdir/%d_%u_%s';
}
exit;
spool log off;
exit
You could leave a comment if you were logged in.
oraclerman.txt · Last modified: 2013/05/04 13:18 by sjoerd