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/oratab
Cat $ filename | while read LINE
Do
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
;;
Esac
Done
Exit
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.