Friday, July 31, 2015

Archive Destination Switchover Automatically once gonna full


Linux – Shell Scripting
Archive Destination Switchover once gonna full

 
Today I have been asked by one of my friend to write a script which automatically change the Archive Destination once its going to full.  I wrote a script which periodically check (cron) every hours and change the archive destination if required when its reached to threshold value.  Here I have set 50%.
 

#!/bin/ksh
 
printf "\n  Archive Destination Switchover once mount point got full - SCRIPT ---  \n"
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=GISDB
 
retcode=$?
 
filesize=`df -k |grep /u02 | awk '{ print $5 }'`
mname=`df -k | grep /u02 | awk '{ print $6 }'`
 
mpct=${filesize//%}
 
filesize2=`df -k |grep /u03 | awk '{ print $5 }'`
mname2=`df -k | grep /u03 | awk '{ print $6 }'`
 
mpct2=${filesize2//%}
 
 
  if [ $retcode != '0' ]; then
     printf "FATAL ERROR:  \n"
     ERROR_FLG='1'
  else
     if [ $mpct -gt 50 ]; then
        printf "\n  Alert - Mountpoint - $mname is above 50 and  $mpct pct  - utilized ...\n"
 
        printf "\n  Message : Changing Archivelog Destination to u03 ....... \n"
        printf "\n  Running ........... \n"
 
        newsize=`df -k |grep /u02 | awk '{ print $5 }'`
        nsize=${newsize//%}
        printf "\n Current Utilization $mname is $nsize\n"
 
        /u01/app/oracle/product/11.2.0/dbhome_1/bin/sqlplus -s '/ as sysdba' << eof
                ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=/u03/Archive' ;
 
         ALTER SYSTEM SWITCH LOGFILE ;
        exit ;
eof
 
       printf "\n  Finished ........... \n"
 
     elif [ $mpct2 -gt 50 ]; then
        printf "\n  Alert - Mountpoint - $mname2 is above 50 and  $mpct2 pct  - utilized ...\n"
 
        printf "\n  Message : Switching Archivelog Destination to u02 ....... \n"
        printf "\n  Running ........... \n"
 
        newsize2=`df -k |grep /u03 | awk '{ print $5 }'`
 
        nsize2=${newsize2//%}
        printf "\n Current Utilization $mname2 is $nsize2\n"
 
        /u01/app/oracle/product/11.2.0/dbhome_1/bin/sqlplus -s '/ as sysdba' << eof
 
         ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=/u02/Archive' ;
 
         ALTER SYSTEM SWITCH LOGFILE ;
        exit;
eof
 
       printf "\n  Finished ........... \n"
 
     else
        printf "\n  Filesystem is stable and available is $mpct pct.\n"
        printf "\n  Filesystem is stable and available is $mpct2 pct.\n"
     fi
  fi

 
Create a entry in cron tab with periodically check every hour.

 

 

No comments:

Post a Comment