#!/bin/ksh # Program: backup_db # Purpose: This script backs up the database from one location # to a different location on disk. # Author: Adam Backman # Date Written: 03/09/98 # # Setup the environment # This program requires the creation of a pipe (backpipe) and a # response file (response) in the scripts directory. The pipe # is used to move the backup to the restore without a having to # create a file in between. The response file contains the # letter "y" (without quotes) that is needed by the restore # utility. The syntax to make a named pipe is: # mknod p # Setup the environment variables SCRIPTS=${SCRIPTS-/u3/users/adamb/scripts} PIPE=$SCRIPTS/pipedir/backpipe LOG=$SCRIPTS/logs/backup export PIPE LOG SCRIPTS umask 0000 # Test the first argument to make sure it is a valid database name . $SCRIPTS/live/read_registry $1 case $? in 2) echo "Database $1 is not in database registry" exit 1 ;; 3) echo "Database $1 is on $HOST not on this host" exit 1 ;; esac LOG=$LOG$DB.log echo > $LOG echo "Start Backup Process" >> $LOG date >> $LOG # Cleanup any old restore processes xxx=`ps -ef | grep $PIPE$DB | grep _dbutil | cut -c 9-15 2>/dev/null` kill -15 $xxx 2>/dev/null if test ! -s $BKDBDIR/$DB.db then # If the target database does not exist go build one echo >> $LOG echo "Looking for structure description file" >> $LOG echo >> $LOG if test ! -s $BKDBDIR/$DB.st then # Target structure file does not exist echo >> $LOG echo "Structure description "$BKDBDIR/$DB.st" does not exist" >> $LOG echo "Structure description "$BKDBDIR/$DB.st" does not exist" echo "Cannot create void database for backup" >> $LOG echo "Cannot create void database for backup" echo >> $LOG exit 1 else # Target structure file does exist echo >> $LOG echo "Creating void multi volume structure" >> $LOG cd $BKDBDIR prostrct create $BKDBDIR/$DB >> $LOG if [ $? != 0 ] then echo "PROSTRCT FAILED - could not create " $BKDBDIR/$DB >> $LOG echo "PROSTRCT FAILED - could not create " $BKDBDIR/$DB exit 1 fi fi # End of Target structure descripture testing fi # End of Target database file checking # Check to see if $PIPE exists and if not exit with a message and # error code. if test ! -r $PIPE$DB then echo "Making pipe" $PIPE$DB >> $LOG /etc/mknod $PIPE$DB p 2>> $LOG if [ $? != 0 ] then MESG='backpipe not Created - Backup not completed' echo echo $MESG >> $LOG echo $MESG echo exit 1 fi fi # Everything exists now time to do the backup echo $DB_DIR/$DB " to " $BKDBDIR/$DB >> $LOG rm -f $BKDBDIR/$DB.lk 2>/dev/null prorest $BKDBDIR/$DB $PIPE$DB < $RESP >/dev/null & sleep 5 # Let the prorest start before starting the backup proutil $DB_DIR/$DB -C busy >/dev/null if [ $? -eq 0 ] then echo "Starting offline backup" >> $LOG probkup $DB_DIR/$DB $PIPE$DB >> $LOG else echo "Starting online backup" >> $LOG probkup online $DB_DIR/$DB $PIPE$DB >> $LOG fi if [ $? -eq 0 ] then echo "Backup Successful - Procedure complete" >> $LOG date >> $LOG exit 0 else echo "*********** Backup Failed ***********" echo "*********** Backup Failed ***********" >> $LOG echo "Check " $BKDBDIR/$DB.lg and $DB_DIR/$DB.lg " for errors" echo "Check " $BKDBDIR/$DB.lg and $DB_DIR/$DB.lg " for errors" >> $LOG exit 1 fi # Procedure complete