4

Oracle使用rman定时清除7天前的日志

 1 year ago
source link: https://bajie.dev/posts/20221208-oracle_rman/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Oracle使用rman定时清除7天前的日志

2022-12-08 1 分钟阅读

这一篇正规的DBA看到肯定会呲之以鼻,但对于没有用过oracle的系统运维来说,就是必须知道的事情了。

公司的 Oracle 实例有两台数据库,定时用rman备份,但是没有自动清理机制 ,过一阵子磁盘就会超过 80% 告警,需要手动清理,烦不胜烦。

凡是要手动做三次的事情必须自动化处理,启荣大师如是说,照办就是。

cat del_log.sh

#!/bin/bash

source /home/oracle/.bash_profile

rman target / << EOF
delete noprompt archivelog until time 'sysdate-7';
exit;
EOF

很简单吧。上面引用的 .bash_profile 内容如下:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export ORACLE_BASE=/data/u01/app/oracle
export ORACLE_HOME=/data/u01/app/oracle/product/18.3.0/dbhome_1
export ORACLE_SID=oradb
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH:/usr/local/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:$ORACLE_HOME/rdbms/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss'
export EDITOR=vi
umask 022

这个 del_log.sh 的脚本放进 oracle 用户的 crontab 里执行就好

0 3 * * * /usr/local/bin/del_log.sh

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK