#!/bin/sh # # $DBA/backup # # <<<<<<<<<<<<<<< MODIFICATION HISTORY >>>>>>>>>>>>>>> # Date Programmer Description # -------- --------------- ----------------------------------------------- # 01/28/98 Brian Lomasky Fix export exit code error detection. # 10/10/97 Brian Lomasky Renamed startmgr and stopmgr to startm, stopm. # 03/03/97 Brian Lomasky Added flag to abort backup if copy_log error. # Include mailed error text in backup log file. # 02/21/97 Brian Lomasky Added backup type, mode, destdev, and raw_fs # parameter processing. Modified to perform raw # hot backups. Modified for new filenames. # Modify for new archive log locating. Backup # control files after any hot backup is done. # 11/11/96 Brian Lomasky Verify for successful export termination. # 10/09/96 Brian Lomasky Add archive log specification restriction text. # 09/25/96 Brian Lomasky Change dbo_users to dbousers. Added comments. # 09/03/96 Brian Lomasky Renamed create_control to ccontrol. # 07/09/96 Brian Lomasky Verify for existing FNDLIBR for conc. managers, # Allow "hot" $2 parameter. Trap for SQL errors # 07/08/96 Brian Lomasky Use OPS$username for export # 04/05/96 Brian Lomasky Call new create_control script # 03/11/96 Brian Lomasky Trap unexpected export errors # 03/05/96 Brian Lomasky Set permissions for the restore file # 02/09/96 Brian Lomasky Add option for $2 parameter to omit the export. # 12/13/95 Brian Lomasky Call $DBA/allmemry for debugging info. Change # ipcs parameters. Include more date stamps. # 11/29/95 Brian Lomasky Call dbo_users for debugging info. Execute # killunix to kill any leftover conc mgr jobs # 11/17/95 Brian Lomasky Skip backup if database is offline # 10/24/95 Brian Lomasky Copy restore_ to backup directory # 10/04/95 Brian Lomasky Also do a full database export # 09/29/95 Brian Lomasky Create & backup script to recreate control file # 09/12/95 Brian Lomasky Rename old internal concurrent manager log file # 09/11/95 Brian Lomasky Call backarch to backup archive log files # 09/07/95 Brian Lomasky Call backcln to erase old backup files, # backdisp to display backed-up files # 08/22/95 Brian Lomasky Call offline and online when database backed up # 06/08/95 Brian Lomasky Include Oracle SID in bkup filespec # 04/12/95 Brian Lomasky Added Oracle SID to all mail messages # 04/04/95 Brian Lomasky Send mail if any error occurs # 04/03/95 Brian Lomasky Call fixcase to set correct case for sid # 03/22/95 Brian Lomasky Ensure correct case of database SID # 03/13/95 Brian Lomasky Include ipcs for debugging purposes # 03/02/95 Brian Lomasky Fix to ensure database up if creating archive # 03/01/95 Brian Lomasky Moved all database/manager waits out of here # 02/16/95 Brian Lomasky Skip archive log backup if no archive destin. # 01/31/95 Brian Lomasky Change all hard-coded directories to $DBA # 01/30/95 Brian Lomasky Call define and crearch to replace $2 and $3 # parameters # 01/24/95 Brian Lomasky Delete old files by their explicit extension # (so as to avoid warning of trying to delete # the lost+found directory) # 01/23/95 Brian Lomasky Fix backup script order, Fix archive directory # 01/20/95 Brian Lomasky Call create_backup to create backup script # 01/12/95 Brian Lomasky Rewrite to use $1, $2, 3 parameters # 01/09/95 Brian Lomasky Moved $1 files from /u04 to /u03, # Use is_demo and is_pilot scripts to see if # concurrent managers are shut down # 12/21/94 Brian Lomasky Added backup of .CTL files on /u01 # 12/23/94 Brian Lomasky Added backup of .arc files # ----------------------------------------------------------------------------- # # Restrictions: # The DBA and TOOLS environment variables need to be defined as pointing # to the directories containing the backup-related scripts. (Files are # placed in their required directories by running the backall script). # # Parameters: # $1 (Required) ORACLE_SID of the database to be backed up. # $2, $3, $4, $5, $6 # (Optional) These parameters can contain none or more of # the following (case-insensitive) values, in # any order: # hot Performs a HOT (online) backup of the database. # The database will not be shutdown. # (Default of performing a COLD backup). # batch When used with a HOT backup, specifies that the # tablespaces are to be backed up in a single # batch: # 1) All tablespaces will be set to # "BEGIN BACKUP", # 2) All tablespaces are then backed up. # 3) All tablespaces will then be set to # "END BACKUP". # (Default of individually processing each # tablespace. For each HOT backup tablespace: # 1) It will be set to "BEGIN BACKUP", # 2) It will be backed up, # 3) It will be set to "END BACKUP"). # full Performs a full database export (after the cold # or hot backup has been completed). (Default # of no export). # tape Specifies that the backup destination will be # tape. (Default backup destination of disk). # raw Indicates that the database files are located # on raw device partitions. (Default of files # located on filesystems). # USAGE="Usage: backup " # # Parse parameter list for first parameter # if [ "$1" = "" ] then echo "$USAGE" 1>&2 mailto "backup error - No \$1 parameter specified." exit 2 fi mysid=`fixcase $1` now=`date '+%m/%d/%y %H:%M:%S'` echo "******* Starting BACKUP for $1 at $now *******" shift # # Parse remaining parameter list # bkuptype=COLD # Default of COLD backup mode=CONSECUTIVE # Default of consecutive files destdev=DISK # Default of disk backup destin. destfs=/dev/rmt/0m # Default tape backup device export=NO # Default of no export raw_fs=FS # Default of filesystem backup while [ $# -gt 0 ] do mypar=`echo $1 | tr '[a-z]' '[A-Z]'` # Uppercase argument case $mypar in HOT) bkuptype=HOT shift ;; BATCH) mode=BATCH shift ;; FULL) export=FULL shift ;; RAW) raw_fs=RAW shift ;; TAPE) destdev=TAPE shift ;; *) echo "Bad parameter specified for backup: $mypar" echo "$USAGE" 1>&2 exit 1 ;; esac done if [ "$mode" = "BATCH" -a "$bkuptype" = "COLD" ] then echo "Backup Error - Incompatible parameters specified" echo " You can specify BATCH mode only with HOT backups" echo " Aborting...\007" exit 1 fi case $bkuptype in COLD) echo "******* Performing COLD backup for $mysid *******" ;; HOT) echo "******* Performing HOT backup for $mysid *******" ;; esac case $mode in CONSECUTIVE) echo "******* Tablespaces will be backed up one at a time" \ "*******" ;; BATCH) echo "******* All tablespaces will be backed up at" \ "the same time *******" ;; esac case $destdev in DISK) echo "******* Backups will be performed disk-to-disk *******" ;; TAPE) echo "******* Backups will be performed disk-to-tape *******" ;; esac case $export in NO) echo "******* No database export will be performed *******" ;; FULL) case $bkuptype in COLD) echo "******* A full database EXPORT will be" \ "performed *******" ;; *) echo "******* A full online database EXPORT will be" \ "performed *******" esac esac case $raw_fs in RAW) echo "******* Database files are stored on raw device" \ "partitions *******" ;; FS) echo "******* Database files are stored on file systems" \ "*******" ;; esac if [ -r $TOOLS/offline.$mysid ] then echo "Skipping backup of database $mysid which is OFFLINE" exit fi echo "Verifying database $mysid" valid_db $mysid if [ $? -ne 0 ] then mailto "backup error - Invalid database: $mysid" exit 2 fi echo "Defining environment for $mysid database" SID=$mysid . define abort_backup=0 if [ "$bkuptype" = "COLD" ] then offline $mysid fi # If backing up to a disk device: if [ "$destdev" = "DISK" ] then # # Calculate a valid backup file system for this database # destfs=`calcbkup` if [ "$destfs" = "" ] then mailto \ "backup error - No valid backup file system found for $ORACLE_SID" exit 2 fi fi # # Display list of any concurrent managers now running # (if running Oracle Applications) # set +u if [ -r "$FND_TOP/bin/FNDLIBR" ] then set -u echo "Concurrent Managers now running:" ps $PS_OPTS | grep -v grep | grep FNDLIBR fi set -u # # Ensure $mysid database is open (so that we can use sql to build backup # script) # dbo_stat $mysid if [ $? -ne 0 ] then # # Startup the $mysid database # echo "Starting database $mysid (to build backup script)..." dbostart $mysid exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from dbostart for $mysid" fi fi echo "Creating $bkuptype backup script for $mysid..." case $mode in CONSECUTIVE) m=CONSECUTIVE ;; BATCH) m=BATCHBEGIN ;; esac creback $mysid $bkuptype $raw_fs $m $destdev $destfs exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from creback for $mysid" fi echo "Creating archive destination variables for $mysid database..." SID=$mysid . $DBA/crearch # # Create script to re-create control file for this database # ccontrol $ORACLE_SID if [ -r cr_$mysid.sql ] then # If backing up to a disk device: if [ "$destdev" = "DISK" ] then # # Copy the control file re-creation script to the backup # directory, then delete the re-creation script # now=`date '+%m/%d/%y %H:%M:%S'` echo " Copying cr_$mysid.sql to $destfs at $now..." cp cr_$mysid.sql $destfs echo " Removing the old $mysid control file" \ "re-creation script..." rm cr_$mysid.sql else # Backing up to tape - See if archive log directory available if [ "$ARCHDIR" != "" ] then # # Copy the control file re-creation script to the # archive log directory, then delete the # re-creation script # now=`date '+%m/%d/%y %H:%M:%S'` echo " Copying cr_$mysid.sql to $ARCHDIR at $now..." cp cr_$mysid.sql $ARCHDIR echo " Removing the old $mysid control file" \ "re-creation script..." rm cr_$mysid.sql fi fi fi # # If restore script was created: # if [ -r restore_$mysid ] then # If backing up to a disk device: if [ "$destdev" = "DISK" ] then # # Copy the restore script to the backup directory, # then delete the restore script # now=`date '+%m/%d/%y %H:%M:%S'` echo " Copying restore_$mysid to $destfs at $now..." cp restore_$mysid $destfs chmod 700 $destfs/restore_$mysid echo " Removing the old $mysid database restore script..." rm restore_$mysid else # Backing up to tape - See if archive log directory available if [ "$ARCHDIR" != "" ] then # # Copy the restore script to the archive log # directory, then delete the restore script # now=`date '+%m/%d/%y %H:%M:%S'` echo " Copying restore_$mysid to $ARCHDIR at $now..." cp restore_$mysid $ARCHDIR chmod 700 $ARCHDIR/restore_$mysid echo " Removing the old $mysid database" \ "restore script..." rm restore_$mysid fi fi else echo "No restore_$mysid file exists to be backed up." fi if [ "$bkuptype" = "COLD" ] then # # Shutdown any concurrent managers if running Oracle Applications # set +u if [ -r "$FND_TOP/bin/FNDLIBR" ] then set -u # # Display list of actual database users # echo "" echo "Oracle users which are in the $mysid database:" dbousers $mysid if [ -r $DBA/allmemry.exe ] then # # Display memory utilization # echo "" echo "Memory utilization before concurrent manager" \ "shutdown:" $DBA/allmemry fi # # Shut down the concurrent managers for the $mysid # database # echo "" echo "Shutting down the concurrent managers for the $mysid" \ "database..." stopm $mysid exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from stopm for $mysid" fi fi fi set -u if [ -r $DBA/allmemry.exe ] then # # Display memory utilization # echo "" if [ "$bkuptype" = "COLD" ] then echo "Memory utilization before database shutdown:" else echo "Memory utilization before backup:" fi $DBA/allmemry fi # # Display list of actual database users # echo "" echo "Oracle users which are in the $mysid database:" dbousers $mysid # # Display list of any users which may be in the $mysid database # echo "" echo "User processes which are in the $mysid database:" ps $PS_OPTS | grep -v grep | grep oracle$mysid if [ "$bkuptype" = "COLD" ] then # # Kill the unix process for any leftover concurrent manager jobs # set +u if [ -r "$FND_TOP/bin/FNDLIBR" ] then set -u echo "" echo "Killing the unix process for any leftover concurrent" \ "manager jobs..." killunix oracle$mysid # # Display list of actual database users # echo "" echo "Oracle users which are still in the $mysid database:" dbousers $mysid # # Display list of any users which may be in the $mysid # database # echo "" echo "User processes which are still in the $mysid database:" ps $PS_OPTS | grep -v grep | grep oracle$mysid fi set -u fi # # Display list of any database processes # echo "Databases processes for $mysid which are now running:" ps $PS_OPTS | grep -v grep | grep ora_.*_$mysid # # Display ipcs debug info # if [ "$bkuptype" = "COLD" ] then echo "Displaying ipcs debug info before database shutdown..." else echo "Displaying ipcs debug info before backup..." fi ipcs -bms # if [ "$bkuptype" = "COLD" ] then # # Shut down the $mysid database # dbostop $mysid exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from dbostop for $mysid" fi # # Display list of any database processes # echo "Databases processes for $mysid which are still running:" ps $PS_OPTS | grep -v grep | grep ora_.*_$mysid fi # # Rename concurrent manager log files if running Oracle Applications # set +u if [ -r "$FND_TOP/bin/FNDLIBR" ] then if [ ! -r $DBA/noconc.$mysid ] then # # Rename the internal concurrent manager log file, if one # exists # if [ -r $FND_TOP/$APPLLOG/std.mgr ] then echo "Renaming internal concurrent manager log file..." dow=`date +%a` mv $FND_TOP/$APPLLOG/std.mgr $FND_TOP/$APPLLOG/std.$dow fi fi fi set -u if [ "$bkuptype" = "COLD" ] then if [ -r $DBA/allmemry.exe ] then # # Display memory utilization # echo "" echo "Memory utilization after database shutdown:" $DBA/allmemry fi # # Display ipcs debug info # echo "Displaying ipcs debug info after database shutdown..." ipcs -bms fi # # See If backing up to disk # if [ "$destdev" = "DISK" ] then # # Remove any old backup files for the $mysid database # backcln $mysid $destfs fi now=`date '+%m/%d/%y %H:%M:%S'` # # Backup the $mysid database # case $bkuptype in COLD) echo "Backing up the control files, database files, and" \ "redo logs at $now..." bkup_$mysid exit_status=$? if [ $exit_status -ne 0 ] then echo "backup error - Unexpected error $exit_status" \ "from bkup_$mysid COLD" mailto \ "backup error - Unexpected error $exit_status from bkup_$mysid COLD" fi rm bkup_$mysid ;; HOT) case $mode in CONSECUTIVE) echo "Hot backing up the database files at" \ "$now..." bkup_$mysid exit_status=$? if [ $exit_status -ne 0 ] then if [ $exit_status -eq 99 ] then echo "backup error - Error" \ "while executing" \ "bkup_$mysid for" \ "database $mysid" > \ backup_err.tmp echo " Examine" \ "$DBA/data/*${mysid}"\ "*.log file for SQL" \ "error" >> \ backup_err.tmp echo " (" \ "Probably due to" \ "database not being" \ "in ARCHIVELOG" \ "mode?)" >> \ backup_err.tmp mailto backup_err.tmp \ "backup $mysid error" \ FILE rm backup_err.tmp else echo "backup error -" \ "Unexpected error" \ "$exit_status from" \ "bkup_$mysid HOT" mailto \ "backup error - Unexpected error $exit_status from bkup_$mysid HOT" fi fi rm bkup_$mysid ;; BATCH) # # Alter the tablespaces and pass file names to # copy_log # echo "Altering $mysid tablespaces for hot" \ "backup at $now..." bkup_$mysid exit_status=$? if [ $exit_status -ne 0 ] then echo "backup error - Unexpected error" \ "$exit_status from" \ "bkup_$mysid ALTER" echo " ABORTING BACKUP..." mailto \ "backup error - Unexpected error $exit_status from bkup_$mysid ALTER" exit 2 fi rm bkup_$mysid now=`date '+%m/%d/%y %H:%M:%S'` # # Backup the $mysid database # echo "HOT Backing up the database files at" \ "$now..." # # Issue special call to copy_log to start the # backup of the passed list of database files # (Wait until the backup has completed) # copy_log $mysid x START $raw_fs $destdev exit_status=$? if [ $exit_status -ne 0 ] then echo "backup error - Unexpected error" \ "$exit_status from copy_log" \ "for $mysid START" mailto \ "backup error - Unexpected error $exit_status from copy_log for $mysid START" abort_backup=1 fi # # End backup if performing a HOT BATCH # backup # echo "Creating HOT END BACKUP script for" \ "$mysid at $now" creback $mysid $bkuptype $raw_fs BATCHEND \ $destdev $destfs exit_status=$? if [ $exit_status -ne 0 ] then echo "backup error - Unexpected error" \ "$exit_status from creback" \ "HOT END for $mysid" mailto \ "backup error - Unexpected error $exit_status from creback HOT END for $mysid" fi # # End the backup of the $mysid database # now=`date '+%m/%d/%y %H:%M:%S'` echo "Ending backup of the $mysid database" \ "at $now..." bkup_$mysid exit_status=$? if [ $exit_status -ne 0 ] then echo "backup error - Unexpected error" \ "$exit_status from" \ "bkup_$mysid for END" mailto \ "backup error - Unexpected error $exit_status from bkup_$mysid for END" fi rm bkup_$mysid if [ $abort_backup -eq 1 ] then echo "Aborting backup..." exit 2 fi ;; esac ;; esac echo "" # # See If backing up to disk # if [ "$destdev" = "DISK" ] then now=`date '+%m/%d/%y %H:%M:%S'` echo "Displaying $mysid files which were backed up at $now..." backdisp $mysid $destfs fi # # Backup any archive files that might exist for the $mysid database # Then delete the archive files that were just backed up (since they are # no longer needed) # if [ "$ARCHSTAT" = "ARCHIVELOG" ] then if [ "$ARCHSTART" != "" ] then if [ -r ${ARCHSTART}*${ARCHEND} ] then case $bkuptype in COLD) passtype=COLD ;; HOT) case $mode in CONSECUTIVE) passtype=HOT ;; BATCH) passtype=HOTALL ;; esac ;; esac backarch $mysid $passtype $ARCHSTART $ARCHEND $raw_fs \ $destfs $destdev $ARCHDIR exit_status=$? if [ $exit_status -ne 0 ] then echo "backup error - Unexpected error" \ "$exit_status from backarch for $mysid" mailto \ "backup error - Unexpected error $exit_status from backarch for $mysid" # Fatal error only if doing a hot backup if [ "$bkuptype" = "HOT" ] then exit 2 fi fi else echo "No archive files exist to be backed up." fi else echo "No ARCHSTART environment variable is defined." fi fi # # See if export wanted # if [ "$export" = "FULL" ] then # # Do a full database export for this database # now=`date '+%m/%d/%y %H:%M:%S'` echo "Performing a full database export of database $mysid at $now..." if [ "$bkuptype" = "COLD" ] then # # Startup the $mysid database in exclusive mode # echo "Starting database $mysid in exclusive mode..." dbostart $mysid exclusive exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from dbostart for $mysid" fi fi # # Export the $mysid database # # If exporting to disk backup device: if [ "$destdev" = "DISK" ] then if [ -r $destfs/$mysid.dmp.Z ] then echo "Removing old $destfs/$mysid.dmp.Z export files..." rm $destfs/$mysid.dmp.Z fi if [ -r $destfs/$mysid.dmp ] then echo "Removing old $destfs/$mysid.dmp export files..." rm $destfs/$mysid.dmp fi fi now=`date '+%m/%d/%y %H:%M:%S'` echo "Exporting at $now..." echo "/" > xport_$mysid.dat # If exporting to disk backup device: if [ "$destdev" = "DISK" ] then echo "FILE=$destfs/$mysid.dmp" >> xport_$mysid.dat else echo "FILE=$destfs" >> xport_$mysid.dat fi echo "FULL=Y" >> xport_$mysid.dat if [ "$bkuptype" = "HOT" ] then echo "CONSISTENT=Y" >> xport_$mysid.dat fi # Output goes to the LOG file as well as to the terminal echo "LOG=xport_$mysid.log" >> xport_$mysid.dat exp PARFILE=xport_$mysid.dat > /dev/null 2>&1 if [ $? -ne 0 ] then echo "\nUnexpected error $? from export of $mysid database\n" mailto "Continuing with backup..." \ "Unexpected error from export of $mysid" fi rm xport_$mysid.dat # Display contents of the log file so that they are included in this # file's log cat xport_$mysid.log # Check the log file to ensure no export error occurred: grep "Export terminated successfully without warnings" \ xport_$mysid.log > /dev/null if [ $? -ne 0 ] then echo "\nUnexpected export error - Aborting with error status..." mailto "Aborting backup due to export error..." \ "Unexpected error from export of $mysid" exit 2 fi rm xport_$mysid.log echo "" # If exporting to disk backup device: if [ "$destdev" = "DISK" ] then if [ -r $destfs/*.dmp ] then echo "Displaying export files for $mysid..." ls -al $destfs/*.dmp echo "Compressing export files for $mysid..." compress $destfs/$mysid.dmp if [ $? -ne 0 ] then echo "\nUnexpected export compress error" \ "- Aborting with error status..." mailto \ "Aborting backup due to export compress error..." \ "Unexpected error from export of $mysid" exit 2 fi echo "Displaying export files after compress" \ "for $mysid..." ls -al $destfs/*.dmp.Z fi fi # # Display list of any database processes # now=`date '+%m/%d/%y %H:%M:%S'` echo "Databases processes for $mysid which are running at $now:" ps $PS_OPTS | grep -v grep | grep ora_.*_$mysid if [ "$bkuptype" = "COLD" ] then # # Shut down the $mysid database # dbostop $mysid exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from dbostop for $mysid" fi # # Display list of any database processes # echo "Databases processes for $mysid which are still running:" ps $PS_OPTS | grep -v grep | grep ora_.*_$mysid fi echo "" echo "" now=`date '+%m/%d/%y %H:%M:%S'` echo "------- Done with EXPORT of $mysid database at $now -------" fi if [ "$bkuptype" = "COLD" ] then # # Startup the $mysid database # echo "Starting database $mysid..." dbostart $mysid exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from dbostart for $mysid" fi online $mysid if [ -r $DBA/allmemry.exe ] then # # Display memory utilization # echo "" echo "Memory utilization after database startup:" $DBA/allmemry fi # # Startup the concurrent managers for the $mysid database # (if running Oracle Applications) # set +u if [ -r "$FND_TOP/bin/FNDLIBR" ] then set -u echo "Starting the concurrent managers for the $mysid" \ "database..." startm $mysid exit_status=$? if [ $exit_status -ne 0 ] then mailto \ "backup error - Unexpected error $exit_status from startm for $mysid" fi fi set -u fi echo "" echo "" now=`date '+%m/%d/%y %H:%M:%S'` echo "------- Done with BACKUP of $mysid database at $now -------"