oracle 删除standby,哪位有 standby数据库 定期删除已经apply的archive的shell脚本?

定期删除DG归档日志的脚本·

作者 小荷||【转载时请务必以超链接形式标明文章原始出处和作者信息】

永久链接: http://www.oracleblog.cn/useful- ... elete-standby-arch/ ·

--------------------------------------------------------------------------------

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 - Production

PL/SQL Release 9.2.0.4.0 - Production

CORE    9.2.0.3.0       Production

TNS for Linux: Version 9.2.0.4.0 - Production

NLSRTL 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      

bin_path=${main_path}/bin      

log_path=${main_path}/log      

arc_path=/oracle/arch      

cd ${bin_path}

## Initial script

touch app_arc_name.sh

chmod +x app_arc_name.sh

## rm applied archivelog that before ${day_before} day ago

day_before=1      

## Db info

dbuser=test

dbpwd=test

dbsid=primary

########## Main shell start here ##########

## load exisit archlog list to db      

sqlplus ${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      

set feedback off                                    

set pages 0

set head off

set timing off

set echo off

spool app_arc_name.tmp

select 'rm -f '||'${arc_path}/'||arc_name from test.arc_log_list

intersect

select 'rm -f '||name from v\$archived_log

where DEST_ID=1 and name like '%.arc'

and SEQUENCE#

and COMPLETION_TIME<=sysdate-${day_before};

spool

exit

EOF

## Exec the shell in background mode

cat 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的归档日志。

下载tar包请到原文处:http://www.oracleblog.cn/useful- ... elete-standby-arch/

[本帖最后由 jimmyhe1981 于 2008-1-19 02:33 编辑]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值