#! /bin/sh # # $DBA/creback # # Creates a script to backup files for a given database. # # Also creates a script (restore_xxx) which can be used to restore files # for a database (where xxx is the Oracle SID of the database) # # $1 must be the Oracle SID of the database to create a backup script for # # $2 specifies the type of backup; It must be one of: "COLD", "HOT", or # "HOTALL". # # $3 specifies whether the database files are on raw partitions (RAW), or # on filesystems (FS). # # $4 specifies the mode of backup; It must be one of: "CONSECUTIVE", # "BATCHBEGIN", "BATCHEND", or "CTRL". # # $5 specifies the type of backup destination; It must be one of: "DISK" # or "TAPE" # # $6 specifies the backup destination device or filesystem specification. # # $7 specifies the backup destination device (for non-Batch CTRL file # backups only) # # Last Change 02/21/97 by Brian Lomasky to modify all parameter values. # Last Change 07/09/96 by Brian Lomasky to allow hot backups. # USAGE="Usage: creback " ctrl_dev=x if [ $# -eq 7 ]; then ctrl_dev=$7 else if [ $# -ne 6 ]; then echo $USAGE exit 2 fi fi mysid=`fixcase $1` bkuptype=`echo $2 | tr '[a-z]' '[A-Z]'` raw_fs=`echo $3 | tr '[a-z]' '[A-Z]'` mode=`echo $4 | tr '[a-z]' '[A-Z]'` destdev=`echo $5 | tr '[a-z]' '[A-Z]'` destfs=$6 echo "" case $mode in CONSECUTIVE) ;; BATCHBEGIN) ;; BATCHEND) ;; CTRL) ;; *) echo "Bad mode parameter: $mode" echo $USAGE exit 2 ;; esac case $raw_fs in FS) ;; RAW) ;; *) echo "Bad raw_fs parameter: $raw_fs" echo $USAGE exit 2 ;; esac case $destdev in DISK) ;; TAPE) ;; *) echo "Bad destdev parameter: $destdev" echo $USAGE exit 2 ;; esac case $bkuptype in COLD) echo "Creates a sql script file which, when executed," \ "will backup all files" echo "for database $mysid to $destfs" passtype=COLD ;; HOT) case $mode in CONSECUTIVE) echo "Creates a sql script file which, when" \ "executed, will HOT backup all files" echo "for database $mysid to $destfs" passtype=HOT ;; BATCHBEGIN) echo "Creates a sql script file which, when" \ "executed, will set the BEGIN BACKUP" echo "status for all tablespaces in the HOT" \ "backup for database $mysid" passtype=HOTBEGIN ;; BATCHEND) echo "Creates a sql script file which, when" \ "executed, will set the END BACKUP" echo "status for all tablespaces in the HOT" \ "backup for database $mysid" passtype=HOTEND ;; CTRL) echo "Creates a sql script file which, when" \ "executed, will switch logfiles and" echo "backup the control files for database" \ "$mysid" passtype=HOTCTRL ;; *) echo "Bad mode parameter for HOT: $mode" echo $USAGE exit 2 ;; esac ;; HOTALL) case $mode in CTRL) echo "Creates a sql script file which, when" \ "executed, will switch logfiles and" echo "backup the control files for database" \ "$mysid" passtype=HOTALLCTRL ;; *) echo "Bad mode parameter for HOTALL: $mode" echo $USAGE exit 2 ;; esac ;; *) echo "Bad bkuptype parameter: $bkuptype" echo $USAGE exit 2 ;; esac echo "" # No restore file created, unless we're processing all files do_restore=0 if [ "$mode" = "CONSECUTIVE" -o "$mode" = "BATCHBEGIN" ] then # Create restore file only if copying to and from filesystems if [ "$raw_fs" = "FS" -a "$destdev" = "DISK" ] then echo "Creates restore_$mysid script to restore disk" \ "backup to all filesystems" do_restore=1 else echo "(No restore script created due to using raw" \ "partitions or tape)" fi fi echo "" SID=$mysid . define sqlplus -s / @$DBA/creback $ORACLE_SID $passtype $raw_fs $destfs $do_restore \ $destdev $ctrl_dev if [ ! -r bkup_$mysid.lst ] then echo "creback: Error - No bkup_$mysid.lst file found" exit 2 fi trunc bkup_$mysid.lst # # Change all of the "?/" in the bkup file to the definition of # $ORACLE_HOME/ # sed s#?/#$ORACLE_HOME/#g bkup_$mysid.lst > bkup_$mysid chmod 770 bkup_$mysid if [ ! -r bkup_$mysid ] then echo "creback: Error - No bkup_$mysid file was found" exit 2 fi if [ ! -s bkup_$mysid ] then echo "creback: Error - A zero-length bkup_$mysid file was found" exit 2 fi rm bkup_$mysid.lst # # In the case of exception backups (for backup filesystems greater than # 4GB in size, and so which had to be split into 2 filesystems), run the # fix_bkup script which will fix this # fix_bkup $mysid if [ $do_restore -eq 1 ] then if [ ! -r restore_$mysid.lst ] then echo "creback: Error - No restore_$mysid.lst file found" exit 2 fi trunc restore_$mysid.lst # # Change all of the "?/" in the restore file to the definition of # $ORACLE_HOME/ # sed s#?/#$ORACLE_HOME/#g restore_$mysid.lst > restore_$mysid chmod 770 restore_$mysid if [ ! -r restore_$mysid ] then echo "creback: Error - No restore_$mysid file was found" exit 2 fi if [ ! -s restore_$mysid ] then echo "creback: Error - A zero-length restore_$mysid file was" \ "found" exit 2 fi # # In the case of exception restores (for backup filesystems # greater than 4GB in size, and so which had to be split into 2 # filesystems), run the fix_rest script which will fix this. # Also, remove null file copies. # fix_rest $mysid fi if [ -r restore_$mysid.lst ] then rm restore_$mysid.lst fi echo "Created bkup_$mysid which can be used to backup database $mysid..." if [ $do_restore -eq 1 ] then echo "Created restore_$mysid which can be used to restore database" \ "$mysid..." fi