Skip to content

Commit 690466c

Browse files
committed
Update backup_rman.sh
Fixed error handling. Appended "controlfile to trace" with "as $backdir/$basename" and removed the controlfile trace search and move section.
1 parent e11fcd8 commit 690466c

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

backup_rman.sh

+28-22
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ fi
5353
error()
5454
{
5555
echo "$@" 1>&2
56+
if [ -n "$email_failure" ]
57+
then
58+
if [ -n "$logmail" ]
59+
then mailto $email_failure $logmail "BACKUP FAILURE while $phase of $sid database on $machine" FILE
60+
else mailto $email_failure "$1" "BACKUP FAILURE while $phase of $sid database on $machine"
61+
fi
62+
fi
5663
exit 1
5764
}
5865

@@ -295,9 +302,9 @@ do_backup_script()
295302
then echo "sql \"create pfile=''$backdir/$basename.node$node.spfile'' from spfile\";" | tee -a $rmanscript
296303
fi
297304

298-
# Create a text controlfile backup. Later, we'll find this file and rename/move it to $backdir.
305+
# Create a text controlfile backup.
299306
if [ "$trace" ]
300-
then echo "sql 'alter database backup controlfile to trace';" | tee -a $rmanscript
307+
then echo "sql \"alter database backup controlfile to trace as ''$backdir/$basename.trace.ctl''\";" | tee -a $rmanscript
301308
fi
302309

303310
# If this is already an spfile backup, disregard the --spfile option.
@@ -365,7 +372,7 @@ do_validation_script()
365372
do_backup()
366373
{
367374
now=`date '+%m/%d/%y %H:%M:%S'`
368-
echo "$phase of database $mysid beginning at $now." | tee -a $logfile $logmail
375+
echo "Backup of database $mysid beginning at $now." | tee -a $logfile $logmail
369376

370377
# Send output from RMAN to its own log that we can tee to the individual log files.
371378
logrman=$(mktemp)
@@ -377,11 +384,10 @@ do_backup()
377384
exit_status=$?
378385
now=`date '+%m/%d/%y %H:%M:%S'`
379386
cat $logrman | tee -a $logfile $logmail
380-
message="$phase of database $mysid complete at $now." | tee -a $logfile $logmail
387+
message="Backup of database $mysid complete at $now." | tee -a $logfile $logmail
381388

382-
if [ $? -ne 0 ]
383-
then mailto $email_failure $logmail "FAIL: $phase of $sid database on $machine" FILE
384-
error "FAIL: $phase of $sid on $machine - see $backdir/$logfile for details"
389+
if [ $exit_status -ne 0 ]
390+
then error "Failure while $phase of $sid on $machine - see $backdir/$logfile for details"
385391
fi
386392

387393
rm $logrman
@@ -504,6 +510,7 @@ do
504510
done
505511
shift $[OPTIND-1]
506512

513+
phase="validating command line arguments"
507514
# Validate command line arguments.
508515
# You have to have a local backup directory:
509516
if [ ! "$backdir" ]
@@ -585,11 +592,13 @@ ORAENV_ASK=NO; export $ORAENV_ASK;
585592
ORACLE_SID=$sid; export $ORACLE_SID;
586593
. $ORACLE_HOME/bin/oraenv
587594

595+
phase="obtaining database status"
588596
db_status $sid
589597
if [ $? -ne 0 ]
590598
then error "The database $sid is not open"
591599
fi
592600

601+
phase="creating support files"
593602
# Create the file extensions
594603
now=`date '+%y-%m-%d_%H-%M-%S'`
595604

@@ -623,6 +632,7 @@ if [ $? -ne 0 ]
623632
then error "Could not create the restore script file"
624633
fi
625634

635+
phase="setting RMAN backup type"
626636
if [ ! "$backuptype" ]
627637
then error "A backup type (full, incremental, copy, archivelog or spfile) must be supplied"
628638
elif [ "$backuptype" != "incremental" -a "$backuptype" != "full" -a "$backuptype" != "copy" -a "$backuptype" != "archivelog" -a "$backuptype" != "spfile" ]
@@ -633,10 +643,13 @@ if [ "$backuptype" != "incremental" -a "$id" ]
633643
then error "A differential backup type is only valid for incremental backups"
634644
fi
635645

646+
phase="setting database environment"
636647
do_dbenv
637648

649+
phase="preparing for backup"
638650
do_backup_script
639651

652+
phase="capturing pre-backup environment"
640653
# Send full diagnostic information to the logfile, but not the email log.
641654
echo " " | tee -a $logfile
642655
if [ "$summary" != "summary" ]
@@ -659,24 +672,15 @@ fi
659672
# If this is not a preview (just write files but don't do a backup) then we run the backup.
660673
if [ ! "$preview" ]
661674
then script=$rmanscript
662-
phase=Backup
675+
phase="performing backup"
663676
do_backup
664-
665-
# If a "backup controlfile to trace" was requested:
666-
# 1. Find the trace file;
667-
# 2. Remove the trm metadata file;
668-
# 3. Move the trace file to the backup directory and rename it to something meaningful.
669-
if [ "$trace" ]
670-
then grep -l "Set #1. NORESETLOGS case" $tracedir/*.trc | gawk -F. -v path=$backdir/$basename '{print "rm "$1.".trm; mv "$1".trc " path ".trace.ctl"}' | xargs -i -t sh -c "{}"
671-
if [ $? == 1 ]
672-
then error "There was a problem moving the controlfile trace."
673-
fi
674-
fi
675677
else echo "Running in preview mode." | tee -a $logfile $logmail
678+
phase="performing backup preview"
676679
fi
677680

678681
if [ "$validate" ]
679-
then validscript=$backdir/$basename.validate.rman
682+
then phase="performing validation"
683+
validscript=$backdir/$basename.validate.rman
680684
touch $validscript
681685
if [ $? -ne 0 ]
682686
then error "Could not create the validation script file"
@@ -686,7 +690,7 @@ if [ "$validate" ]
686690

687691
if [ ! "$preview" ]
688692
then script=$validscript
689-
phase=Validation
693+
phase="validating backup"
690694
do_backup
691695
else echo "Validation not performed - running in preview mode" | tee -a $logfile $logmail
692696
fi
@@ -696,9 +700,11 @@ if [ ! "$preview" ]
696700
then echo " " | tee -a $logfile
697701

698702
if [ "$clean" ]
699-
then do_log_cleanup
703+
then phase="performing cleanup"
704+
do_log_cleanup
700705
fi
701706

707+
phase="capturing post-backup environment"
702708
# Don't write "after backup" diagnostic information for previews.
703709
if [ "$summary" != "summary" ]
704710
then echo "User processes in the $sid database after backup:" | tee -a $logfile

0 commit comments

Comments
 (0)