Oracle Delete archive log script

Source: Internet
Author: User

 

Archive logs record database operation records, which are the basis for data recovery. If the archive mode is enabled for the database, a large number of archive logs will be generated. Of course, if there is an RMAN backup, logs that have been backed up can be deleted after the backup. If RMAN backup is not used, you need to delete the archived logs by yourself. The following scripts reduce DBA workload.

 

Linux platform:
0 2 ***/home/Oracle/scripts/del_archive.sh>/home/Oracle/scripts/del_archive.log

[Oracle @ hfcc-svr-newccsdb1 ~] $ More/home/Oracle/scripts/del_archive.sh
#! /Usr/bin/KSh
# Create by tianlesoftware

Export ORACLE_HOME =/DBA/Oracle/product/10.2.0/db_1
Export oracle_sid = orcl

Export shell_dir =/home/Oracle/scripts

Del_seq = 'ls/u01/newccs_archive/| head-1 | cut-F2-D _'
Echo $ del_seq

$ ORACLE_HOME/bin/sqlplus-s "sys/pwd @ Sid as sysdba" <EOF>/home/Oracle/scripts/MAX
_ SN. Log
Set head off;
Set feedback;
Select max (sequence #) from V/$ log_history;
Exit;
EOF

Max_sn = 'cat/home/Oracle/scripts/max_sn.log | awk '{print $1}' | grep ^ [0-9]'
Max_sn = 'expr $ max_sn-5'
Echo $ max_sn

While [$ del_seq-lt $ max_sn]
Do
Rm/u01/archive/1 _ "$ del_seq" _ 692846987.dbf
Del_seq = 'expr $ del_seq + 1'
Echo $ del_seq

Done

Or use the script:
Del_arc.sh
Find/u01/backups-mtime + 10-name "*. DBF"-exec Rm-RF {}/;

 

Windows:

 

Del_arc_orcl.bat
Forfiles/P d:/arc_orcl/M *. DBF/D-3/C "CMD/C del @ file"

 

Add del_arc_orcl.bat to the scheduled task.

 

 

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.