Thursday, May 28, 2009

Script to purge old database backups

This script can be used to purge database backups taken using the script in the previous post. (replace the argument after “mtime” with the required number of days beyond which the backups can be deleted).

========================================================

DATE=`date +%d%b%y_%H_%M_%S`
LOGFILE='/t2/backups/logs/dbtech_backup_'${DATE}'.log'
ORACLE_BASE=/t2/oracleORACLE_HOME=/t2/oracle/PROD/db/tech_st/10.2.0
ORACLE_SID=PROD
WORK=/t2/scripts
EXEC_DIR=/t2/scripts
LOG_HOME=/t2/backups/logs
DB_BACKUP_LOC=/t2/backups/dbtech
export ORACLE_BASE ORACLE_SID ORACLE_HOME LOG_HOME DB_BACKUP_LOC
TNS_ADMIN=$ORACLE_HOME/network/admin/PROD_perp
SHELL=/usr/bin/ksh
LD_LIBRARY_PATH=/usr/lib:$ORACLE_HOME/lib
export TNS_ADMIN SHELL LD_LIBRARY_PATH
PATH=$PATH:/usr/bin:/usr/sbin:/usr/local/bin:/usr/lib:/etc:$ORACLE_HOME/bin:$LD_LIBRARY_PATH
export PATH
TERM=vt100
export TERM
NLS_LANG=American_America.UTF8
export NLS_LANG
find $LOG_HOME -type f -mtime +7 xargs rm -f
find $ORACLE_HOME/admin/PROD_perp/bdump -type f -mtime +14 xargs rm -f
find $ORACLE_HOME/admin/PROD_perp/udump -type f -mtime +14 xargs rm -f
find $ORACLE_HOME/admin/PROD_perp/cdump -type f -mtime +14 xargs rm -f
find $DB_BACKUP_LOC -type f -mtime +6 > $WORK/purge.list
if [ -s $WORK/purge.list ]then
for
file in `cat $EXEC_DIR/purge.list`
do
rm ${file}
done
for address in `cat $EXEC_DIR/mail_list`
do
if [ "`echo $address cut -c1`" != "#" ]; then
mail -s "${ORACLE_SID} - DB Purge Success Log" $address < $WORK/purge.list
sleep 1
fi
done
else
for address in `cat $EXEC_DIR/mail_list`
do
if [ "`echo $address cut -c1`" != "#" ]; then
echo "No Files found in backup directory to purge!!" mail -s "${ORACLE_SID} - DB Purge Failure Log" $address
fi
done
fi
find $WORK/purge.list xargs rm -f
========================================================

1 comment:

Unknown said...

once upon a time I have heard about a good way of repair sql database tool. hope it helps