53
53
error ()
54
54
{
55
55
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
56
63
exit 1
57
64
}
58
65
@@ -295,9 +302,9 @@ do_backup_script()
295
302
then echo " sql \" create pfile=''$backdir /$basename .node$node .spfile'' from spfile\" ;" | tee -a $rmanscript
296
303
fi
297
304
298
- # Create a text controlfile backup. Later, we'll find this file and rename/move it to $backdir.
305
+ # Create a text controlfile backup.
299
306
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
301
308
fi
302
309
303
310
# If this is already an spfile backup, disregard the --spfile option.
@@ -365,7 +372,7 @@ do_validation_script()
365
372
do_backup ()
366
373
{
367
374
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
369
376
370
377
# Send output from RMAN to its own log that we can tee to the individual log files.
371
378
logrman=$( mktemp)
@@ -377,11 +384,10 @@ do_backup()
377
384
exit_status=$?
378
385
now=` date ' +%m/%d/%y %H:%M:%S' `
379
386
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
381
388
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"
385
391
fi
386
392
387
393
rm $logrman
504
510
done
505
511
shift $[OPTIND-1]
506
512
513
+ phase=" validating command line arguments"
507
514
# Validate command line arguments.
508
515
# You have to have a local backup directory:
509
516
if [ ! " $backdir " ]
@@ -585,11 +592,13 @@ ORAENV_ASK=NO; export $ORAENV_ASK;
585
592
ORACLE_SID=$sid ; export $ORACLE_SID ;
586
593
. $ORACLE_HOME /bin/oraenv
587
594
595
+ phase=" obtaining database status"
588
596
db_status $sid
589
597
if [ $? -ne 0 ]
590
598
then error " The database $sid is not open"
591
599
fi
592
600
601
+ phase=" creating support files"
593
602
# Create the file extensions
594
603
now=` date ' +%y-%m-%d_%H-%M-%S' `
595
604
@@ -623,6 +632,7 @@ if [ $? -ne 0 ]
623
632
then error " Could not create the restore script file"
624
633
fi
625
634
635
+ phase=" setting RMAN backup type"
626
636
if [ ! " $backuptype " ]
627
637
then error " A backup type (full, incremental, copy, archivelog or spfile) must be supplied"
628
638
elif [ " $backuptype " != " incremental" -a " $backuptype " != " full" -a " $backuptype " != " copy" -a " $backuptype " != " archivelog" -a " $backuptype " != " spfile" ]
@@ -633,10 +643,13 @@ if [ "$backuptype" != "incremental" -a "$id" ]
633
643
then error " A differential backup type is only valid for incremental backups"
634
644
fi
635
645
646
+ phase=" setting database environment"
636
647
do_dbenv
637
648
649
+ phase=" preparing for backup"
638
650
do_backup_script
639
651
652
+ phase=" capturing pre-backup environment"
640
653
# Send full diagnostic information to the logfile, but not the email log.
641
654
echo " " | tee -a $logfile
642
655
if [ " $summary " != " summary" ]
659
672
# If this is not a preview (just write files but don't do a backup) then we run the backup.
660
673
if [ ! " $preview " ]
661
674
then script=$rmanscript
662
- phase=Backup
675
+ phase=" performing backup "
663
676
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
675
677
else echo " Running in preview mode." | tee -a $logfile $logmail
678
+ phase=" performing backup preview"
676
679
fi
677
680
678
681
if [ " $validate " ]
679
- then validscript=$backdir /$basename .validate.rman
682
+ then phase=" performing validation"
683
+ validscript=$backdir /$basename .validate.rman
680
684
touch $validscript
681
685
if [ $? -ne 0 ]
682
686
then error " Could not create the validation script file"
@@ -686,7 +690,7 @@ if [ "$validate" ]
686
690
687
691
if [ ! " $preview " ]
688
692
then script=$validscript
689
- phase=Validation
693
+ phase=" validating backup "
690
694
do_backup
691
695
else echo " Validation not performed - running in preview mode" | tee -a $logfile $logmail
692
696
fi
@@ -696,9 +700,11 @@ if [ ! "$preview" ]
696
700
then echo " " | tee -a $logfile
697
701
698
702
if [ " $clean " ]
699
- then do_log_cleanup
703
+ then phase=" performing cleanup"
704
+ do_log_cleanup
700
705
fi
701
706
707
+ phase=" capturing post-backup environment"
702
708
# Don't write "after backup" diagnostic information for previews.
703
709
if [ " $summary " != " summary" ]
704
710
then echo " User processes in the $sid database after backup:" | tee -a $logfile
0 commit comments