簡單DG歸檔日誌刪除指令碼

來源:互聯網
上載者:User

最近在擺弄DG,由於磁碟資源緊缺,需要一個歸檔Tlog的策略

網上找了幾個指令碼,發現寫的那麼麻煩

毛了,於是簡單寫了一個,實際路徑等可以自己在修改

主庫備庫都可以用,自己再做crontab就好,建議錯開時間進行

需要注意,提前查詢DEST_ID,下面這個是主庫刪除的指令碼(備庫只需更改dest_id即可),我的主庫v$archived_log裡,主庫的歸檔dest_id=1,備庫是dest_id=2

 

  1. #!/bin/bash 
  2.  
  3. ############ easy script by lcrash @ 2011-1-25############ 
  4. # for delete DG archive log                              # 
  5. # you should modify USER_HOME && make sure del_dir exists# 
  6. # and you can change your keep date by modify SQL below  # 
  7. ########################################################## 
  8.  
  9. USER_HOME=/opt/Oracle 
  10. DEL_DIR=$USER_HOME/del_arch 
  11.  
  12. source $USER_HOME/.bash_profile  
  13. $ORACLE_HOME/bin/sqlplus -S "/as sysdba" <<EOF 
  14. set heading off 
  15. set feedback off 
  16. spool /opt/oracle/del_arch/del_arch.list 
  17. select 'rm -rf '||name from v\$archived_log  
  18. where DEST_ID=1 and SEQUENCE#<(select max(SEQUENCE#) from v\$archived_log where applied='YES') and COMPLETION_TIME<=sysdate-0; 
  19. spool off 
  20. exit 
  21. EOF 
  22.  
  23. cd $DEL_DIR 
  24. sed -n '/dbf/p' del_arch.list>del_arch_do.sh 
  25. chmod +x del_arch_do.sh 
  26. source del_arch_do.sh 
  27.  
  28. rm del_arch.list 
  29. mv {,`date +%Y-%m-%d-%H`}del_arch_do.sh 
  30.  
  31.  
  32. rman target / <<EOF 
  33. crosscheck archivelog all; 
  34. delete obsolete; 
  35. delete noprompt expired archivelog all; 
  36. EOF 

by the way:

1、我開始使用uniread sqlplus,發現動不了,浪費時間,後面修改為$ORACLE_HOME/bin/sqlplus

防止其他別名取代出問題

2、指令碼中的SQL語句一句話太長居然給我認成兩行,非常惱火

於是將where語句另換行


╮(╯▽╰)╭

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.