Re: FW: Ontape and Shell Script
Posted in 1997
Sean Wong (swong@kato.den.csci.csc.com) wrote:
: If the data volume to be backed up is larger than the tape volume, you =
: will have problem as ontape will actually rewind the tape and write from =
: the beginning again!
We have a perl script here which handle multiple tapes, errors, or
whatever. I'll post a copy here on an un-supported basis. It works
with Informix ODS 6 and 7 on HP-UX 9 and 10.
There are two components, a ksh and perl script.
Piece 1 - ksh:
#!/usr/bin/ksh
###############################################################################
#
# db_ontape
#
###############################################################################
#
# Set traps to return fail code on interrupt
#
trap "exit 1" KILL INT HUP
function UsageMessage
{
date
print "Usage: '$P' -e <INSTANCE | nosap> -t <TAPE FILE NAME> -l <ONTAPE ARCHIVE LEVEL (0,1,2)> [-p <ENVIRONMENT SET SCRIPT>]"
}
error_proc ()
{
MSG=$1
echo " "
echo "db_ontape | Fatal Error Encountered: $MSG"
echo "db_ontape | Sending EMail Error Notification to sapgap/dbagap"
mailx -s "db_ontape Error (`hostname`) - $MSG" <an email address> << EOF
Host=`hostname`
Instance=$ENV_TYPE
Msg=$MSG
EOF
#echo "db_ontape | Sending OpC Message"
#/opt/OV/bin/OpC/opcmsg object=DB_Backup severity=critical msg_text="$MSG" application="SAP R/3" msg_grp=General
if [ "$PROD_SYS" = "Y" ]; then
echo "db_check | Sending Pager Notification"
page_dbagap db_ontape `hostname` << EOF
db_ontape Critical Error
Msg=$MSG
Host=`hostname`
Instance=$ENV_TYPE
EOF
fi
echo "db_ontape | Exiting - \\c"
date
exit 1
}
#
# Initializations
#
P=$(basename $0)
PGMPATH=$0
PGMDIR=${0%/$P}
export PATH=$PGMDIR:/usr/local/bin:$PATH
export HOST=`hostname`
export LOCATION=`nslookup $(hostname) | grep Name: | awk '{ \\
split($2,array,".")
print array[2]
}'`
ID=`/usr/bin/whoami`
echo "------------------------------------------------------------------------"
print "$P | Starting - \\c"
date
print "$P | PGMPATH=$PGMPATH PGMDIR=$PGMDIR LOCATION=$LOCATION ID=$ID"
print "PATH=$PATH"
#
# Get command line options
#
while getopts :e:t:l:p: option
do case $option in
e) ENV_TYPE=$OPTARG;;
t) TAPEFILE=$OPTARG;;
l) ARCLEVEL=$OPTARG;;
p) ENVSCRIPT=$OPTARG;;
:) print "$(basename $0): -$OPTARG requires a value"
exit 2;;
\\?) print "$(basename $0) unknown option $OPTARG"
UsageMessage
exit 2;;
esac
done
export ENV_TYPE
print "$P | ENV_TYPE=$ENV_TYPE TAPEFILE=$TAPEFILE ARCLEVEL=$ARCLEVEL ENVSCRIPT=$ENVSCRIPT"
#
# Edits
#
if [ -z "$TAPEFILE" ]; then
UsageMessage
exit 1
fi
if [ -z "$ARCLEVEL" ]; then
UsageMessage
exit 1
fi
if [ -z "$ENV_TYPE" ]; then
UsageMessage
exit 1
fi
#
# Main
#
if [[ "$ID" != "root" && "$ID" != "informix" ]];then
error_proc "db_ontape must be run be either root or informix"
fi
if [ $ENV_TYPE = nosap ]; then
if [ ! -z $ENVSCRIPT ];then
print "$P | Executing . $ENVSCRIPT"
. $ENVSCRIPT
if [ $? != 0 ];then
error_proc "Error running user specified ENV script"
fi
print "$P | Environment after $ENVSCRIPT"
env
else
print "$P | Executing . /etc/profile"
. /etc/profile
print "$P | Executing . /etc/profile.d/*"
PROFILE_FRAGMENT_DIR=/etc/profile.d
if [ -d $PROFILE_FRAGMENT_DIR ]
then
for FRAGMENT in `/bin/ls $PROFILE_FRAGMENT_DIR`
do
if [ -x ${PROFILE_FRAGMENT_DIR}/${FRAGMENT} \\
-a -r ${PROFILE_FRAGMENT_DIR}/${FRAGMENT} \\
-a -f ${PROFILE_FRAGMENT_DIR}/${FRAGMENT} ]
# these files must be readable AND executable
then
. ${PROFILE_FRAGMENT_DIR}/${FRAGMENT}
RETURN_VALUE=$?
if [ $RETURN_VALUE -ne 0 ]
then
echo "# ${PROFILE_FRAGMENT_DIR}/${FRAGMENT} exited abnormally"
echo "# with value $RETURN_VALUE"
echo "###########################################################"
fi
fi
done
fi
print "$P | Environment after /etc/profile"
env
export ERROR_EMAIL="<an email address>"
fi
else
. dbeset $ENV_TYPE
if [ $? != 0 ];then
error_proc "dbeset Error"
fi
export ERROR_EMAIL="<an email address>"
fi
print "$P | INFORMIXDIR=$INFORMIXDIR"
if [ -z "$ENV_TYPE" ]; then
error_proc "INFORMIXDIR is null - env var error"
fi
#
# Check for Informix active
#
onstat - | grep "On-Line"
if [ $? != 0 ];then
error_proc "Informix not On-Line"
fi
#
# Check for TAPEDEV set to /dev/null
#
onstat -c | grep ^TAPEDEV | grep /dev/null
if [ $? = 0 ];then
error_proc "TAPEDEV set to /dev/null"fi
#
# Check for other db_ontapes executing
#
PCNT=`ps -efuinformix | grep "db_ontape.pl" | grep -v grep | wc -l `
echo "db_ontape | Total number of db_ontape running: $PCNT"
if [ $PCNT -gt 0 ];then
ps -efuinformix | grep "db_ontape.pl" | grep -v grep
error_proc "db_ontape | Another db_ontape.pl Already running"
exit 1
fi
#
# Start perl pgm
#
export PATH=$PGMDIR:$PATHprint "PATH=$PATH"
#####################################################################
# Start - Code to stop SAP before archive
#
grep $INFORMIXSERVER /usr/local/sap/tools/db_bounce_sap.cfg
if [ $? = 0 ];then
echo "db_ontape | Issuing r3_auto_shutdown to stop SAP"
r3_auto_shutdown $ENV_TYPE r3
if [ $? != 0 ];then
error_proc "r3_auto_shutdown non-zero RC"
fi
echo "db_ontape | r3_auto_shutdown successful completion"
fi
#
# End - Code to stop SAP before archive
#####################################################################
if [ "$ID" = "informix" ];then
db_ontape.pl $ARCLEVEL $TAPEFILE
else
su informix -c "db_ontape.pl $ARCLEVEL $TAPEFILE"
fi
LASTRC=$?
print "$P | db_ontape.pl RC=$LASTRC"
if [ $LASTRC != 0 ];then
if [ $LASTRC = 1 ];then
print "$P | $P.awk failed - exiting"
exit 1
fi
if [ $LASTRC = 202 ];then
print "$P | $P.awk failed - Rerunning - Executing db_ontape_rerun_auto $ENV_TYPE $TAPEFILE $ARCLEVEL after sleeping 60"
sleep 60
db_