Shell script to disable and enable Flashback in database

 *****************************************Version 1 *******************************************************


./$HOME/fra_delete_1.sh SID Database_role >$HOME/fradelete.log 2>&1



#!/bin/bash

########################################################################################

#   Script Created by  :- ***************                                                              #

#   Date of Creation   :- *********************                                                   #

#   Purpose of Script  :- To CLear Flashback on all Databases                                 #

#   Mode of Usage      :- ALl database(Physica,Standby,Logical)                            #

#   Remarks            :- you need to have two script accompanied with this one        #

#                         for operating on primary and standby database                 #

#   Checks Required    :- Use only if Flashback has been enabled on Database           #

#                                                                                      #

########################################################################################

if [ "$#" -ne 1 ]

   then

     echo " EROOR!! Wrong Arguments  Usage fra_delete <SID> " ;

     exit 1;

   else

     echo "Arguments are perfect and sid is:$1"

fi


filedate=$(date +%Y%m%d)

ORACLE_SID=$1 export ORACLE_SID

ORACLE_TERM=xterm; export ORACLE_TERM

PATH=/usr/sbin:$PATH; export PATH

PATH=$ORACLE_HOME/bin:$PATH; export PATH

tab='v$database'

MAILLIST=********

cat /dev/null > $HOME/FRA_DELETE_$filedate.log


# extract the ORACLE_HOME from /etc/oratab and validate

ORACLE_HOME=`grep "^$ORACLE_SID:" /etc/oratab | awk -F: '{print $2}'`

if [ -z "$ORACLE_HOME" ]

then

  echo " ERROR!! ORACLE_HOME for $ORACLE_SID not extracted from /etc/oratab ";

  exit 1;

else

  echo "Today : $filedate"

  echo "ORACLE_HOME for $ORACLE_SID :$ORACLE_HOME"

fi


DBROLE=`sqlplus -s / as sysdba << EOF

set heading off

set verify off

set echo off

select  database_role from $tab ;

exit

EOF`


if [ $DBROLE=PRIMARY ] && [ -e $HOME/fra.sql ]

  then

   echo "$ORACLE_SID IS $DBROLE"

fi


FRA_OUTPUT=`sqlplus -s / as sysdba << EOF >>$HOME/FRA_DELETE_$filedate.log

@$HOME/fra.sql

exit

EOF`


exit


####################################  Version 2######################################################################


oracle@pfs-4db100.mandtbank.com:  /home/oracle #-- cat fra_delete.sh

#!/bin/bash

########################################################################################

#   Script Created by  :- Rama Krishna Bikkina                                         #

#   Date of Creation   :- 21/09/2020                                                   #

#   Purpose of Script  :- To CLear Flashback on all Databases                          #

#   Mode of Usage      :- ALl database(Physica,Standby,Logical)                        #

#   Remarks            :- you need to have two script accompanied with this one        #

#                         for operating on primary and standby database                 #

#   Checks Required    :- Use only if Flashback has been enabled on Database           #

#                                                                                      #

########################################################################################

if [ "$#" -ne 2 ]

   then

     echo " EROOR!! Wrong Arguments  Usage fra_delete <SID> " ;

     exit 1;

   else

     echo "Arguments are perfect and sid is:$1"

fi


filedate=$(date +%Y%m%d)

ORACLE_SID=$1 export ORACLE_SID

ORACLE_TERM=xterm; export ORACLE_TERM

PATH=/usr/sbin:$PATH; export PATH

PATH=$ORACLE_HOME/bin:$PATH; export PATH

MAILLIST="MAIL ID"

cat /dev/null > $HOME/FRA_DELETE_$filedate.log


if [ $DBROLE=PRIMARY ] && [ -e $HOME/fra.sql ]

  then

   echo "$ORACLE_SID IS $DBROLE"

   else

   echo "$ORACLE_SID IS PHYSICAL STANDBY"

fi


FRA_OUTPUT=`sqlplus -s / as sysdba << EOF >>$HOME/FRA_DELETE_$filedate.log

@$HOME/fra.sql

exit

EOF`


ERRCNT=`grep -ic ora- $HOME/FRA_DELETE_$filedate.log`


if [[ $ERRCNT -gt 1 ]]

then

  mailx -s  "Error in FRA cleanup" $MAILLIST

else

  mailx -s  "FRA cleanup successful" $MAILLIST

fi


exit



oracle@pfs-4db100.mandtbank.com:  /home/oracle #-- cat fra_delete.sh

#!/bin/bash

########################################################################################

#   Script Created by  :- ********************                                         #

#   Date of Creation   :-******************                                                   #

#   Purpose of Script  :- To Clear Flashback on all Databases                          #

#   Mode of Usage      :- All database(Physical Standby,Logical)                        #

#   Remarks            :- you need to have two script accompanied with this one        #

#                         for operating on primary and standby database                 #

#   Checks Required    :- Use only if Flashback has been enabled on Database           #

#                                                                                      #

########################################################################################

if [ "$#" -ne 2 ]

   then

     echo " EROOR!! Wrong Arguments  Usage fra_delete <SID> " ;

     exit 1;

   else

     echo "Arguments are perfect and sid is:$1"

fi


filedate=$(date +%Y%m%d)

ORACLE_SID=$1 export ORACLE_SID

ORACLE_TERM=xterm; export ORACLE_TERM

PATH=/usr/sbin:$PATH; export PATH

PATH=$ORACLE_HOME/bin:$PATH; export PATH

MAILLIST="*********************"

cat /dev/null > $HOME/FRA_DELETE_$filedate.log

DBROLE=PRIMARY ; export DBROLE


if [ $DBROLE=$2 ] && [ -e $HOME/fra.sql ]

  then

   echo "$ORACLE_SID IS $DBROLE"

   else

   echo "$ORACLE_SID IS PHYSICAL STANDBY"

fi


FRA_OUTPUT=`sqlplus -s / as sysdba << EOF >>$HOME/FRA_DELETE_$filedate.log

@$HOME/fra.sql

exit

EOF`


exit





Comments

Popular posts from this blog

Oracle Architecture SGA

FRA Usage and Administration

Format Date in Oracle Database - NLS_DATE_FORMAT