Simple DG archiving log deletion script

Source: Internet
Author: User

Recently, I have been playing with DG. Due to the shortage of disk resources, a policy for archiving logs is required.

I found several scripts on the Internet and found that writing is so troublesome.

Mao, So I simply wrote one, and the actual path can be modified by myself.

You can use both the master and slave databases. You can use crontab by yourself. We recommend that you stagger the time.

Note that DEST_ID is queried in advance. The following isScript deleted from the master database(You only need to change the dest_id of the standby database.) In my primary database v $ archived_log, the archive dest_id of the primary database is 1, and the standby database is dest_id = 2.

 

 
 
  1. #! /Bin/bash
  2.  
  3. ########### Easy scriptByLcrash @ 2011-1-25 ############
  4. #For DeleteDG archive log #
  5. # You shoshouldModifyUSER_HOME & make sure del_dir exists #
  6. #AndYou can change your keepDate By ModifySQL 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. SetHeadingOff 
  15. SetFeedbackOff 
  16. Spool/opt/oracle/del_arch/del_arch.list
  17. Select 'Rm-rf'|Name FromV \ $ archived_log
  18. WhereDEST_ID = 1And SEQUENCE# <(Select Max(SEQUENCE#)FromV \ $ archived_logWhereApplied ='Yes')AndCOMPLETION_TIME <= sysdate-0;
  19. SpoolOff 
  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 archivelogAll;
  34. DeleteObsolete;
  35. DeleteNoprompt expired archivelogAll;
  36. EOF

By the way:

1. When I started using uniread sqlplus, I found that it could not be moved and it was a waste of time. Later I changed it to $ ORACLE_HOME/bin/sqlplus.

Prevent replacement of other aliases

2. the SQL statement in the script is very annoying because it is too long to recognize two lines for me.

So we can wrap the where statement in another line.


Second (second) Second

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.