SHIFT

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

User Tools

Site Tools


pfilebackup
Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pfilebackup [2013/05/04 13:20] (current)
sjoerd created
Line 1: Line 1:
 += Script: Bash: PFILE Backup =
  
 +You need a pfile when restoring the [[oraclerman|Oracle RMAN Backup]].
 +
 +<code bash>
 +#!/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
 +</​code>​
 +
 +As you can see, there is an external reference to offsitecopy and mail.txt. Both are described in [[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 [[http://​www.dba-oracle.com/​concepts/​pfile_spfile.htm|this article]]. ​
 +{{tag>​scripts oracle backup}}
pfilebackup.txt ยท Last modified: 2013/05/04 13:20 by sjoerd