This script performs DBCCs, transaction dumps, or database dumps for a
specified database.
#!/usr/bin/ksh
#-------------------------------------
# syb_maint
#
# Sybase database maintenance: perform DBCCs / log backups / db backups
#
# Parms: database, dump dir, mode (dump | tran_only | dbcc)
#
# Step 1: DBCCs (dbcc mode only)
# Step 2: Backup
#
# Output is routed to backup.log & dbcc.log
#-------------------------------------
if test $# -lt 3
then
echo " "
echo "usage:"
echo "------"
echo "syb_maint <dbname> <dump path> <mode (tran_only,dump,dbcc)>"
echo " "
echo " "
exit
fi
if test ! -d $2 ; then
echo " "
echo " Invalid path: "
echo $2
echo " "
exit
fi
if test ! -f /usr2/dumps/scripts/contact.txt ; then
echo " contact.txt file not found "
exit
fi
contact=`cat /usr2/dumps/scripts/contact.txt`
logfile1=/usr2/dumps/cronlogs/syb_maint/dbcc.log
logfile2=/usr2/dumps/cronlogs/syb_maint/backup.log
if test -f /tmp/syb_stop ; then
echo " ***** db stop detected ***** " >> $logfile1
exit
fi
echo "=============================" > /dev/null
echo $1 > /dev/null
echo "=============================" > /dev/null
if test "$3" = "dbcc" ; then
echo "Running dbcc step ..." > /dev/null
eval /apps/sybase/bin/isql -Sserver -I/apps/sybase/interfaces -Ujsmith -Pyankees << finis >> $logfile1
print '***** DBCC $1 **************************************'
go
use master
go
sp_dboption $1, "single user", true
go
use $1
go
dbcc checkdb ($1,skip_ncindex)
go
dbcc checkcatalog
go
dbcc checkalloc
go
checkpoint
go
use master
go
sp_dboption $1, "single user", false
go
quit
finis
# check output
if egrep "error|corrupt" $logfile1 | egrep -v "printed|TABLE|Checking" > /dev/null
then
echo "*** Errors found in DBCC log file."
rmail $contact@focal.com << endmsg
*** Errors found in DBCC log file
.
endmsg
fi
fi
echo "Running dump step ..." > /dev/null
eval /apps/sybase/bin/isql -Sserver -I/apps/sybase/interfaces -Ujsmith -Pyankees << finis2 >> $logfile2
print '***** DUMP $1 **************************************'
go
use master
go
exec sp_syb_maint $1, '$2', '$3'
go
quit
finis2
if grep "error|corrupt" $logfile2 > /dev/null
then
echo "*** Errors found in backup log file"
rmail $contact@mycompany.com << endmsg2
*** Errors found in backup log file
.
endmsg2
fi
echo "Sybase maintenance complete" > /dev/null
|
|