如何定期自动删除归档日志如何定期自动删除归档日志
Dataguard的维护稍微麻烦点,不能删除尚未applied的归档日志,但是每次手工去核对就
比较麻烦了,今天在pub上看到这样一个要求:
“哪位有 standby数据库 定期删除已经apply的archive的shell脚本,”于是就写了个
脚本,基本可以满足题目的要求:
1、已经在standby库apply的;
2、2天以上的
脚本如下(具体的脚本和初始化路径可见文章最后的下载tar包,在这里对这个脚本的内容
进行下说明):
OS:
[oracle@standby1 etc]$ c...
如何定期自动删除归档日志
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 <-------------------------------------假设删除1天前已经
的
日志,这个变量设置为1,你可以设置成其他。
## Db info
dbuser=test
dbpwd=test
dbsid=primary
########## Main shell start here ########## ## load exisit archlog list to db <------------------------从此处开始利用
sqlldr将arch文件列表load到数据库中。
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 <-------------利用
load数据库中的arch列表和
set feedback off <-------------数据库中
v$archived_log,找出符合条件可以删除的arch,同时生成删除脚本。
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#<(select max(SEQUENCE#) from v\$archived_log where applied='YES')
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的归档日志。注意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 {} ;
本文档为【如何定期自动删除归档日志】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。