Linux regularly deletes oracle automatic archive logs

Scenario: If you do not clean up oracle's automatic archive logs in time, it may cause the disk partition to be full, causing oracle to mount

Version: oracle 11.2.0.4.0

Default path of archived logs: oracle installation directory/flash_recovery_area/instance name/archivelog

Thanks to this old man: https://blog.csdn.net/weixin_43969688/article/details/118799768

1. Create a regular cleanup script: vim clear_archivelog.sh

#!/bin/bash

# 删除归档脚本
# 修改区域
# ==========================
# 1. 指定生成删除归档日志的存放路径
log_dir=/home/oracle/myclearlog

# 如果无目录创建目录 
if ! test -d ${log_dir}
    then
    mkdir -p ${log_dir}                                                                   
fi

# 自动执行区域
# ================================
# 脚本执行日期
TODAY=`date +%y%m%d`
msg_log=${log_dir}/clear_archivelog_${TODAY}.log
run_log=./run.log

# 补充调用环境变量
if [ -f ~/.bash_profile ];
then
. ~/.bash_profile
fi

# 清除失效归档,删除1天前归档,并记录
$ORACLE_HOME/bin/rman target / msglog=${msg_log} append <<EOF
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog until time 'sysdate-1';
exit;
EOF

# 记录操作结果
RC=$?

# 记录磁盘使用情况
echo -e "\n------------------------" >> ${msg_log}
echo "------ Disk Space ------" >> ${msg_log}
df -h >> ${msg_log}

# 判断,汇报清除归档结果
if [ "$RC" == 0 ]; then
    echo "------ no error occured ------" >> ${msg_log}
else
    echo "------ error ------" >> ${msg_log}
fi

echo -e "$(date +%y%m%d) : $(grep error ${msg_log})" >> ${run_log}

2. Authorize the script: chmod 777 clear_archivelog.sh

3. Add the script to the linux scheduled task, run at 1 am every day: crontab -e

00 01 * * * sh 加上你脚本的绝对路径

Guess you like

Origin blog.csdn.net/qq_17685725/article/details/127566427