Linux/Unix shell script to clear archived log files

Source: Internet
Author: User

Linux/Unix shell scripts clear archive log files for DEV and UAT environments, sometimes the database needs to be in archive mode, but it does 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 the shell script for archiving logs [python] robin @ SZDB :~ /Dba_scripts/custom/bin> more remove_arch_dump.sh #! /Bin/bash # objects + # FileName: remove_arch_dump.sh | # Desc: | # Remove old archived log and data pump file | # Usage: | #. /remove_arch_dump.sh | # response + 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 # export dir =/u02/database/$ ORACLE_SID/archive/echo $ dir filelist = 'ls -t $ dir 'echo $ filelist # delimiter # 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 # folder # 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 # defaults 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. This script reads the database SID defined in oratab through an external loop to find the archive Log Path of the corresponding database and the datapump dump path. 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.

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.