oracle归档日志怎么自动清除,如何定期自动删除归档日志

Dataguard的维护稍微麻烦点,不能删除尚未applied的归档日志,但是每次手工去核对就比较麻烦了,今天在pub上看到这样一个要求:“哪位有

standby数据库

定期删除已经apply的archive的shell脚本?”于是就写了个脚本,基本可以满足题目的要求:

1、已经在standby库apply的;

2、2天以上的

脚本如下(具体的脚本和初始化路径可见文章最后的下载tar包,在这里对这个脚本的内容进行下说明):

OS:

[oracle@standby1

etc]$ cat redhat-release

Enterprise Linux Enterprise Linux AS release 4 (October Update

4)

DB:

BANNER----------------------------------------------------------------------------------------------------

Oracle9i Enterprise Edition Release 9.2.0.4.0 -

ProductionPL/SQL Release 9.2.0.4.0 - ProductionCORE 9.2.0.3.0ProductionTNS for Linux: Version 9.2.0.4.0 - ProductionNLSRTL Version 9.2.0.4.0 - Production

脚本部署路径为:/oracle/del_appl_arc/bin

脚本生成的日志路径:/oracle/del_appl_arc/log

#!/bin/sh

#########################################################################

# This shell is for primary and

standby database #

# to rm applied archivelog that

before some day ago. #

# #

# You can define "some day" in variables

${day_before} #

# This shell can be put in

crontab for auto run #

# #

# 2008-01-18 writen by www.oracleblog.cn #

#########################################################################

## load profile file

. /oracle/.bash_profile

## Path Define

main_path=/oracle/del_appl_arc

## Initial scripttouch app_arc_name.shchmod +x app_arc_name.sh## rm

applied

archivelog

that

before

${day_before} day agoday_before=1

infodbuser=testdbpwd=testdbsid=primary########## Main shell start here ##########

## load

exisit

archlog

list

to db

${dbuser}/${dbpwd}@${dbsid}<

>/dev/null

drop table

${dbuser}.arc_log_list;

CREATE TABLE

${dbuser}.arc_log_list (arc_name

VARCHAR2(2000));

exit;

EOF

ls -l ${arc_path}|awk

'{print $9}' |grep arc

>arc_log_list.tmp

echo "load data">>arc_log.ctl

echo "infile

'arc_log_list.tmp'">>arc_log.ctl

echo "replace into table

arc_log_list">>arc_log.ctl

echo "fields terminated by

X'09'">>arc_log.ctl

echo "(arc_name)">>arc_log.ctl

sqlldr

${dbuser}/${dbpwd}@${dbsid}

control=arc_log.ctl log=sqlldr_run.log bad=sqlldr_badfile.bad

### Create shell for rm applied archive that before some day

ago

sqlplus -s

${dbuser}/${dbpwd}@${dbsid}</dev/null

from

test.arc_log_list intersectselect 'rm -f '||name from v\$archived_log where DEST_ID=1 and name like '%.arc' and SEQUENCE#

the shell in background modecat app_arc_name.tmp |grep -v spooling>app_arc_name.sh

./app_arc_name.sh

mv app_arc_name.sh rm_appl_arc_`date +"%Y%m%d%H%M"`.log

mv rm_appl_arc*.log

${log_path}

rm app_arc_name.tmp arc_log.ctl sqlldr_run.log

arc_log_list.tmp

完成脚本后,你可以把脚本放入crontab中定期运行,以达到自动删除n天以前且已经applied的归档日志。注意crontab的部署把primary和standby的时间错开,如果同时进行,会对arc_log_list表有争用。

1. 写rman备份脚本的时候用ARCHIVELOG ALL DELETE

INPUT;

2. 或者直接写个shell Script,使用crontob来删除 .

开归档的目的即为备份,满足你备份策略的archive

log都是可以删除的。在backup archivelog时加上delete

input,备份后归档日志自然就删除了。所以你可以加大一下备份归档日志的频次。

手动的删除也没问题,不过当rman备份时会检测到日志的缺失,按如下的操作即可:

RMAN> crosscheck archivelog all;

RMAN> delete obsolete;

=============================

自動刪除腳本

find /ocfs_arch1/SID/1_*.dbf -mmin +5760 -exec rm -f

{} ;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值