#!/bin/bash
# file name:arch_self_del.sh
# Used to delete archive log when archive log directory>=90% and <=50GB
# */5 * * * * /bin/bash ~/scripts/arch_self_del.sh >> ~/logs/arch_self_del.log
source /home/oracle/.bash_profile
# 定义删除 1 天前日志函数
rman_del_1d() {
rman target / <<EOF
crosscheck archivelog all;
delete expired archivelog all;
delete noprompt archivelog all completed before "SYSDATE-1";
exit;
EOF
}
# 定义强制删除 6 小时前日志函数
rman_del_6h() {
rman target / <<EOF
crosscheck archivelog all;
delete expired archivelog all;
delete force noprompt archivelog all completed before "SYSDATE-6/24";
exit;
EOF
}
# 定义强制删除 2 小时前日志函数
rman_del_2h() {
rman target / <<EOF
crosscheck archivelog all;
delete expired archivelog all;
delete force noprompt archivelog all completed before "SYSDATE-2/24";
exit;
EOF
}
# 获取 Archive destination
archdir=$(echo -e "set lines 200 pagesize 9999 time off timing off trimout on wrap off HEADING off feedback off ;\narchive log list;" | sqlplus -S / as sysdba | grep "Archive destination" | awk '{print $NF}' | sed -e "/^$/d")
# 识别 archive log d
Oracle archive log 清理脚本(配合crontab或zabbix等实现自愈)
于 2023-06-01 10:24:41 首次发布
本文介绍了一个使用Bash脚本配合crontab或Zabbix进行Oracle归档日志自动清理的方法,旨在实现数据库运维的自愈能力。
摘要由CSDN通过智能技术生成