#!/bin/sh # # $DBA/backarch # # Backup any archive files that might exist for the specified database. # (Then delete the archive files since they are no longer needed) # # $1 = Oracle SID whose archive files are being backed up # $2 = Type of backup; One of: COLD, HOT, or HOTALL # $3 = Start of Archive log destination directory (ARCHSTART) # $4 = End of Archive log destination directory (ARCHEND) # $5 = Whether the database tablespace files are on raw device partitions (RAW), # or on filesystems (FS) # $6 = Backup filesystem to be used (if no override file is found), or tape # device specification # $7 = Type of backup device; One of: DISK, TAPE # $8 = Archive log destination directory (no filename prefix) (ARCHDIR) # # <<<<<<<<<<<<<<<<<<< Modification History >>>>>>>>>>>>>>>>>>> # 01/28/98 Brian Lomasky Modify comment for the $6 parameter. Pass # tape device specification to copy_log to # support fbackup usage. Include additional # debug info if bkup_$mysid script fails. # 02/21/97 Brian Lomasky Change filenames, process different backup # types. Process variable backup filesystem. # Process all pieces of archive log directory. # Rename backup override data file. # 11/11/96 Brian Lomasky Detect and emit an error if the archive log # copy_log fails. # USAGE="Usage: backarch COLD|HOT " if [ "$1" = "" ] then echo "$USAGE\007" 1>&2 mailto "backarch error - No \$1 parameter specified." exit 2 else mysid=`fixcase $1` fi if [ "$2" = "" ] then echo "$USAGE\007" 1>&2 mailto "backarch error - No \$2 parameter specified." exit 2 else bkuptype=`echo $2 | tr '[a-z]' '[A-Z]'` fi if [ "$3" = "" ] then echo "$USAGE\007" 1>&2 mailto "backarch error - No \$3 parameter specified." exit 2 else myarch1=$3 fi if [ "$4" = "" ] then echo "$USAGE\007" 1>&2 mailto "backarch error - No \$4 parameter specified." exit 2 else myarch2=$4 fi if [ "$5" = "" ] then echo "$USAGE\007" 1>&2 mailto "backarch error - No \$5 parameter specified." exit 2 else raw=$5 fi if [ "$6" = "" ] then echo "$USAGE\007" 1>&2 mailto "backarch error - No \$6 parameter specified." exit 2 else bkupfs=$6 fi if [ "$7" = "" ] then echo "$USAGE\007" 1>&2 mailto "backarch error - No \$7 parameter specified." exit 2 else destdev=$7 fi if [ "$8" = "" ] then echo "$USAGE\007" 1>&2 mailto "backarch error - No \$8 parameter specified." exit 2 else ARCHDIR=$8 fi echo "** Processing any archive log files for database $1 **" if [ -r ${myarch1}*${myarch2} ] then echo " Verifying database $mysid" valid_db $mysid if [ $? -ne 0 ] then mailto "backarch error - Invalid database: $mysid" exit 2 fi SID=$mysid . define case $bkuptype in COLD) echo " COLD backup of archive logs..." ;; HOT) echo " HOT backup of control file and archive logs..." ;; HOTALL) echo " HOT BATCH backup of control file and archive" \ "logs..." ;; *) echo "Bad bkuptype of $bkuptype specified" echo "$USAGE" 1>&2 exit 1 ;; esac # # See if backup override file exists and we are copying to disk # if [ -r backarch_$mysid.tmp ] then rm backarch_$mysid.tmp fi if [ -r $DBA/back$mysid.dat -a "$destdev" = "DISK" ] then # See if nawk should be used instead of awk (nawk '{ print ; exit }' /etc/passwd) > /dev/null 2>&1 if [ ${?} -eq 0 ] then cmd=nawk else cmd=awk fi echo " Processing backup override file:" \ "$DBA/back$mysid.dat..." # Extract the root archive log file system being copied fs=`echo "${myarch1}*${myarch2}" | $cmd '{ x=index($0,"/") y=index(substr($0,x+1),"/") if (x != 0 && y != 0) { print substr($0,x,y) } }' -` echo " Archive log file system is $fs" # See if a file system was found if [ "$fs" != "" ]; then cat $DBA/back$mysid.dat | while read THISLINE do # Skip blank lines if [ "$THISLINE" = "" ]; then continue fi # Extract the matching file system and backup # destination, if any outlin=`echo $THISLINE | $cmd -F: '{ if (substr($0,1,1) != "#") { if ($1 == fs) { print $2 } } }' fs=$fs -` # Use matching file system if [ "$outlin" != "" ]; then echo "$outlin" > backarch_$mysid.tmp fi done fi fi # Use override filesystem for archive log backup, if one exists if [ -r backarch_$mysid.tmp ] then echo " Using override filesystem instead of $bkupfs..." bkupfs=`cat backarch_$mysid.tmp` rm backarch_$mysid.tmp fi case $bkuptype in COLD) echo " Copying ${myarch1}*${myarch2} to $bkupfs..." ls -1 ${myarch1}*${myarch2} | while read THISLINE do copy_log $THISLINE $bkupfs DATA $raw $destdev if [ $? -ne 0 ] then echo "\nError from copy_log DATA\n" mailto \ "backarch error from copy_log DATA" exit 2 fi done # Include any control file re-creation script file if [ -r $ARCHDIR/cr_$mysid.sql ] then copy_log $ARCHDIR/cr_$mysid.sql $bkupfs DATA \ $raw $destdev if [ $? -ne 0 ] then echo "\nError from copy_log DATA cr\n" mailto \ "backarch error from copy_log DATA cr" exit 2 fi fi # Include any restore script file if [ -r $ARCHDIR/restore_$mysid ] then copy_log $ARCHDIR/restore_$mysid $bkupfs DATA \ $raw $destdev if [ $? -ne 0 ] then echo "\nError from copy_log DATA cr\n" mailto \ "backarch error from copy_log DATA rest" exit 2 fi fi echo " List of files in $bkupfs" mypwd=`pwd` cd $bkupfs ls -al df -k $bkupfs cd $mypwd ;; HOT) # # Create script to switch logfiles and wait for # the current log file to be archived # now=`date '+%m/%d/%y %H:%M:%S'` echo "Creating HOT CTRL BACKUP script for $mysid" \ "at $now" creback $mysid $bkuptype $raw CTRL $destdev \ $ARCHDIR $bkupfs exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from creback HOT CTRL for $mysid" fi # # Switch logfiles and wait for the current log # file to be archived # echo "Switching logfiles and backing up the control" \ "file for the $mysid database..." bkup_$mysid exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from bkup_$mysid for CTRL" echo "-----------------------------------" echo "bkup_$mysid is:" cat bkup_$mysid echo "-----------------------------------" fi rm bkup_$mysid # # Continue with the archive log files # echo " Copying ${myarch1}*${myarch2} to $bkupfs..." ls -1 ${myarch1}*${myarch2} | while read THISLINE do copy_log $THISLINE $bkupfs DATA $raw $destdev if [ $? -ne 0 ] then echo "\nError from copy_log DATA\n" mailto \ "backarch error from copy_log DATA" exit 2 fi done # Include any control file re-creation script file if [ -r $ARCHDIR/cr_$mysid.sql ] then copy_log $ARCHDIR/cr_$mysid.sql $bkupfs DATA \ $raw $destdev if [ $? -ne 0 ] then echo "\nError from copy_log DATA cr\n" mailto \ "backarch error from copy_log DATA cr" exit 2 fi fi # Include any restore script file if [ -r $ARCHDIR/restore_$mysid ] then copy_log $ARCHDIR/restore_$mysid $bkupfs DATA \ $raw $destdev if [ $? -ne 0 ] then echo "\nError from copy_log DATA cr\n" mailto \ "backarch error from copy_log DATA rest" exit 2 fi fi echo " List of files in $bkupfs" mypwd=`pwd` cd $bkupfs ls -al df -k $bkupfs cd $mypwd ;; HOTALL) # # Initialize for list of control files and archive logs # to be backed up # echo " Initializing for batch control file and" \ "archive log copying..." copy_log $mysid x INITARCH $raw $destdev if [ $? -ne 0 ] then echo "\nError from copy_log INITARCH\n" mailto "backarch error from copy_log INITARCH" exit 2 fi # # Create script to switch logfiles and wait for # the current log file to be archived # now=`date '+%m/%d/%y %H:%M:%S'` echo "Creating HOT BATCH CTRL BACKUP script for" \ " $mysid at $now" creback $mysid $bkuptype $raw CTRL $destdev \ $ARCHDIR $bkupfs exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from creback HOT BCTRL for $mysid" fi # # Switch logfiles and wait for the current log # file to be archived # echo "Switching logfiles and backing up the control" \ "file for the $mysid database..." bkup_$mysid exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from batch bkup_$mysid for CTRL" echo "-----------------------------------" echo "bkup_$mysid is:" cat bkup_$mysid echo "-----------------------------------" fi rm bkup_$mysid # # Continue with the archive log files # echo " Batch copying ${myarch1}*${myarch2} to" \ "$destdev..." # Pass list of archive log files to be backed up ls -1 ${myarch1}*${myarch2} | while read THISLINE do copy_log $mysid $THISLINE PASS_ARCH $raw \ $destdev if [ $? -ne 0 ] then echo "\nError from copy_log PASS_ARCH\n" mailto \ "backarch error from copy_log PASS_ARCH" exit 2 fi done # Include any control file re-creation script file if [ -r $ARCHDIR/cr_$mysid.sql ] then copy_log $mysid $ARCHDIR/cr_$mysid.sql \ PASS_ARCH $raw $destdev if [ $? -ne 0 ] then echo "\nError from copy_log PASS_ARCH" \ " cr_$mysid.sql\n" mailto \ "backarch error from copy_log PASS_ARCH cr" exit 2 fi fi # Include any restore script file if [ -r $ARCHDIR/restore_$mysid ] then copy_log $mysid $ARCHDIR/restore_$mysid \ PASS_ARCH $raw $destdev if [ $? -ne 0 ] then echo "\nError from copy_log PASS_ARCH" \ " restore_$mysid\n" mailto \ "backarch error from copy_log PASS_ARCH restore" exit 2 fi fi # Start archive log batch backup process copy_log $mysid $bkupfs STARTARCH $raw $destdev if [ $? -ne 0 ] then echo "\nError from copy_log STARTARCH\n" mailto "backarch error from copy_log STARTARCH" exit 2 fi ;; esac echo " Removing the old $mysid archive log files..." if [ "$bkuptype" = "HOTALL" ] then bkuptype=HOT fi $DBA/delarch $bkuptype $myarch1 $myarch2 if [ $? -ne 0 ] then echo "\nbackarch error $? from delarch $bkuptype for $mysid" mailto "backarch error $? from delarch $bkuptype for $mysid" exit 2 fi else echo "" echo " backarch - No archive log files exist to backup" echo "" fi