Oracle 11g Data Guard 備庫歸檔日誌清理指令碼(保留一週歸檔)

feelpurple發表於2016-03-07
#!/bin/sh
#clean archived log
#author jiadingyi
#version 1.0 2015/11/04
#設定資料庫環境變數
TMP=/tmp
export TMP
TMPDIR=$TMP
export TMPDIR
ORACLE_BASE=/u01/app/oracle
export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_HOME
ORACLE_SID=gtfdb
export ORACLE_SID
ORACLE_UNQNAME=gtfdbdg
export ORACLE_UNQNAME
ORACLE_TERM=xterm
export ORACLE_TERM
PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$CLASSPATH
export CLASSPATH
NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS"
export NLS_DATE_FORMAT
NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export NLS_LANG

now=`date +%Y%m%d`
Gap=`sqlplus -silent "/ as sysdba" << EOF 
set pagesize 0 feedback off verify off heading off echo off
select count(*) from v\\\$archive_gap;
exit;`
Arc_applied=`sqlplus -silent "/ as sysdba" << EOF 
set pagesize 0 feedback off verify off heading off echo off
select count(*) from v\\\$archived_log where applied='NO';
exit;`
#check the archive log applicance and the gap information
if [ $Gap -eq 0 ] && [ $Arc_applied -eq 0  ]
then
rman target / log=/home/oracle/log/$now.log << EOF
delete noprompt archivelog until time 'sysdate-7';
exit
EOF
else
echo "Please check the archivelog appliance error.." >> /home/oracle/log/error_$now.log
#sendmail
#mail -s "subject" jiadingyi@xxx.com < /home/oracle/log/$now.log
fi

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

相關文章