Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement a script that automatically deletes archive logs

Shulou Source: shulou.com Published: 2022-06-02 06:02:26 11月07日 Update

This article mainly introduces how to automatically delete the archive log script, the article is very detailed, has a certain reference value, interested friends must read it!

Scripts that automatically delete archive logs (especially in dataguard environments)

There have been 236 reads 2011-12-16 21:02 | personal category: oracle data guard

Scripts that automatically delete archive logs (especially in dataguard environments)

In archive mode, always be careful not to burst the disk space, especially in the dataguard environment, you need to clean the logs that have already been apply regularly so as not to burst the hard disk.

There are several points to consider when deleting logs automatically:

1. The log must have been apply

two。 Log backups have already been backed up

3. In order to ensure some management leeway, do not delete immediately after apply, but should set a deletion policy according to the actual situation.

4. The script should be compatible with both primary and standby states, and automatically judge the state and execute different logic, otherwise it may be unfortunate if you forget to modify the script after switching.

The following is a script I used to delete the archive log. To run this script, you need to enter a parameter to control the retention time of the log.

This script can be used for either the standard side or the standby side

1. For the standby side, as long as the archive is within the save cycle and is archived by apply, it will be deleted.

two。 For the backup side, in addition to meeting the preservation cycle and apply conditions, it is also necessary to ensure that the archive has been backed up before it is deleted.

For dataguard environment, although backup can be performed on primary and standby side, if the pressure is not very high, it is recommended to perform backup on standard side for convenience of management.

The detailed script is as follows:

[oracle@dwapp1 DBA] $cat delete_arch.sh

#! / bin/bash

#

#

# This script is to delete the arch logs for the standby database after it has applied the logs to the instance.

#

#

Source / home/oracle/.bash_profile

#

Usage ()

{# usage

Echo "USAGE: `basename $0` $retention"

Exit 2

}

ArgNum=1

If [! $#-eq $ArgNum]; then

Echo ""

Echo "Incorrect parameter"

Usage

Fi

Retention=$1

Script= `basename $0`

Dir=/tmp

Tmpf=$dir/.$script.tmp

# get archived log list for standby database

Function GetLogListForStandby

{

Sqlplus-S / nolog

Tags: Logs scripts environment backups cycles management content parameters suggestions status articles guarantees inputs differences personal value tasks leeway examples interests Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB vpn Redmi Huawei