Oracle Data Guard backup database archive file deletion script

Source: Internet
Author: User
Tags tmp file

Oracle Data Guard synchronizes Data through archive files. The archive files of the master database can be deleted during RMAN backup, but the archive files of the slave database cannot be deleted automatically. You need to write scripts to delete them regularly.

If you delete an archive file directly, you may find that the archive file has not been urgently applied. Therefore, the safest way is to delete the archive file and make a judgment. Then, delete the file.

The shell script for deleting the slave database is as follows:

[Oracle @ bkjia www.bkjia.com] $ cat del_st_archive.sh

#! /Usr/bin/ksh

# Created by tianlesoftware

#2010/12/24

Export ORACLE_HOME =/u01/app/oracle/product/10.2.0/db_1

Export ORACLE_SID = xxxx

Export SHELL_DIR =/u02/scripts

Del_seq = 'ls/u02/archivelog/| head-1 | cut-f2-d _'

Echo $ del_seq

$ ORACLE_HOME/bin/sqlplus-s "user/pwd @ sid_pd as sysdba" <eof>/u02/scripts/max_sn.log

Set head off;

Set feedback;

Select max (sequence #) from v \ $ log_history;

Exit;

Eof

Max_sn = 'cat/u02/scripts/max_sn.log | awk '{print $1}' | grep ^ [0-9]'

Max_sn = 'expr $ max_sn-30'

-- I keep the last 30 archive files here. I will decide the specific situation.

Echo $ max_sn

While [$ del_seq-lt $ max_sn]

Do

Rm/u02/archivelog/1 _ "$ del_seq" _ 737806218.arc

-- Here I define the format of the archive file. The key is matching the log sequence no according to the format of the archive file.

Del_seq = 'expr $ del_seq + 1'

Echo $ del_seq

Done

-- Modify the red part of the script based on your own situation.

[Oracle @ bkjia www.bkjia.com] $ ls

Del_st_archive.sh del_st_arch.log max_sn.log

-- Max_sn.log is the tmp file that stores the largest seq. Used for comparison

Add to crontab for scheduled execution:

[Oracle @ bkjia www.bkjia.com] $ crontab-l

00 6 ***/u02/scripts/del_st_archive.sh>/u02/scripts/del_st_arch.log 2> & 1

Linux Crontab scheduled task commands

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.