Custom Search
www.rocket99.com : Technical Guides Sybase Oracle UNIX Javascript


Technical Guides
Sybase
Oracle
UNIX
Javascript




Of Interest

Business Intelligence and Analytics



Oracle Training





Sybase » Administration » DBA » Coding

Database maintenance script

     



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














Sybase : Related Topics

Sybase : Administration : Post-installation check
Sybase : Administration : Device initialization
Sybase : Administration : Database Creation
Sybase : Administration : A backup routine
Sybase : Administration : Striping Dump Devices
Sybase : Administration : Moving the transaction log to another device
Sybase : Administration : Adding a segment to a database
Sybase : Administration : Configuring the cache
Sybase : Administration : Apply multiple transaction dumps
Sybase : Administration : Database maintenance procedure
Sybase : Administration : Server configuration
Sybase : Administration : Dealing with a Corrupted Database
Sybase : Administration : Dealing with a Server Failure
Sybase : Administration : DBCC Notes
Sybase : Administration : Create proxy tables and external logins
Sybase : Administration : Renaming a database
Sybase : Administration : Reorg: rebuilding a table
Sybase : Administration : Sybase ASE 15 Enhancements
Sybase : Administration : Setting the thresholds
Sybase : Administration : Apply a transaction dump
Sybase : Administration : Security Tasks
Sybase : Administration : Setting Process Priorities
Sybase : Administration : Sybase ASE Architecture Overview
Sybase : Administration : Drop an alias, with objects linked to login
Sybase : Administration : Display grants, effective rights to objects
Sybase : Administration : Displaying access information from sysprotects
Sybase : Administration : Database Engines: Status and Settings
Sybase : Administration : Replication Server 15 Configuration
Sybase : Administration : Loading data into Sybase IQ from a Remote Server
Sybase : Administration : Sybase IQ Overview
Sybase : Administration : Sybase IQ Functions
Sybase : Administration : Sybase IQ - Remote Access From ASE

Sybase Web Site
Sybase Mobile Web Site
Oracle Web Site



Get the latest Rocket99 news and tech tips via






Site Index About this Guide to Sybase, Oracle, and UNIX Contact Us Advertise on this site




Copyright © 2012 Stoltenbar Inc All Rights Reserved.