dbexport for backups
Posted in 1994
Topics: Migration, Import/Export & Data Conversion, Jobs, Consulting & Announcements
These scripts were written for SCO Unix They may not be the
latest versions. Consequently, there may still be a couple of
bugs. The general idea is that the whole file system should
be backup up on a single tape. I have not reviewed the scripts
for a while, but I think that there must be enough scratch space
to hold the entire contents of the largest database. The script
could be modified to remove this constraint. Files are included
as the output of the more command:
::::::::::::::
admin-ni.sh
::::::::::::::
PATH=${HOME}/etc:${PATH}
INFORMIXDIR=`var.sh informix`TBCONFIG_LIST=`var.sh tbconfig`
PATH=${PATH}:${INFORMIXDIR}/bin
if [ "$DEBUG" != "SKIP REBOOT" ]
then
if [ "$TBCONFIG_LIST" != "" ]
then
#
# First: Kill the Informix Server, and restart it.
#
for TBCONFIG in ${TBCONFIG_LIST}
do
export TBCONFIG
tbmode -ky
tbinit -sy
tbmode -my
done \\
\\
2>&1 \\
> /usr/backup/log/informix.log
else
TBCONFIG_LIST='#'
fi
fi
if [ "$DEBUG" != "SKIP BACKUP" ]
then
#
# Second: Run the Backup Program
#
OUTPUT=/usr/backup/log/output.log \\
\\
cpio-backup.sh / "${TBCONFIG_LIST}" \\
\\
2> /usr/backup/log/remove.log \\
1> /tmp/stdout.log
#
# Next: Make Sure that the Tape Drive is not Active
#
tape-stat.sh rewind
fi
if [ "$DEBUG" != "SKIP REBOOT" ]
then
#
# Finally: Reboot Machine
#
init 6 2>&1 > /dev/console
fi
::::::::::::::
cpio-bak.sh
::::::::::::::
#!/bin/sh -f
#
# FILE: cpio-backup.sh
#
# Setting Environment Variables
#
#set -x
PATH=${HOME}/etc:${PATH}
INFORMIXDIR=`var.sh informix`
PATH=${PATH}:${INFORMIXDIR}/bin
if [ "$OUTPUT" = "" ]
then
OUTPUT=/dev/tty
else
echo "****************** ENVIRONMENT ******************" >>${OUTPUT}
set | sort >>${OUTPUT}
echo "\\n*************************************************\\n" >>${OUTPUT}
fi
if [ "${1}" = "#" ]
then
ROOTDIR=""
elif [ "${1}" != "" ]
then
ROOTDIR=${1}
else
ROOTDIR=/
fi
if [ "${ROOTDIR}" = "/" ]
then
RELATIVE="."
else
RELATIVE=""
fi
if [ "${2}" = "#" ]
then
DBSPEC=""
elif [ "${2}" != "" ]
then
shift
DBSPEC="${*}"
else
DBSPEC=`var.sh tbconfig`
fi
DEVICE=`var.sh device`
BACKUPDIR=`var.sh informix`
BACKUPSUB=`var.sh backup`
LOADDIR=${BACKUPDIR}/${BACKUPSUB}
EXIT=0
ADMIN_USER=`var.sh admin-user`
ADMIN_HOST=`var.sh admin-host`
LOCAL_HOST=`uname -n`
LOGSDIR=${HOME}/log
FLAGDIR=${HOME}/flag
DATE=`date '+%m-%d@%H:%M'`
DIRFILE=${DATE}.dir
ERRFILE=${DATE}.err
LOGSPEC="[0-1][0-9]-[0-3][0-9]@[0-1][0-9]:[0-5][0-9]"
DIRLIST=${LOGSDIR}/${DIRFILE}
ERRLIST=${LOGSDIR}/${ERRFILE}
DATPATH=${LOGSDIR}/${DATE}
FLAG_RM=.+RM+${ADMIN_USER}+${DATE}
FLAG_OK=.+OK+${ADMIN_USER}+${DATE}
export PATH
export INFORMIXDIR
export OUTPUT
export DIRLIST
export DATLIST
export ROOTDIR
export FLAGDIR
export FLAG_RM
export FLAG_OK
export DATPATH
export DBSPEC
export RELATIVE
export LOADDIR
echo Date: $DATE >> ${OUTPUT}
tape-stat.sh rewind
if [ $? -ne 0 ]
then
echo "Could not Rewind Tape. Is it Off-Line?" >> ${OUTPUT}
echo "Could not Rewind Tape." > ${ERRLIST}
EXIT=1
else
cd ${ROOTDIR}
for DIR in ${LOGSDIR} ${FLAGDIR} ${LOADDIR}
do
if [ ! -d $DIR ]
then
mkdir $DIR
fi
chmod 755 $DIR
done
#
# Retain ONLY log files that have been created in the last 7 days.
#
find ${LOGSDIR} -name "${LOGSPEC}.*" -mtime +7 -exec rm -f {} \\;
echo ${RELATIVE}${DIRLIST} > ${DIRLIST}
echo `date '+%H:%M:%S'`"\\tEntering Main Processing Level." >> ${OUTPUT}
cpio-input.sh 2>${ERRLIST} \\
| grep -v '^$' \\
| cpio -ovcB -O${DEVICE} 2>&1 \\
| cpio-output.sh
grep -v '^$' ${ERRLIST} > ${ERRLIST}.alt
mv ${ERRLIST}.alt ${ERRLIST}
if [ `grep -v '^# .*command errors:' ${ERRLIST} | wc -l` -ne 0 ]
then
EXIT=2
fi
fi
GOOD="Successful"
BAD="Errors"
if [ "${OUTPUT}" != "/dev/tty" ]
then
if [ ${EXIT} -eq 0 ]
then
SUBJECT="${GOOD}"
ERRLIST=${OUTPUT}
else
SUBJECT="${BAD}"
fi
if [ "${ADMIN_HOST}" != "${LOCAL_HOST}" \\
-a ${EXIT} -ge `var.sh notify` ]
then
su ${ADMIN_USER} -c\\
rcp ${ERRLIST} ${ADMIN_HOST}:/tmp/${ADMIN_USER}:${ERRFILE}.${LOCAL_HOST}.${SUBJECT}
fi
mail -sBackup\\ ${SUBJECT}\\ \\(${DATE}\\)\\
${LOGNAME},${ADMIN_USER}\\
< ${ERRLIST}
fi
for REMOTE in /tmp/${ADMIN_USER}:${LOGSPEC}.*
do
if [ -f "${REMOTE}" ]
then
BACKUP_STATUS=`basename ${REMOTE} .${GOOD}`
if [ "${BACKUP_STATUS}" != "" ]
then
SUBJECT="${GOOD}"
else
SUBJECT="${BAD}"
fi
MESSAGE=`echo ${REMOTE} | cut -d: -f2`
mail -sRemote Backup\\ ${SUBJECT}\\ \\(${MESSAGE}\\)\\
${LOGNAME} ${ADMIN_USER}\\
< ${REMOTE}
rm -f ${REMOTE}
fi
done
exit ${EXIT}
::::::::::::::
cpio-in.sh
::::::::::::::
# FILE: cpio-input.sh
#
# set -x
toggle()
{
FLAG=${FLAGDIR}/${1}
BLOCKED=NO
while [ -f ${FLAG} ]
do
output Waiting for cpio to process ${FLAG}.
BLOCKED=YES
sleep 5
done
if [ ${BLOCKED} = YES ]
then
output Processing Resumed.
BLOCKED=NO
fi
error touch
touch ${FLAG}
output touching ${FLAG}
echo ${FLAG}
}
output()
{
echo `date '+%H:%M:%S'`"\\t$*" >> ${OUTPUT}
}
error()
{
echo "# $1 command errors:" 1>2&
}
if [ "${ROOTDIR}" != "" ]
then
output Creating List via FIND.
error find
find . -depth -local -print \\
\\
| grep -v '^./tmp/' \\
| grep -v '^/tmp/' \\
| grep -v '^tmp/' \\
\\
| grep -v '^./usr/tmp/' \\
| grep -v '^/usr/tmp/' \\
| grep -v '^usr/tmp/' \\
\\
| egrep -v "${FLAG_RM}\\$\\|${FLAG_OK}\\$" \\
\\
>> ${DIRLIST}
output Archiving List via CPIO.
fi
cat ${DIRLIST}
if [ "${DBSPEC}" != "" ]
then
for TBCONFIG in ${DBSPEC}
do
export TBCONFIG
output Creating DataBase list using ${TBCONFIG}
error tbcheck
tbcheck -pc \\
| grep Data