Linux/Unix shell script to clear archived log files

Source: Internet
Author: User

For Dev and UAT environments, databases must be in archive mode, but do not need to be backed up. Therefore, the constant increase in archive archiving logs results in a large amount of disk space consumption. In this case, you can use a shell script to automatically clear these archived logs at regular intervals. This article provides a script to clear archived logs.

 

1. Clear shell scripts for archiving logs

robin@SZDB:~/dba_scripts/custom/bin> more remove_arch_dump.sh#!/bin/bash# ------------------------------------------------------------+#   FileName: remove_arch_dump.sh                             |#   Desc:                                                     | #        Remove old archived log and data pump file           |#   Usage:                                                    |#        ./remove_arch_dump.sh                                |#                                                             |#   Authror : Robinson                                        |#   Blog    : http://blog.csdn.net/robinson_0612              |# ------------------------------------------------------------+filename=/etc/oratabcat $filename | while read LINEdo    case $LINE in        \#*)                ;;        #comment-line in oratab        *)        ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`        echo $ORACLE_SID          # ---------------------------------        # define archived log directory             # ---------------------------------        dir=/u02/database/$ORACLE_SID/archive/        echo $dir        filelist=`ls -t $dir`        echo $filelist                # ----------------------------------------------------------        # start to remove archived log and keep last 2 archived log        # ----------------------------------------------------------        count=0        for filename in $filelist        do                echo $filename                count=$(($count+1))                if [ $count -gt 2 ]; then                        echo $count                        rm -vrf $dir$filename                fi        done        ls -tr $dir                # --------------------------------        # define data pump dump directory        # --------------------------------        dir=/u02/database/$ORACLE_SID/BNR/dump/        echo $dir        filelist=`ls -t $dir`        echo $filelist                # ---------------------------------------------------------        # start to remove data pump file and keep last 5 dump file         # ---------------------------------------------------------        count=0        for filename in $filelist        do                echo $filename                count=$(($count+1))                if [ $count -gt 5 ]; then                        echo $count                        rm -vrf $dir$filename                fi        done        ls -tr $dir     ;;    esacdoneexit

2. Script description
A. The script reads the database Sid defined in oratab through an external loop to find the archive log path and DataPump dump path of the corresponding database.
B. A for loop is used to clear archived logs and keep the last two archived log files.
C. The next for loop is used to clear the dump file exported under the corresponding dump (Oracle DataPump) directory under the current Sid.
D. The last five files in the dump directory are retained. You can modify the number of recent files that are retained (dump 5 or archive log 2.
E. If you do not need to clear the dump path, comment out the dump part.
F. Deploy it to crontab as needed.

 

More references

PL/SQL --> cursor

PL/SQL --> implicit cursor (SQL % found)

Batch SQL forall statements

Bulk collect clause for batch SQL

Initialization and assignment of PL/SQL Sets

PL/SQL Union arrays and nested tables
PL/SQL variable-length Array
PL/SQL --> PL/SQL records

SQL tuning steps

Efficient SQL statements

Parent cursor, child cursor, and shared cursor

Bind variables and their advantages and disadvantages

Use of the display_cursor function of dbms_xplan

Use of the display function of dbms_xplan

Description of each field module in the execution plan

Use explain plan to obtain the SQL statement execution plan

Oracle rowid

Null Value and index (1)

Null Value and index (2)

Enable autotrace

The function invalidates the index column.

Oracle variable binding

Oracle adaptive shared cursor

Oracle tablespace and data files
Oracle Password File
Oracle parameter file
Oracle online redo log file)
Oracle Control File)
Oracle archiving logs
Oracle rollback and undo)
Oracle database instance startup and Shutdown Process
Automated Management of Oracle 10g SGA
Oracle instances and Oracle databases (Oracle Architecture)

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.