ADR Maintenance & Log Tidy scripts

#!/bin/ksh
############################################################################
#
#       Script :        diag_maint.ksh
#
#       Date :          12th Jan 2011
#
#       Author :        Mark Ramsay
#
#       Description :   Performs various maintenance on the ADR for all ADR homes found.
#
#       Parameters :    \$1 - (OPTIONAL) Number of days to keep.
#                       Overrides the Adr Short and Long Policy
#
# History       Date        Name          Reason
#               ----        ----          ------
#               17/01/11    Oraclewiki    Add unset LD_LIBRARY_PATH_64 so script works as a Grid Job.
#               13/04/12    Oraclewiki    Removed SID references as not applicable and misleading.
#
############################################################################
#
#Start Script Message
#

clear
echo ""
echo "***************************************"
echo "DIAG DIRECTORY MAINTENANCE STARTING...."
echo "***************************************"
echo ""

#
#Check for Command Line Variables
#

export SDS_age=${1+"-age $(($1 * 1440))"}

#
# Set-up Relevant Variables
#

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin

SDS_adrbackup=/u01/app/oracle/adrbackups
SDS_date=`date +"%Y%m%d%H%M%S"`

echo ""

#
#Get a list of home directories known to the adr repository
#

echo ""
echo "Listing diag directory homes..."
echo ""
SDS_adrhomes=`adrci exec="show homes" |grep -v "ADR Homes:"`
adrci exec="show homes" |grep -v "ADR Homes:"
echo ""
echo ""

#
#Set-up loop for each home
#

for f in $SDS_adrhomes
do

#
#Create ADR Backup directory if not exists
#

[ ! -d $SDS_adrbackup ] &&  mkdir $SDS_adrbackup

#
#Backup the metadata for ADR
#

echo "Processing ADR home $f...."
echo "================================================================"
echo ""
echo "Backing up ADR Metadata to $SDS_adrbackup..."
echo ""

export ADR_BASE=`adrci exec="show base" |awk -F\" '{print $2}'`
export SDS_stem=`echo $f|awk -F\/ '{print $4}'`

echo "cp -R metadata $SDS_adrbackup/meta_${SDS_stem}_${SDS_date}_backup"
adrci exec="set home $f;set autoshell on;cd $ADR_BASE/$f; begin backup;cp -R metadata $SDS_adrbackup/meta_${SDS_stem}_${SDS_date}_backup;end backup"
SDS_ret=$?
if [ $SDS_ret -ne 0 ]
then echo "******************************************"
     echo "WARNING - Backup of ADR Metadata failed..."
     echo "******************************************"
     echo ""
else echo ""
     echo "Backup of ADR Metadata Complete."
     echo ""
     echo ""
fi

#
#Purge old Metadata Backups
#

echo "Purging old Metadata backups..."
echo ""
echo "The following files will be deleted..."
echo ""
find $SDS_adrbackup -name "meta_${SDS_stem}_*_backup" -mtime +7
find $SDS_adrbackup -name "meta_${SDS_stem}_*_backup" -mtime +7 -exec rm -r {} \;
echo ""
echo "Purging of old Metadata backups complete"

#
#Display the purging policy for each home
#

SDS_shortpol=`adrci exec="set home $f;select SHORTP_POLICY from adr_control"|tail -3|head -1`
SDS_longpol=`adrci exec="set home $f;select LONGP_POLICY from adr_control"|tail -3|head -1`
SDS_shortpol_days=$((SDS_shortpol/24))
SDS_longpol_days=$((SDS_longpol/24))

echo ""
echo ""
echo "Retrieving purging policy details for diagnostics home $f..."
echo ""
echo "Short term files are set to $SDS_shortpol_days days."
echo "Long term files are set to $SDS_longpol_days days."
echo ""
if [[ $SDS_age != "" ]]
then echo "**** WARNING ****"
     echo ""
     echo "The above purging policy has been overridden by the specified command line"
     echo "parameter \$1 which is set to $1 days"
     echo ""
fi

echo "Purging diagnostics home $f......."
adrci exec="set home $f;purge $SDS_age"
echo ""
echo "Purge complete."
echo ""
echo ""
echo "**** Processing for ADR home $f complete. ****"
echo ""
echo "                          *****"
echo ""
done

#
#Job Complete Message
#

echo "***********************************"
echo "DIAG DIRECTORY MAINTENANCE COMPLETE"
echo "***********************************"
echo ""
echo "JOB COMPLETE"
exit 0

No comments: