Oracle DG standby刪除歸檔的判斷指令碼

靜以致遠√團團發表於2015-08-11
#!/bin/bash

rman_date=`date "+%Y%m%d"`
rman_log="/home/oracle/oracle_sh/rman_bk_delete.log"
arch_num='10'

####Oracle PATH INFO
export ORACLE_SID=fogtestdb
export ORACLE_BASE=/opt/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin


####select arch_num which is not recover
value=`sqlplus -S "/ as sysdba" << !
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
select count(1) from v\\$archived_log where applied <> 'YES';
exit
!`


#### if count(1) is less than arch_num,delete archive log, else sent mail to me
if [[ $value -le $arch_num ]]; then


echo '---------------------------------------------------------------------------------------' >> $rman_log
echo 'delete_date is:' >> $rman_log
echo  $rman_date  >> $rman_log
echo '---------------------------------------------------------------------------------------' >> $rman_log
$ORACLE_HOME/bin/rman target / << EOF >> $rman_log
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog all completed before 'sysdate-4';
crosscheck backup;
delete noprompt obsolete;
exit;
EOF


echo "exec rman delete archivelog"
exit 0
else
echo "Oracle DGarchivelog is not recover,please check" | mail -s 'DG ARCH CHECK' **********@mail.com,*********@mail.com
fi

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29320885/viewspace-1768021/,如需轉載,請註明出處,否則將追究法律責任。

相關文章