Run dbcc checks and perform database backups to protect the integrity and recoverability of your SAP ASE databases.
Use dbcc checkstorage to run regular consistency checks on large databases when the amount of time you require to perform consistency checks is less than the amount of time required for dbcc checkalloc or dbcc checkdb to complete. dbcc checkstorage performs a fast consistency check, but it is not as thorough as dbcc checkalloc or dbcc checkdb. See Preparing to use dbcc checkstorage and Checking Database Consistency in the System Administration Guide, Volume 2, and the Reference Manual: Commands.
#!/bin/csh -f if ( -e dbcc_mail.out) then rm dbcc_mail.out endif foreach i (*.dbcc) isql -Usa -Ppassword < $i > dbcc_out if ( ‘grep -c ‘Msg 25[0-9][0-9]’ dbcc_out’ ) then echo "There are errors in" $i >> dbcc_mail.out cat dbcc_out >> dbcc_mail.out else echo "Backing up " $i:r >> dbcc_mail.out isql -Usa -Ppassword < $i:r.backup endif end mail -s "Backup Report" jjones < dbcc_mail.out
The first set of scripts (one for each database with a file name appended with .dbcc) runs dbcc checkalloc and dbcc checkdb for each database and sends the messages to an output file called dbcc_out.
dbcc checkalloc (master) go dbcc checkdb (master) go
The C shell script then runs the grep command to find 2500-level error messages in dbcc output. The results of the grep command are sent to an output file called dbcc_mail.out.
use master go dump database master to master_dump go
You may want to add appropriate dump transaction commands to your scripts.
If there are 2500-level error messages, the script does not back up the database. At the end of the script, dbcc_mail.out is mailed to the system administrator “jjones,” who then has a record of fatal dbcc errors and successful backups.
You can tailor the sample shell and isql scripts to suit the needs of your installation.
00 02 * * * /usr/u/sybase/dbcc_ck 2>&1
This example executes a C shell script called dbcc_ck every morning at 2:00 a.m.