Listing 1: archive.sh--The master archiving script
# archive.sh
INFORMIXDIR=/usr/informix; export INFORMIXDIR
TBCONFIG=tbconfig; export TBCONFIG
DATE=/bin/date; export DATE
MV=/bin/mv; export MV
RM=/bin/rm; export RM
CP=/bin/cp; export CP
CHMOD=/bin/chmod; export CHMOD
CHOWN=/bin/chown; export CHOWN
CHGRP=/bin/chgrp; export CHGRP
GREP=/bin/egrep; export GREP
PWD=/usr/ed/arch; export PWD
AWKTYPE=/usr/bin/awk; export AWKTYPE
BACKARCDIR=/apps/backup/archive; export BACKARCDIR
BACKLOGDIR=/apps/backup/logs; export BACKLOGDIR
COMPRESS=/usr/bin/compress; export COMPRESS
if [ $# -ne 1 ]
then
echo "Usage: archive.sh <0 for archive 0> <1 for archive 1> <2 for achive >"
exit 1
fi
if [ $1 -ne 0 -a $1 -ne 1 -a $1 -ne 2 ]
then # choose which archive
echo "Usage: archive.sh <0 for archive 0> <1 for archive 1> <2 for achive 2>"
exit 1
fi
LOGFILE=$PWD/logs/archive"$1".log
BACKARC=$BACKARCDIR/arc"$1"
$DATE > $LOGFILE # initialize log file
$PWD/Ktbtape.sh # stop logical logging
sleep 120 # sleep long enough for last logical log to complete
# setup the archive and logical log files
if test -w $BACKARC
then
$CP /dev/null $BACKARC
$RM $BACKARCDIR/*.Z
else
$CP /dev/null $BACKARC
$CHOWN informix $BACKARC
$CHGRP informix $BACKARC
$CHMOD 644 $BACKARC
$RM $BACKARCDIR/*.Z
fi
# change the tape device to the correct file name
cat $INFORMIXDIR/etc/$TBCONFIG|$AWKTYPE '
{
if($1 == "TAPEDEV") #check for archive tape device
$2=backarc
printf("%s\n", $0)
} ' backarc=$BACKARC > $INFORMIXDIR/etc/tbarctmp.int
$MV $INFORMIXDIR/etc/tbarctmp.int $INFORMIXDIR/etc/$TBCONFIG
# do the actual archive
$INFORMIXDIR/bin/tbtape -s < $PWD/arch_"$1" \
1>>$LOGFILE 2>/dev/null
if [ $? -ne 0 ]
then # quit if tbtape command fails
exit 1
fi
# once the archive is complete change log tape device to correct file
pid=`$GREP "Program over" $LOGFILE`
if [ "$pid" != "" ]
then
BACKLOG=$BACKLOGDIR/logs1
cat $INFORMIXDIR/etc/$TBCONFIG|$AWKTYPE '
{
if($1 == "LTAPEDEV") #check for log tape device
$2=backarc
printf("%s\n", $0)
} ' backarc=$BACKLOG > $INFORMIXDIR/etc/tblogtmp.int
$MV $INFORMIXDIR/etc/tblogtmp.int $INFORMIXDIR/etc/$TBCONFIG
$CP /dev/null $BACKLOG
$CP /dev/null $BACKLOGDIR/logs2
$COMPRESS $BACKARC
# backup or remote copy the archive right here
fi
# this only happens if the archive fails for some reason
pid=`$GREP "Program cancel" $LOGFILE`
if [ "$pid" != "" ]
then
BACKLOG=$BACKLOGDIR/logs2
cat $INFORMIXDIR/etc/$TBCONFIG|$AWKTYPE '
{
if($1 == "LTAPEDEV") # check for log tape device
$2=backarc
printf("%s\n", $0)
} ' backarc=$BACKLOG > $INFORMIXDIR/etc/tblogtmp.int
$MV $INFORMIXDIR/etc/tblogtmp.int $INFORMIXDIR/etc/$TBCONFIG
$CP /dev/null $BACKLOG
fi
$PWD/Stbtape.sh # Re-start logical logging
|