dataguard日志自动删除

dataguard日志自动删除

1、判断日志是否已经应用到今天。
2、删除3天前的日志。
3、主机、备机分别配置

----check_del_arch.sh
#!/bin/sh
ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome1
ORACLE_SID=capp
export ORACLE_HOME ORACLE_SID
cd $HOME/ljy
tab='v$archived_log'
res=`$ORACLE_HOME/bin/sqlplus -S '/ as sysdba' <<EOF |
        set heading off
        select sign(sysdate-max(first_time)-1) from $tab where dest_id=2 and applied='YES';
EOF

awk '{print}'`
echo $res

if [ $res = "-1" ]; then
        sh delarch.sh
fi

echo "ennnnd!"


---delarch.sh

#!/bin/sh
ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome1
ORACLE_SID=capp
export ORACLE_HOME ORACLE_SID
cd $HOME/ljy

$ORACLE_HOME/bin/rman nocatalog target / log delarch.log <<!
delete noprompt archivelog all completed before 'sysdate - 3';
quit
!


rman管理归档日志
===============================rman 管理archivelog
rman登录
 rman target /
 查看所有日志
 list archivelog all;
 检查存在错误的日志,适用于日志文件已经被删除的情形。
 crosscheck archivelog all;
 查看错误的日志
list expired archivelog all;
删除错误的日志
 delete expired archivelog all;
 
 删除7天前全部日志
 DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-1';

posted @ 2017-11-06 11:14  junyue  阅读(669)  评论(0编辑  收藏  举报