Cover V05, I08
Article
Figure 1
Figure 2
Listing 1
Listing 2

aug96.tar


Listing 1: dump_db.ksh -- The main backup script

#!/bin/ksh
#
# Script set to backup the database using
# Sybase dump directly to the TZ877 Tape
# Changer. The Digital utility mcutil(1)
# is used to manipulate the media changer.
#
# dump_db.ksh: The main, cron-called script
#              that creates pipe and starts
#              the Sybase dump down one end
#              of the pipe and starts an awk
#              script on the other end to
#              watch for a tape eject

#
# Set needed environment variables
#
# Sybase variables
#
SYBASE=/usr/sybase; export SYBASE
SERVER=SERVER1; export SERVER
DATABASE=PROD_DB; export DATABASE
PASSWORD=secret; export PASSWORD

BACKUP_DIR=${SYBASE}/backups
LOGFILE=${BACKUP_DIR}/dump_db.`date +"%a"`.out
PIPE=${BACKUP_DIR}/backup_pipe

#
# Tape device and its capacity to dump to
#
DEVICE=/dev/nrmt0h; export DEVICE
CAPACITY=20971520; export CAPACITY

#
# Timestamp backup start via logger(1)
#
logger -p local1.info "Backup begun"

#
# Determine the starting tape based on the day
# of the week and insert that tape into drive 0
#
DAY=`date +"%a"`

case ${DAY} in
Mon)
TAPE=0
;;
Tue)
TAPE=2
;;
Wed)
TAPE=4
;;
Thu)
TAPE=6
;;
Fri)
TAPE=1
;;
Sat)
TAPE=3
;;
Sun)
TAPE=3
;;
esac

export TAPE

#
# Assign "starting" tape in the backup set
#
SET=${TAPE}"-"

#
# Check the status of the tape drive and
# position the proper starting tape
#
SLOT=`expr 256 + ${TAPE}`
DRIVE_STATUS=`mcutil -e d:0 | awk '{print $3}' | \
awk 'FS="," {print substr($1,2)}'`

case ${DRIVE_STATUS} in
empty)
mcutil -m s:${TAPE} d:0
;;
full)
SOURCE=`mcutil -e d:0 | awk '{print $3}' | \
awk 'FS="," {print substr($3,8,3)}'`
if [ ${SOURCE} != ${SLOT} ]
then
mcutil -m d:0 s:`expr ${SOURCE} - 256`

mcutil -m s:${TAPE} d:0
fi
;;
esac

#
# if the pipe exists, reuse it, otherwise
# create a new one.
#
if test ! -p "${PIPE}"
then
rm -f ${PIPE}
mknod ${PIPE} p
fi

#
# execute the awk(1) script to parse output
#
awk -v SCRIPT="${BACKUP_DIR}/vol_change.ksh" '
/@session_id/ {
SESSION_ID=substr($3,1,length($3)-1)
}
/<new_volume_name>/ {
print SESSION_ID | SCRIPT
}
' < ${PIPE} &

#
# execute the backup process with stdout tee'ed
# into the pipe
#
${SYBASE}/bin/isql -Usa -P${PASSWORD} -S${SERVER} <<
ENDSQL | \ tee -a ${PIPE} > ${LOGFILE}
dump database ${DATABASE} to '${DEVICE}' with capacity=${CAPACITY}, init
go
ENDSQL

#
# Determine the "ending" tape in the backup set and
# kbytes dumped
#
SOURCE=`mcutil -e d:0 | awk '{print $3}' | \
awk 'FS="," {print substr($3,8,3)}'`
SET=${SET}`expr ${SOURCE} - 256`

KBYTES=`awk '/kilobytes DUMPed/ {kbytes=$6} END {print kbytes}' ${LOGFILE}`

#
# Unload the final tape
#
mcutil -m d:0 s:`expr ${SOURCE} - 256`

#
# Timestamp backup completion, tapes used, and amount
# backed up via logger(1)
#
logger -p local1.info "Backup Completed, Tapes
${SET}, ${KBYTES} kilobytes DUMPed "

exit 0

# End of File