shell脚本实现logmnr分析

shell脚本实现logmnr分析

#!/bin/bash  
# Created:2019-05-28
# Written by:Kay
# Description: analyze archivelog using logmnr fetch sql_redo!
# Please make happy in analyze log!

#ORACLE_SID=ora11g;
START_TIME=$1;
#START_TIME example '2019-01-01 10:00:00'
END_TIME=$2;
#END_TIME=`date +"%Y-%m-%d %H:%M:%S"`

#EXAMINE END_TIME IS NULL
if [ -z "$2" ]
then
		echo "Please input LOGMNR'S END TIME,example '2019-01-01 10:00:00'"
		exit
fi

out_file="/tmp/logfilelist"
#result=`tail -n 1 /tmp/logfilelist.lst`
#echo $result
#if [[ $result == 'SQL> spool off' ]]
#then
#		echo "no archivelog between '$START_TIME' and '$END_TIME'"
#		exit
#fi

RESULT=
RESULT=`sqlplus -s /nolog <<EOF 
set echo off feedback off heading off underline off;
conn / as sysdba;
select name from v\\$archived_log where next_time > to_date('${START_TIME}', 'yyyy-mm-dd hh24:mi:ss') and next_time <to_date('${END_TIME}', 'yyyy-mm-dd hh24:mi:ss') and name is not null;
exit;
EOF`
if [ -z "$RESULT" ];
then
		echo "NO archivelog between '$START_TIME' and '$END_TIME',plesae change time range"

		exit



else

sqlplus / as sysdba >/dev/null 2>&1 <<EOF
set echo off
set sqlblanklines off
set feedback off
set heading off
set pagesize 50000
set linesize 50000
set newpage none
set pages 0
set trimspool on
set newpage none
set termout off
set trimout on
spool ${out_file}
select name from v\$archived_log where next_time > to_date('${START_TIME}', 'yyyy-mm-dd hh24:mi:ss') and next_time <to_date('${END_TIME}', 'yyyy-mm-dd hh24:mi:ss') and name is not null;
spool off
exit
EOF
awk 'BEGIN{print "begin"}NR>1 && !/SQL/ {print "dbms_logmnr.add_logfile(logfilename=>'\''"$1"'\'');"}END{print "end; \n /"}' /tmp/logfilelist.lst > addlogfile.sql
fi
sqlplus / as sysdba >/dev/null 2>&1 <<EOF
create table admin.archdump as select * from sys.v\$logmnr_contents where 1=0;
truncate table admin.archdump;
start addlogfile.sql;
exec dbms_logmnr.start_logmnr(options=>dbms_logmnr.dict_from_online_catalog);
insert into admin.archdump(timestamp,sql_redo,sql_undo,operation,seg_owner,seg_name,scn,start_scn,commit_scn,xidsqn,tx_name,table_name,username,os_username,machine_name,session#,serial#,session_info) select timestamp,sql_redo,sql_undo,operation,seg_owner,seg_name,scn,start_scn,commit_scn,xidsqn,tx_name,table_name,username,os_username,machine_name,session#,serial#,session_info from sys.v\$logmnr_contents;
commit;
exec dbms_logmnr.end_logmnr;
exit
EOF
echo "Please query archivelog contents on admin.archdump by PLSQL!"

示例:

[root@db ~]# su - oracle
[oracle@db ~]$ sh logmnr.sh '2019-05-28 15:11:00' '2019-05-28 15:12:00'       
Please query archivelog contents on admin.archdump by PLSQL!
select timestamp,sql_redo,operation,seg_owner,seg_name,scn,
start_scn,commit_scn,xidsqn,tx_name,table_name,username,os_username,machine_name,
session#,serial#,session_info 
from admin.archdump where seg_name='TEST';

在这里插入图片描述
另附脚本

链接:https://pan.baidu.com/s/1bocyJHt1VrxRvSEUY44GmA  密码:h5n1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值