SHIFT-WIKI

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

User Tools

Site Tools


pfilebackup

Script: Bash: PFILE Backup

You need a pfile when restoring the Oracle RMAN Backup.

#!/bin/bash
# set -x
 
### Script Variables
WHATAMI=`basename $0`
BASEDIR=`dirname $0`
 
### Oracle Variables
export ORACLE_SID=<oraclesid>
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/10.2
 
 
### Offsitecopy Variables
. "$BASEDIR/mail.txt"
. "$BASEDIR/offsitecopy.func2"
BACKUPDIR=/var/backup/oracle/pfile
HOSTNAME=`hostname`
HOSTNAME_SHORT=`hostname -s`
LOGFILE="$BACKUPDIR/log.txt"
TOUSER="repluser"
TOHOST="syncserver.company.local"
TODIR="/srv/syncdata/Oracle/${HOSTNAME_SHORT}_${ORACLE_SID}/pfile"
BACKUPFILE="$BACKUPDIR/${HOSTNAME_SHORT}_${ORACLE_SID}-pfile_`date +%Y%m%d%H%M`.pfile"
DOCOPY="1"
 
mailFunction() {
   if [ "$1" == "SUCCESS" ]; then
      cat $LOGFILE | mail -s "Check PFILE Backup, not copied and not checked!" $MAILTOFAIL
   fi
}
 
copyFunction() {
   if [ "$DOCOPY" == "1" ]; then
      offsitecopy "${BACKUPFILE}" "$TOUSER" "$TOHOST" "$TODIR" "$LOGFILE" "$WHATAMI" "$HOSTNAME" "$MAILTOSUCCESS" "$MAILTOFAIL"
   else
      echo
      echo "Copy to offsite location is not enabled."
      echo "Modify the script under Offsitecopy Variables to enable offsitecopy"
      echo
      mailFunction SUCCESS
   fi
}
 
# NOTE: Output of command is always succesful because of the echo!!! Always check $LOGFILE
createPfile() {
   echo "Starting pfile backup..." > $LOGFILE
   echo "create pfile='$BACKUPFILE' from spfile;" | $ORACLE_HOME/bin/sqlplus -S "/ as sysdba" >> $LOGFILE
   echo "Pfile backup done." >> $LOGFILE
}
 
createPfile
copyFunction
 
echo
echo "INFO - PFILE backup finished"
echo

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

Another Check

You can cat the created pfile, so you can view the oracle settings.

More Resources

For more info on pfile, please see this article.

pfilebackup.txt · Last modified: 2021/09/24 00:25 by 127.0.0.1