Shell script to delete applied archive log from standby database

This script will run on standby database.

It will basically check for  applied archives on standby database and it will keep last 100's number of archives present and will delete rest of the archives that have been already applied. I have personally tested this script on my environment which is running on RHEL 7 and Database Ver 11.2.0.4. 

Warning:- Before running the script directly into Production Environment , please test it on a non production environment.


#Schedule this script on standby database server.

  vi /home/oracle/archive_del.sh

#!/bin/bash

ARCHLOG_DIR=/arch/prodtest/archivelog

 LogNo=`tail -3000 /db/prodtest/db/tech_st/11.2.0.4/admin/PRODTEST_ccuine103/diag/rdbms/prdtstdr/PRODTEST/trace/alert_PRODTEST.log | grep "Media Recovery Log" | cut -d " " -f 4 | cut -d "_" -f 2 | tail -1 `

echo "Oracle applied LogNo is $LogNo"

let SecLogNo=${LogNo}-100

echo "Archivelog is present from number : $SecLogNo"

echo "*****************************"

cd $ARCHLOG_DIR

for i in `ls *.arc`

do

Newi=`echo $i | cut -d "_" -f 2`

if [ "$Newi" -lt "$SecLogNo" ]; then

echo "$i to be deleted..."

rm -r $i

fi

done

 

 

Schedule to run for every 4 hours

[oracle@ccuine103 ~]$ crontab -l

0 */4 * * * /home/oracle/archive_del.sh



Another simple script that deletes archivelog from standby database

cat archive_delete.sh

. /db/prod/proddb/tech_st/19.3.0/PRODCDB_ccuine103.env
rman nocatalog log=/home/oracle/archive_del.log << EOF
connect target /
CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;
DELETE noprompt ARCHIVELOG ALL COMPLETED BEFORE 'sysdate-1';
CROSSCHECK ARCHIVELOG ALL;
DELETE noprompt EXPIRED ARCHIVELOG ALL;
EOF

No comments:

Post a Comment