ITPub博客

首页 > 数据库 > Oracle > Oracle 11g Data Guard 备库归档日志清理脚本(保留一周归档)

Oracle 11g Data Guard 备库归档日志清理脚本(保留一周归档)

原创 Oracle 作者:feelpurple 时间:2016-03-07 17:45:48 0 删除 编辑
#!/bin/sh
#clean archived log
#author jiadingyi
#version 1.0 2015/11/04
#设置数据库环境变量
TMP=/tmp
export TMP
TMPDIR=$TMP
export TMPDIR
ORACLE_BASE=/u01/app/oracle
export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_HOME
ORACLE_SID=gtfdb
export ORACLE_SID
ORACLE_UNQNAME=gtfdbdg
export ORACLE_UNQNAME
ORACLE_TERM=xterm
export ORACLE_TERM
PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$CLASSPATH
export CLASSPATH
NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS"
export NLS_DATE_FORMAT
NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export NLS_LANG

now=`date +%Y%m%d`
Gap=`sqlplus -silent "/ as sysdba" << EOF 
set pagesize 0 feedback off verify off heading off echo off
select count(*) from v\\\$archive_gap;
exit;`
Arc_applied=`sqlplus -silent "/ as sysdba" << EOF 
set pagesize 0 feedback off verify off heading off echo off
select count(*) from v\\\$archived_log where applied='NO';
exit;`
#check the archive log applicance and the gap information
if [ $Gap -eq 0 ] && [ $Arc_applied -eq 0  ]
then
rman target / log=/home/oracle/log/$now.log << EOF
delete noprompt archivelog until time 'sysdate-7';
exit
EOF
else
echo "Please check the archivelog appliance error.." >> /home/oracle/log/error_$now.log
#sendmail
#mail -s "subject" jiadingyi@xxx.com < /home/oracle/log/$now.log
fi

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26506993/viewspace-2050904/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-08-01

  • 博文量
    404
  • 访问量
    1192183