Subject: Archive Informix 5.03 dbspaces to HP 6 tape shuttle drive
Date: Mon, 23 Dec 1996 10:18:00 +0200
From: johank@olfitra.com.na (Johan Kotze)
Organization: Model Supermarkets

Hi

In order to archive our 10 GB DBSPACE to a HP shuttle tape drive we had
to make some modifications to Carlos Godines' original script.

This modified script works very well and I hope somebody can use it.

Regards

Johan Kotze
johank@olfitra.com.na

#!/bin/sh
# 	dbarchive: automatic level 0,1,2 archive
#	original author: Carlos Godinez/INFORMIX
#	@(#)dbarchive	1.3	/usr/informix/backup/sh/s.dbarchive
# @(#)dbarchive	1.3   /usr/informix/backup/s.dbarchive
#	last update:8/25/90 @ 11:37:06
#
#	-----------------------------------------------------------------
#
#	Modifications for Informix 5.03 UC1
#
#	Tape device: HP C1553A DDS-2 6-tape shuttle
#
#	Author: Johan Kotze - Model Supermarket, Namibia
#
#	Notes:
#
#	1. As our Informix lies on a seperate filesystem we had to use
#	   the ln -s command to link to the tape device.
#
#	2. The level0, level1 and level2 files which lie in
#	   $INFORMIXDIR/backup contains 6 identical entries specifying
#	   the HP tape device name.
#
#	3. The tape unload command is issued when tbtape asks for the next
#	   tape.
#
#	4. The original variable NEXTTAPE did not conform with the output
#	   given by tbtape on our version of Informix.
#
#	5. Backup log shows the number of tapes used for the archive.
#
#	6. Remove the 'who am i' command if running out of the cron.
#
#	=====================================================================
#
# Set informix directory
INFORMIXDIR=/u1/informix;export INFORMIXDIR

TBCONFIG=tbconfig;export TBCONFIG

# Added to insure matching block sizes in "dbarchive" and "dbrestore". MAK
SIZE=`grep "^TAPEBLK" $INFORMIXDIR/etc/tbconfig|awk '{print $2}'`
if [ "${SIZE}" != "16" ];then
echo TAPE BLOCK SIZE IS INCORRECT.. PLEASE RESET THE TAPEBLK TO 16
exit
fi

## Check to see User ID = "informix"
#if [ "`ucb whoami`" != "informix" ]
if [ "`who am i | cut -c1-8`" != "informix" ]
then
	echo "\nUSAGE: $0: Must be executed as User ID = informix\n" >&2
	exit 1
fi

#	test for one parameter and that it is 1, 2, or 3
case "$1" in
	0) LVL=0;;
	1) LVL=1;;
	2) LVL=2;;
#		echo tmp unavailable
#		exit 99;;
	*) echo "\nUSAGE: dbarchive [0|1|2]"
	   exit 2;
esac

#	check that INFORMIXDIR is set
: ${INFORMIXDIR:?"INFORMIXDIR is not set"}

# Set PATH just in case
PATH=$INFORMIXDIR/bin:$PATH; export PATH

# Check for TBCONFIG
: ${TBCONFIG:?"TBCONFIG is not set"}
TBCNFG=$INFORMIXDIR/etc/$TBCONFIG; export TBCNFG

# Check that the system is in On-Line or Quiescent mode
MODE1=`tbstat - | grep "On-Line"`
MODE2=`tbstat - | grep "Quiescent"`
[ -z "$MODE1" -a -z "$MODE2" ] && { echo "\nERROR: OnLine is not On-Line or Quiescent mode"; exit 3; }

# Set dummy tape device from tbconfig
TPLINK=`sed -n '/^TAPEDEV/ s/TAPEDEV//p' $TBCNFG`
[ -z "$TPLINK" ] && { echo "\nERROR: dummy backup device not set"; exit 4; }

# Set environment variables
BUDIR=/u1/informix/backup		# Backup directory
BASETIME=`date +%m%d%R`			# Time stamp for the in/out files
TIMESTAMP=`date "+%D %T"`		# Time stamp for the log file
FILEDEVS=${BUDIR}/level$LVL     	# Name of file containing backup devices

