#!/bin/sh # Program: cp_full_ai # Purpose: This script backs-up all full AI extents to the backup # directory and initializes the extents for reuse # Syntax: cp_full_ai # # Author: Adam Backman, Aaron Tetlow # Date Written: 03/09/98 # # Mods: Added double quotes around find command being executed via rexec # due to the command not running properly. Aaron. # Setup the generic variables SCRIPTS=${SCRIPTS-/u3/users/adamb/scripts} LOG=$SCRIPTS/logs BKLOG=$SCRIPTS/logs/archive INPROCESS=$SCRIPTS/tmp DOW=`date +%a` export SCRIPTS LOG BKLOG INPROCESS DOW # Do Operating system dependent aliasing case `uname -s` in HP-UX) alias rsh=remsh ;; esac # Read the registry to setup the database specific variables . $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 if [ $BKAIDIR = "NO_AI" ] then exit 0 fi LOG=$LOG/swai$DB INPROCESS=$INPROCESS/swai$DB.inprocess # Exit subroutine # This subroutine takes three parameters. # "Error code" - This gives the status the program will exit with # 0 - OK, not 0 - error # "Message" - The message you want in the log file # "Keep_file" - This parameter is optional. It allows you to exit # but leave the swai.inprocess file intact exit_code() { echo >> $LOG if [ $1 != 0 ] # If it is a bad exit code display "ERROR" header then echo "###### ERROR ###### ERROR ###### ERROR ######" >> $LOG echo >> $LOG fi echo $2 >> $LOG # Regardless of the exit code display a message if [ $1 != 0 ] # If it is a bad exit code display "ERROR" footer then echo >> $LOG echo "###### ERROR ###### ERROR ###### ERROR ######" >> $LOG fi echo >> $LOG ## Error mailing code if [ $1 != 0 ] then mailx -s "Error in swai for $DB" $WHOAMI < $LOG else mailx -s "swai for $DB Successful" $WHOAMI < $LOG fi if [ x$3 = "x" ] then rm $INPROCESS fi exit $1 } # Logging subroutine # One parameter - The message you want in the log file log_code() { echo >> $LOG echo $1 >> $LOG echo >> $LOG } # Check if another SWAI is running if test -s $INPROCESS # If the inprocess file exists then # Give a message to the screen and exit echo echo "SWAI for "$DB" already in process" exit 1 else # Archive the the log file and create a new one mv $LOG.* $BKLOG 2>/dev/null LOG=$LOG.$DOW log_code "Starting SWAI process for "$DB date >> $LOG date > $INPROCESS fi # Check to see if the backup node is available ping $BKUPNODE 1024 2 >/dev/null 2>/dev/null if [ $? != 0 ] then exit_code "1" "The backup node "$BKUPNODE" is not available" else log_code "Backup node is available for transfer" fi # If there are less than 9 full extents switch extents so that the busy # extent is marked as full and can be backed up FULLAIEXT=`rfutil $DB_DIR/$DB -C aimage extent list | grep -i full | wc -l` if [ $FULLAIEXT -lt 9 ] then log_code "Switching AI extents for $DB" _rfutil $DB_DIR/$DB -C aimage extent new else log_code "All extents full for $DB - No AI switch" fi if [ $? != 0 ] then exit_code "1" "Could not switch after image extents" else log_code "AI switch for $DB_DIR/$DB complete" fi # Copy all extents marked full to the backup directory and make # them as empty extents so that it can be reused FIRST_LOOP="yes" while true do EXTENT_NAME=`_rfutil $DB_DIR/$DB -C aimage extent full` if [ $? = 0 ] then # Full extent available to copy # Get the directory and file name to be copied from DAY_TIME=`date "+%a%H%M%S"` # Get current day and time # Copy full ai file to backup directory and then compress them if [ $FIRST_LOOP = "yes" ] then log_code "removing ai file(s) older than 3 days" find $BKAIDIR/$DB* -mtime 3 -exec \rm {} \; 2>/dev/null >/dev/null find $BKAIDIR/$DB* -mtime 4 -exec \rm {} \; 2>/dev/null >/dev/null find $BKAIDIR/$DB* -mtime 5 -exec \rm {} \; 2>/dev/null >/dev/null fi log_code "doing copy of $EXTENT_NAME to $BKDIR/$DB.$DAY_TIME" cp $EXTENT_NAME $BKAIDIR/$DB.$DAY_TIME if [ $? != 0 ] # Error if copy failed then exit_code "1" "Copy of AI file to backup directory failed" fi # Copy the extent to the backup node if [ $FIRST_LOOP = "yes" ] # First, clean up last weeks extents then # We will keep 3 days of AI history then remove it. log_code "removing ai file(s) older than 3 days from $BKUPNODE:$RMTAIDIR" rsh $BKUPNODE "find $RMTAIDIR/$DB* -mtime 3 -exec \rm {} \;" 2>/dev/null >/dev/null rsh $BKUPNODE "find $RMTAIDIR/$DB* -mtime 4 -exec \rm {} \;" 2>/dev/null >/dev/null rsh $BKUPNODE "find $RMTAIDIR/$DB* -mtime 5 -exec \rm {} \;" 2>/dev/null >/dev/null FIRST_LOOP="no" fi log_code "Compressing $BKAIDIR/$DB.$DAY_TIME in background" compress $BKAIDIR/$DB.$DAY_TIME & log_code "Copying $EXTENT_NAME to $BKUPNODE:$RMTAIDIR/$DB.$DAY_TIME" rcp -p $EXTENT_NAME $BKUPNODE:$RMTAIDIR/$DB.$DAY_TIME if [ $? != 0 ] then exit_code "1" "remote copy of $EXTENT_NAME failed" else log_code "Remote copy of $EXTENT_NAME successful" fi # Roll forward AI file on the backup node RETCODE=`rsh $BKUPNODE $SCRIPTS/live/roll_forward_ai $RMTDBDIR/$DB $RMTAIDIR/$DB.$DAY_TIME` if [ $RETCODE != 0 ] then exit_code "1" "Roll forward failed" else log_code "Roll forward of $RMTAIDIR/$DB.$DAY_TIME successful." fi rsh $BKUPNODE "compress $RMTAIDIR/$DB.$DAY_TIME &" # Make the extent empty for reuse _rfutil $DB_DIR/$DB -C aimage extent empty $EXTENT_NAME 2>/dev/null 1>/dev/null if [ $? != 0 ] then exit_code "1" "Could not empty $EXTENT_NAME" else log_code "Extent $EXTENT_NAME marked as empty" fi else # No more full extents date >> $LOG exit_code "0" "No full extents - procedure complete" break fi done # end of loop