From: cwa@leia (cwakins@rmc.com)
Subject: Archive to disk script
Date: 11 Feb 1994 13:58:06 -0500


I've had several requests to post our solution to the archive to disk
problem, so here it is.  While this works well for us and has for a
long time now, you get no warranty, so check this code carefully for
compatibility with your system!  

Some notes:

	The tunables.sh program set a number of environmental variables
	which may be used by several programs.

	I used GNU zip, because it gets way better compression -- in
	the 80-90% range for one of our archived systems.

	We DECnet copy the compressed archive file to a remote node
	for offsite backup.  This could easily be FTP or something
	else.

     ______________________________________________________________
     | Clem Akins                  Standard Disclaimers Apply      |
     | Reynolds Metals Co.         ("Cutesy" ones, too!)           |
     | Alloys Plant (MS #59)                                       |
     | 3509 East 2nd St            Internet: cwa@leia.rmc.com      |
     | Muscle Shoals, Al           Telephone: (205) 386-6783       |
     | USA    35661-1256           Facsimile: (205) 386-6831       |
     |                 "Climb High, Cave Deep!"                    |
     |_____________________________________________________________|

       O   /
        \ /
Here ----\---- Snip Here --------- Snip Here --------- Snip Here --------- Snip
        / \
       O   \
#!/bin/sh5
#######################################################################
#
#	DATE CREATED: 06/15/91
#
#	PURPOSE:
#	A script to perform a complete backup of the OnLine system
#	database.
#
#	Logic:
#		force checkpoint
#		## force completion of current log
#		determine pid of log archiver and kill it
#		move log file to Old log file and create new log
#		start log archiver program
#		perform level 0 backup 
#		compress archive
#		copy archive to a remote node
#
#	ENVIRONMENT EXPECTED:
#	Written on DEC Ultrix (BSD variant).
#	The following variables are defined in tunables.sh:
#		LOGS - dir to hold std out and std err
#		INFORMIXDIR - dir with informix progs
#		LOGFILE - informix logical log tape device (from tbconfig)
#		ARCHIVE_DIR - dir to hold the archive file
#		    Note:  this *must* be bigger than the entire dbspace!
#		           If you run out of space, the archive program
#		           will fill up your LOGS dir with error messages!
#		ARCHIVE_FILE - name of the archive device (from tbconfig)
#		BACKUP_NODE - name of computer to store archive on
#		BACKUP_ACCOUNT - name of secure account on that node
#		BACKUP_PASSWORD - password for secure account
#		ALT_BACKUP_DIR - dir on BACKUP_NODE to store archive file
#
#	ARGUMENTS RECEIVED: None
#
#	POSSIBLE ERROR EXIT STATUS:
#	Returns: 0 for success, else return code of most recent command
#
#########################################################################
#
echo "running tunables.sh..."
. /usr/local/tunables.sh

# re-direct stdout and stderr to a log file
EXEC_LOGFILE=$LOGS/`basename $0`.log
exec 1>> $EXEC_LOGFILE 2>&1

echo `date` "Beginning On-Line Backup; user id of " `id`

cd $LOGS		# run from here
THESTATUS="$?"
if [ "$THESTATUS" -ne 0 ]
then
    echo "$LOGS DOES NOT EXIST.  ARCHIVE ABORTED"
    exit 1
fi

USERID=`id`
USERID=`echo $USERID | cut -f2 -d"(" | cut -f1 -d")"`
if [ $USERID != "informix" ]
then
    echo "$USER ATTEMPTED TO RUN `basename $0`"
    exit 1
fi

INFORMIXBIN=$INFORMIXDIR/bin

echo "Forcing a checkpoint..."
${INFORMIXBIN}/tbmode -c
THESTATUS=$?
if [ $THESTATUS != 0 ]
then
    echo "Error from checkpoint was $THESTATUS"
    exit $THESTATUS
fi

sleep 10		# let prior step complete...

#	use OnLine utility to determine pid 
log_pid=`${INFORMIXBIN}/tbstat -u | grep '.*-A-' | cut -c18-23`
if [ -n "$log_pid" ]    #### variable is non-zero
then
	echo "Stopping log archiver process pid = $log_pid"
	${INFORMIXBIN}/tbmode -z $log_pid 
	sleep 10
	kill -9 $log_pid
fi

o_log_pid=$log_pid
while [ -n "$o_log_pid" ] 
do
	echo "waiting for tbtape to exit...  PID  $o_log_pid"
	sleep 5
	o_log_pid=`${INFORMIXBIN}/tbstat -u | grep '.*-A-' | cut -c18-23`
done

#	assumes directory set (above)
#	nohup creates local file nohup.out
echo "Cleaning out the old logical log..."
touch ${LOG_FILE}
cat /dev/null > ${LOG_FILE}

echo "Restarting log archiver..."
nohup ${INFORMIXBIN}/tbtape -c &

echo "Creating new archive file..."
cd ${ARCHIVE_DIR}
touch ${ARCHIVE_FILE}
cat /dev/null > ${ARCHIVE_FILE}

echo "Running backup utility..."
####  run the backup utility, answering questions
${INFORMIXBIN}/tbtape -s <<END

0
END

THESTATUS=$?
if [ $THESTATUS != 0 ]
then
    echo "WARNING.  NO TBTAPE PROCESS.  Error from archive was $THESTATUS"
    exit $THESTATUS
fi

####  compress the archive and make a copy on another node
# uses gnu zip, available by ftp in prep.ai.mit.edu:/pub/gnu
/usr/local/tools/gzip -fv -5 $ARCHIVE_FILE

THESTATUS=$?
if [ $THESTATUS != 0 ]
then
    echo "Error from compress of archive file was $THESTATUS"
    exit $THESTATUS
fi
#
# this uses the DECnet copy command.  It could be written to use an
# ftp or other network copy command.
#
echo "dcp -iv ${ARCHIVE_FILE}.gz ${BACKUP_NODE}/${BACKUP_ACCOUNT}/${BACKUP_PASSWD}::${ALT_BACKUP_DIR}archive.gz"

dcp -iv ${ARCHIVE_FILE}.gz ${BACKUP_NODE}/${BACKUP_ACCOUNT}/${BACKUP_PASSWD}::${ALT_BACKUP_DIR}archive.gz

THESTATUS=$?
if [ $THESTATUS != 0 ]
then
    echo "Error from archive file copy to ${BACKUP_NODE} was $THESTATUS"
    exit $THESTATUS
fi

#### exit program with success status
echo "Another successful archive and backup"
exit 0
       O   /
        \ /
Here ----\---- Snip Here --------- Snip Here --------- Snip Here --------- Snip
        / \
       O   \
