--9. 将相关的归档都copy备份出来
RUN {
allocate channel dev1 device type disk format '/tmp/backup/arc_%h_%e_%t';
backup as copy archivelog sequence 30 thread 1;
backup as copy archivelog sequence 31 thread 1;
backup as copy archivelog sequence 32 thread 1;
backup as copy archivelog sequence 25 thread 2;
backup as copy archivelog sequence 26 thread 2;
backup as copy archivelog sequence 27 thread 2;
release channel dev1;
}
备份出来的归档日志文件如下:
[oracle@jyrac1 backup]$ ls -lrth
total 17M
-rw-r----- 1 oracle asmadmin 2.3M Jun 27 21:50 arc_1_30_947800247
-rw-r----- 1 oracle asmadmin 591K Jun 27 21:50 arc_1_31_947800249
-rw-r----- 1 oracle asmadmin 143K Jun 27 21:50 arc_1_32_947800250
-rw-r----- 1 oracle asmadmin 9.5M Jun 27 21:50 arc_2_25_947800251
-rw-r----- 1 oracle asmadmin 3.6M Jun 27 21:50 arc_2_26_947800253
-rw-r----- 1 oracle asmadmin 77K Jun 27 21:50 arc_2_27_947800254
10.使用LogMiner分析
使用LogMiner分析归档日志:
--使用LogMiner分析归档日志
--应该有插入操作的日志
begin
dbms_logmnr.add_logfile('/tmp/backup/arc_1_30_947800247');
dbms_logmnr.add_logfile('/tmp/backup/arc_2_25_947800251');
dbms_logmnr.start_logmnr(Options=>dbms_logmnr.dict_from_online_catalog);
end;
/
--应该有删除操作的日志
begin
dbms_logmnr.add_logfile('/tmp/backup/arc_1_31_947800249');
dbms_logmnr.add_logfile('/tmp/backup/arc_2_26_947800253');
dbms_logmnr.start_logmnr(Options=>dbms_logmnr.dict_from_online_catalog);
end;
/
--应该有更新操作的日志
begin
dbms_logmnr.add_logfile('/tmp/backup/arc_1_32_947800250');
dbms_logmnr.add_logfile('/tmp/backup/arc_2_27_947800254');
dbms_logmnr.start_logmnr(Options=>dbms_logmnr.dict_from_online_catalog);
end;
/
查询v$logmnr_contents
set lines 180 pages 500
col username format a8
col sql_redo format a50
select username,scn,timestamp,sql_redo from v$logmnr_contents where table_name='T2';
select username,scn,timestamp,sql_redo from v$logmnr_contents where username='JINGYU';
select username,scn,timestamp,sql_redo from v$logmnr_contents where sql_redo like '%JINGYU%';
select username,scn,timestamp,sql_redo from v$logmnr_contents where sql_redo like 'insert%JINGYU%';
select username,scn,timestamp,sql_redo from v$logmnr_contents where sql_redo like 'delete%JINGYU%';
select username,scn,timestamp,sql_redo from v$logmnr_contents where sql_redo like 'update%JINGYU%';
SQL> --应该有更新操作的日志
SQL> begin
2 dbms_logmnr.add_logfile('/tmp/backup/arc_1_32_947800250');
3 dbms_logmnr.add_logfile('/tmp/backup/arc_2_27_947800254');
4 dbms_logmnr.start_logmnr(Options=>dbms_logmnr.dict_from_online_catalog);
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> select count(1) from v$logmnr_contents;
COUNT(1)
----------
388
SQL> select username,scn,timestamp,sql_redo from v$logmnr_contents where username='JINGYU';
no rows selected
SQL> select username,scn,timestamp,sql_redo from v$logmnr_contents where sql_redo like '%JINGYU%';
USERNAME SCN TIMESTAMP
------------------------------ ---------- ------------
SQL_REDO
--------------------------------------------------------------------------------
UNKNOWN 1575420 27-JUN-17
update "JINGYU"."T2" set "CONTENTS" = 'xxx' where "CONTENTS" = 'YSWGNNLCLMYWPSLQ
ETVLGQJRKQIEAMOEYUFNRUQULVFRVPEDRV' and ROWID = 'AAAVWVAAGAAAAHnABj';
UNKNOWN 1575420 27-JUN-17
update "JINGYU"."T2" set "CONTENTS" = 'xxx' where "CONTENTS" = 'WHCWFOZVLJWHFWLJ
DNVSMQTORGJFFXYADIOJZWJCDDOYXAOQJG' and ROWID = 'AAAVWVAAGAAAAOYAAE';
SQL>
至此,LogMiner基本的操作实验已完成。
附:与LogMiner有关的一些操作命令参考:
conn / as sysdba
--安装LOGMINER
@$ORACLE_HOME/rdbms/admin/dbmslmd.sql;
@$ORACLE_HOME/rdbms/admin/dbmslm.sql;
@$ORACLE_HOME/rdbms/admin/dbmslms.sql;
@$ORACLE_HOME/rdbms/admin/prvtlm.plb;
--停止logmnr
exec dbms_logmnr.end_logmnr
--查询附加日志开启情况:
select supplemental_log_data_min, supplemental_log_data_pk, supplemental_log_data_ui from v$database;
--开启附加日志
alter database add supplemental log data;
--取消补充日志
alter database drop supplemental log data (primary key) columns;
alter database drop supplemental log data (unique) columns;
alter database drop supplemental log data;
--最后一个即为新的归档
select name,dest_id,thread#,sequence# from v$archived_log;
最后确认如果开启了附加日志,username就可以捕获到正确的值:
SQL> set lines 180
SQL> /
GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------ ------------ ------------
1 1 35 52428800 512 2 YES INACTIVE 1590589 27-JUN-17 1591935 27-JUN-17
2 1 36 52428800 512 2 NO CURRENT 1591935 27-JUN-17 2.8147E+14
3 2 29 52428800 512 2 YES INACTIVE 1590594 27-JUN-17 1591938 27-JUN-17
4 2 30 52428800 512 2 NO CURRENT 1591938 27-JUN-17 2.8147E+14
1,36
2,30
SQL> update t2 set contents =
2 'aaa' where id = 44449;
1 row updated.
SQL> commit;
Commit complete.
RUN {
allocate channel dev1 device type disk format '/tmp/backup/arc_%h_%e_%t';
backup as copy archivelog sequence 36 thread 1;
backup as copy archivelog sequence 30 thread 2;
release channel dev1;
}
begin
dbms_logmnr.add_logfile('/tmp/backup/arc_1_36_947808116');
dbms_logmnr.add_logfile('/tmp/backup/arc_2_30_947808118');
dbms_logmnr.start_logmnr(Options=>dbms_logmnr.dict_from_online_catalog);
end;
/
SQL> select username,scn,timestamp,sql_redo from v$logmnr_contents where username='JINGYU';
USERNAME SCN TIMESTAMP
------------------------------ ---------- ------------
SQL_REDO
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
JINGYU 1593448 27-JUN-17
set transaction read write;
JINGYU 1593448 27-JUN-17
update "JINGYU"."T2" set "CONTENTS" = 'aaa' where "CONTENTS" = 'WZTSQZWYOCNDFKSMNJQLOLFUBRDOHCBMKXBHAPJSHCMWBYZJVH' and ROWID = 'AAAVWVAAGAAAACLAAL';
JINGYU 1593450 27-JUN-17
commit;