Oracle Automatic cleanup Log script

Source: Internet
Author: User
Tags disk usage

I. BACKGROUND

Following the Oracle Backup Restore Practice (link address: http://kaliarch.blog.51cto.com/8966921/1978151), due to business growth, frequent backup restores have a greater space requirement for disk space, The basic 500G per week of disk, space usage will reach more than 85%, so write an Oracle cleanup script combined with Crond automatically clean up the Oracle archive log.

Ii. Introduction of tools

RMAN (Recovery Manager) is an Oracle tool for backing up (backup), restore, and recovery (recover) databases. Rman can only be used in ORACLE8 or later versions. It can back up entire databases or database parts, such as tablespaces, data files, control files, archive files, and spfile parameter files. Rman also allows you to make incremental block-level backups, and incremental Rman backups are time and space efficient because they only back up those blocks that have changed since the last backup. Furthermore, through the interface provided by Rman, third-party backup and recovery software such as Veritas will provide more powerful backup and recovery management capabilities. With Rman, additional features such as database cloning, setting up a standby database with Rman, and using Rman to back up and move files on a bare device (raw) are made easier and easier. With enhanced automatic configuration and management capabilities, and a unique block-level recovery, the 9i Rman makes backup and recovery work faster and better.

When using Rman to connect to a database, it is logged on by default using the SYSDBA role.

Rman target/#连接进rman
DELETE noprompt ARCHIVELOG all completed before ' SYSDATE-7 '; #删除系统时间7天以前的归档日志, the active archive log for the Flashback zone will not be deleted

Because the physical disk DBF files are many, if the physical deletion of the DBF file is more cumbersome, the following commands are listed for physical removal reference

Rm-rf ' ls-l/home/oracle/app/arch/|grep apr|awk ' {print $9} ' #PATH可以根据实际环境, delete all archive logs for APR month
Rm-rf ' ls-l/home/oracle/app/arch/|awk ' {if ($7<20) print$0} ' #删除20号以前的日志

650) this.width=650; "src=" https://s5.51cto.com/oss/201711/20/73a2fc0e9ed74ca852b7842b3012bed6.png "title="% 5YC9M3S{BG ' Odts8p58[%l.png "alt=" 73a2fc0e9ed74ca852b7842b3012bed6.png "/>

If you manually clean up the log file on disk, you need to check in Rman and then delete the expired log

Crosscheck Archivelog All;            #检查所有归档日志list expired Archivelog All;        #列出过期的归档日志delete noprompt expired Archivelog all;               #删除过期的归档日志delete noprompt Archivelog All; #清除所有的归档日志

Third, self-cleaning scripts

#!/bin/bashoracle_env ()  {    source /home/oracle/.bash_profile       export oracle_base=/home/oracle/app    export oracle_home=$ oracle_base/oracle/product/12.1.0/dbhome_1    export oracle_sid=glpfin     export path= $PATH: $HOME/bin: $ORACLE _home/bin    oraclecmd= "/home/oracle/ App/oracle/product/12.1.0/dbhome_1/bin/sqlplus "    oraclerman="/home/oracle/app/oracle/ Product/12.1.0/dbhome_1/bin/rman "}disk_useper= '/bin/df -th|grep -v  ' Filesystem ' |awk  '/\/ dev\/mapper\/vg00-lv_root/{if  ("$ (NF)" = = "/");p rint $ (NF-1)} ' |cut -d% -f1 ' Oracle_clean ()  {oracle_env    ${oraclerman} target /<<EOFDELETE NOPROMPT  archivelog all completed before  ' SYSDATE-7 ';crosscheck archivelog all;list  Expired archivelog all;delete noprompt expired archivelog all;exit; Eof}main ()  {    if [ ${disk_useper} -gt 80 ];then         oracle_clean    fi} main

With timed tasks to clean up the disk, this script writes to determine that the disk usage is greater than 80% to clean up, can also be judged according to their own needs, or each time to perform cleanup.

This article is from the "Kaliarch" blog, make sure to keep this source http://kaliarch.blog.51cto.com/8966921/1983430

Oracle Automatic cleanup Log script

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.