wiki.getshifting.com

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

User Tools

Site Tools


start

SHIFT-WIKI - Sjoerd Hooft's InFormation Technology

This WIKI is my personal documentation blog. Please enjoy it and feel free to reach out through blue sky if you have a question, remark, improvement or observation. See below for the latest additions, or use the search or tags to browse for content.


Script: Bash: AIX: Oracle RMAN Backup

Summary: How to handle Oracle backup and restore through rman.
Date: Around 2013
Refactor: 8 March 2025: Checked links and formatting.

#!/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 Bash: Function: Offsitecopy.

→ Read more...

2025/06/01 11:59

Oracle RMAN Restore

Summary: How to work an Oracle RMAN restore.
Date: Around 2013
Refactor: 8 March 2025: Checked links and formatting.

If you've created a RMAN backup and have created a pfile backup you'll also want a way to restore this.

→ Read more...

2025/06/01 11:59

Oracle Listener Not Listening On Localhost

Summary: How to configure the Oracle Listener to listen on the short hostname.
Date: Around 2013
Refactor: 8 March 2025: Checked links and formatting.

The oracle dba-er told me there was something wrong with the network on a new AIX box. The Oracle listener didn't listen on localhost which caused the oracle enterprise manager installation to fail.

This was shown using the netstat command:

sjoerd@oraclebox:/home/sjoerd>netstat -na | grep 1521
tcp4       0      0  10.10.10.100.1521         *.*                       LISTEN
tcp4       0      0  10.10.10.100.1521         10.10.10.1.1429           ESTABLISHED
tcp4       0      0  10.10.10.100.1521         10.10.10.100.32782        ESTABLISHED
tcp4       0      0  10.10.10.100.32782        10.10.10.100.1521         ESTABLISHED
tcp4       0      0  10.10.10.100.1521         10.10.10.100.32871        ESTABLISHED

And indeed, when trying to do a 'telnet localhost 1521' we got an connection refused error.

→ Read more...

2025/06/01 11:59

Oracle Dump

Summary: How to create a dump of a Oracle database.
Date: Around 2013
Refactor: 8 March 2025: Checked links and formatting.

Normally when creating backups you should prefer a RMAN backup. However, this is not the way to go when you want to transfer a database across an operating system. So say you have an Oracle database on AIX and you want to transfer it to Windows, you should use another method, simply being a dump. I have gathered here the required commands and variables you need just for the dump. If you need a script that creates this, use RMAN backup as an example and work from there.

→ Read more...

2025/06/01 11:59

<< Newer entries | Older entries >>

This wiki has been made possible by:

start.txt · Last modified: by sjoerd