asm下如何自動刪除standby上已經applied過的歸檔日誌

warehouse發表於2013-01-06

由於是asm,所以和檔案系統處理起來可能還不太一樣,這要完全依賴rman了,不能依賴os了,當然我的這些指令碼適合db是檔案系統。

[@more@]

首先先寫了一個指令碼purge_archlog_sql_.sh,內容如下:

ORACLE_BASE=/oracle
ORACLE_HOME=/oracle/product/11.1.0/db_1
ORACLE_SID=lnmsadg
export ORACLE_BASE ORACLE_HOME ORACLE_SID
applied_days=3
cat /dev/null>applied_arch.lst
chmod +x applied_arch.lst
sqlplus -s "/ as sysdba"</dev/null
set feedback off
set pages 0
set head off
set timing off
set echo off
spool applied_arch.lst
select 'run{' from dual;
select 'delete noprompt archivelog sequence '||sequence#||' ;' from v$archived_log where DEST_ID=1 and name like '%.dbf' and status='A'
and SEQUENCE#and COMPLETION_TIME<=sysdate-${applied_days}
order by COMPLETION_TIME;
select '}' from dual;

spool off;
exit

EOF
--================================

以上指令碼用來生成檔案applied_arch.lst,applied_arch.lst的內容就是rman要呼叫的刪除歸檔日誌的指令碼,內容大致如下:

$ more applied_arch.lst
run{
delete noprompt archivelog sequence 14254 ;
delete noprompt archivelog sequence 14255 ;
delete noprompt archivelog sequence 14256 ;
delete noprompt archivelog sequence 14257 ;
delete noprompt archivelog sequence 14258 ;
..................

delete noprompt archivelog sequence 14268 ;
delete noprompt archivelog sequence 14269 ;
delete noprompt archivelog sequence 14270 ;
delete noprompt archivelog sequence 14271 ;
delete noprompt archivelog sequence 14272 ;
delete noprompt archivelog sequence 14273 ;

}

--===============================

最後在指令碼purge_archlog.sh裡呼叫就可以了,purge_archlog.sh的內容如下:

$ more purge_archlog.sh


PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:.

export PATH
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/11.1.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=lnmsadg

rman target / cmdfile='/home/oracle/purge_archlog/applied_arch.lst' log='/home/o
racle/purge_archlog/purge_archlog.log' append <

--==========================

最後透過crontab自動執行就可以了,crontab -l的結果如下:

$ crontab -l
10 22 * * * purge_archlog_sql.sh >/dev/null 2>&1
20 22 * * * purge_archlog.sh >/dev/null 2>&1
$

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

相關文章