# Mark the file with the number of the day_of_the_week
# This allows seven logs before over-writing
RUNLOG=${BUDIR}/logs/level${LVL}_`date +%w`

# This file will contain the Start and End times
#	of the last 100 archives at ${LVL}
LEVLOG=${BUDIR}/logs/level${LVL}   # GTH

# Check that the file containing device names is readable
[ ! -r "$FILEDEVS" ] && { echo "\nERROR: cannot read ${FILEDEVS}"; exit 5; }

# Set temporary filenames
IN=/tmp/in${BASETIME}			# Feeds keystrokes to tbmonitor
OUT=/tmp/out${BASETIME}			# Holds tbmonitor's output

# Set messages expected from tbmonitor
BCKLVL="'Level $LVL archive is 100 percent completed.'"
NEXTTAPE="'please mount next tape & type Return to continue.'"

# Perform update of statistics
#dbaccess sys /u1/mast/model/bin/update.sql
#echo "Statistics updated ....." > $RUNLOG

# Build input shell on the fly
cat >$IN <<E-O-F
#!/bin/sh
#	input shell

#	read from file and set backup devices
DEVICES="`cat $FILEDEVS`"

# Set devices to \$1, \$2, \$3, (positional parameters)
set \$DEVICES

# Link tape device to first device
DEV=\$1
rm -f $TPLINK 2>/dev/null		# Remove any existing link
ln -s \$DEV $TPLINK 2>/dev/null


# Check for the link
[ "\$?" -ne 0 ] && { echo "\nERROR: link failed"; exit 6; }

# Create the RUNLOG
echo "First tape loaded" >> $RUNLOG

#	answers to tbtape
echo "ac"
sleep 10
echo "\r"
sleep 10
echo "$LVL\r"
sleep 5

# Continue backup in second device if necessary
# Move the next argument into \$1, after all, there are more than 9 devices
shift

#	test for end of backup
grep -s $BCKLVL $OUT
while [ "\$?" -ne 0 ]
do
	sleep 10

	# Test for additional tapes/devices
	grep -s $NEXTTAPE $OUT
	if [ "\$?" -eq 0 ]; then

		# Check for another device
		if [ \$# -gt 0 ]
		then
			# Set next backup device
			eval DEV=\$1
		else
			echo "$0: Ran out of archive devices" >&2
			exit  7
		fi

		# Make the link to the next device
		rm -f $TPLINK

		# Issue tape unload command to move to next tape
		tape unload
		sleep 50

		# Link to next device
		ln -s \$DEV $TPLINK
		[ "\$?" -ne 0 ] && { echo "\nERROR: link failed"; exit 8; }

		# Keep a record of the number of tapes changes
		echo "Change tape" >> $RUNLOG

		# Move the next device into \$1
	 	shift

		# Send a <RETURN> to tbmonitor
		echo "\r\c"

		# Empty the output file
		>$OUT

	fi
	sleep 10
	grep -s $BCKLVL $OUT
done
echo "\ree"
E-O-F

# Make the input file executable
chmod +x $IN

# Perform archive
echo "Archive level $LVL in progress ..."
$IN | tbmonitor > $OUT 2>/tmp/errlist

# Tell the operator we're done
echo "Level $LVL archive is 100 percent completed."

# Keep track of the most current backups
echo "BEGIN: ${TIMESTAMP} END: `date '+%D %T' `" >> ${RUNLOG}
nof_tapes=`grep "tape" ${RUNLOG} | wc -l`
echo "Number of tapes used: $nof_tapes" >> ${RUNLOG}
tail -1 ${RUNLOG} >> ${LEVLOG}
grep ERROR $OUT >> ${RUNLOG}
tail -100 ${LEVLOG} > /tmp/llog$$
mv /tmp/llog$$ ${LEVLOG}

# Grab the archive message from tbmonitor
grep "Archive level:" $OUT

# Remove temporary files
rm -f $IN $OUT

# Print backup log
klp -dcomproom ${RUNLOG}
