本文是基于http://blog.csdn.net/tanqingru/article/details/7767466的整理版,此次恢复基于ODU测试1的表odu_test进行,分别测试了4.1.3和3.0.9。
ODU版本为“4.1.3试用版 for Windows”,结果发现试用版在恢复时有1000行左右的限制,超出的无法恢复。
3.0.9测试成功,本文只列出3.0.9的部分。
可从这下载odu4.1.3:http://www.laoxiong.net/odu或http://www.oracleodu.com/cn/,可参考老熊自己的博客:http://www.laoxiong.net/odu_recover_drop_table.html
1.环境准备:
D:\Downloads\odu\data>sqlplus"/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on星期五 7月 20 08:42:37 2012
Copyright (c) 1982, 2010, Oracle. Allrights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining andReal Application Testing options
SQL> alter system checkpoint;
系统已更改。
SQL> select count(*) frombamuta.odu_test;
COUNT(*)
----------
72259
SQL> drop table bamuta.odu_testpurge
表已删除。
SQL> alter system checkpoint;
2.恢复:
2.1将该表空间离线(保证删除的表的位置不被重写)
SQL> alter tablespace users offline;
表空间已更改。
2.2 通过logmnr,找出data_object_id
安装logmnr
SQL> @?/rdbms/admin/dbmslm.sql;
程序包已创建。
授权成功。
同义词已创建。
SQL> @?/rdbms/admin/dbmslmd.sql;
程序包已创建。
同义词已创建。
设置utl_file_dir
SQL> alter system setutl_file_dir='C:\Users\Administrator\Desktop\20120719ODU' scope=spfile;
系统已更改。
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup
ORACLE 例程已经启动。
Total System Global Area 535662592 bytes
Fixed Size 1375792 bytes
Variable Size 360710608 bytes
Database Buffers 167772160 bytes
Redo Buffers 5804032 bytes
数据库装载完毕。
数据库已经打开。
开始日志挖掘:
SQL> select group#,status from V$log;
GROUP# STATUS
---------- --------------------------------
1 CURRENT
2 INACTIVE
3 INACTIVE
SQL> select member fromV$logfile where group#=1;
MEMBER
--------------------------------------------------------------------------------
G:\APP\ADMINISTRATOR\ORADATA\TAN01\REDO01.LOG
SQL> execsys.dbms_logmnr.add_logfile(logfilename=>'G:\APP\ADMINISTRATOR\ORADATA\TAN01\REDO01.LOG');
PL/SQL 过程已成功完成。
SQL> execsys.dbms_logmnr.start_logmnr(options=>sys.dbms_logmnr.dict_from_online_catalog);
PL/SQL 过程已成功完成。
SQL> select scn,to_char(timestamp,'yyyy-mm-ddhh24:mi:ss'),sql_redo
2 fromV$logmnr_contents where operation='DDL'
3 and sql_redolike '%odu_test%';
SCN TO_CHAR(TIMESTAMP,'YYYY-MM-DDH SQL_REDO
---------- --------------------------------------------------------------------------------------------------------------
1161298 2012-07-20 13:54:04 create table odu_test as select * fromdba_objects
;
1161688 2012-07-20 14:00:41 droptable odu_test purge
SQL> select sql_redo fromV$logmnr_contents where timestamp=to_date('2012-07-20 14:00:41','yyyy-mm-ddhh24:mi:ss')
2 andoperation='DELETE';
SQL_REDO
--------------------------------------------------------------------------------
/* No SQL_REDO for temporary tables */
delete from "SYS"."OBJ$"where "OBJ#" = '73649' and"DATAOBJ#" = '73649' and "OW
可以看出删除的表data_object_id是73649
2.3通过ODU恢复:
配置config.txt,如下:
byte_order little
block_size 8192
data_path data
lob_path lob
charset_name ZHS16GBK
ncharset_name AL32UTF8
output_format text
lob_storage file
clob_byte_order little
trace_level 1
delimiter |
为配置control做准备
SQL> select ts#,file_id fno#,file_id rfno#,file_name,value
2 from V$tablespacet,dba_data_files d,v$parameter p
3 where t.name=d.tablespace_name
4 and p.name='db_block_size';
TS# FNO# RFNO# FILE_NAME VALUE
---------- ---------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0 1 1G:\APP\ADMINISTRATOR\ORADATA\TAN01\SYSTEM01.DBF 8192
1 2 2G:\APP\ADMINISTRATOR\ORADATA\TAN01\SYSAUX01.DBF 8192
2 3 3G:\APP\ADMINISTRATOR\ORADATA\TAN01\UNDOTBS01.DBF 8192
4 4 4G:\APP\ADMINISTRATOR\ORADATA\TAN01\USERS01.DBF 8192
配置control,如下:
#ts fno rfno filename block_size 0 1 1 G:\APP\ADMINISTRATOR\ORADATA\TAN01\SYSTEM01.DBF 8192
1 2 2G:\APP\ADMINISTRATOR\ORADATA\TAN01\SYSAUX01.DBF 8192
2 3 3G:\APP\ADMINISTRATOR\ORADATA\TAN01\UNDOTBS01.DBF 8192
4 4 4G:\APP\ADMINISTRATOR\ORADATA\TAN01\USERS01.DBF 8192
2.3使用ODU恢复
Oracle Data Unloader:Release 3.0.9
Copyright (c) 2008,2009 XiongJun. All rightsreserved.
Web: http://www.laoxiong.net
Email: magic007cn@gmail.com
loading default config.......
byte_order little
block_size 8192
data_path data
lob_path lob
charset_name ZHS16GBK
ncharset_name AL32UTF8
charset name 'AL32UTF8' not found,will usedefault ncharset AL16UTF16
output_format text
lob_storage file
clob_byte_order little
trace_level 1
delimiter |
load control file 'config.txt' successful
loading default control file ......
ts# fn rfn bsize blocks bf offset filename
---- ---- ---- ----- -------- -- --------------------------------------------------
0 1 1 8192 89600 N 0G:\APP\ADMINISTRATOR\ORADATA\TAN01\SYSTEM01.DBF
1 2 2 8192 76800 N 0G:\APP\ADMINISTRATOR\ORADATA\TAN01\SYSAUX01.DBF
2 3 3 8192 65920 N 0G:\APP\ADMINISTRATOR\ORADATA\TAN01\UNDOTBS01.DBF
4 4 4 8192 2560 N 0G:\APP\ADMINISTRATOR\ORADATA\TAN01\USERS01.DBF
load control file 'control.txt' successful
loading dictionary data......
ODU> scan extent tablespace 4;
scan extent start: 2012-07-20 14:32:39
scanning extent...
scanning extent finished.
scan extent completed: 2012-07-20 14:32:40
ODU> unload object 73649 sample
Unloading Object,object ID: 73649, Cluster: 0
output data is in file : 'data\ODU_0000073649.txt'
Sample result:
object id: 73649
tablespace no: 4
sampled 1061 rows
column count: 14
column 1 type:VARCHAR2
column 2 type:VARCHAR2
column 3 type: RAW
column 4 type: NUMBER
column 5 type: NUMBER
column 6 type:VARCHAR2
column 7 type: DATE
column 8 type: DATE
column 9 type:VARCHAR2
column 10 type: VARCHAR2
column 11 type: VARCHAR2
column 12 type: VARCHAR2
column 13 type: VARCHAR2
column 14 type: NUMBER
COMMAND:
unload object 73649 tablespace 4 column VARCHAR2VARCHAR2 RAW NUMBER NUMBER VARCHAR2 DATE DATE VARCHAR2 VARCHAR2 VARCHAR2VARCHAR2 VARCHAR2 NUMBER
ODU> unload object 73649tablespace 4 column VARCHAR2 VARCHAR2 RAW NUMBER NUMBER VARCHAR2 DATE DATEVARCHAR2 VARCHAR2 VARCHAR2 VARCHAR2 VARCHAR2 NUMBER
Unloading Object,object ID: 73649, Cluster: 0
72259 rows unloaded
恢复成功
2.4最后将数据恢复到表中:
SQL> alter tablespace users online;
SQL> @D:\Downloads\odu\data\ODU_0000073649.sql
D:\Downloads\odu\data>sqlldrbamuta/bamuta control=ODU_0000073649.ctl
达到提交点 -逻辑记录计数 224
达到提交点 -逻辑记录计数 448
达到提交点 -逻辑记录计数 672
达到提交点 -逻辑记录计数 896
……
……
……
达到提交点 -逻辑记录计数 71592
达到提交点 -逻辑记录计数 71816
达到提交点 -逻辑记录计数 72040
达到提交点 -逻辑记录计数 72259
SQL> select count(*) from odu_0000073649;
COUNT(*)
----------
72259
和之前的数据条目完全一样,但有一点缺点就是column的名字变了:
SQL> descodu_0000073649
Name Type Nullable Default Comments
----- -------------- -------- ---------------
C0001 VARCHAR2(4000) Y
C0002 VARCHAR2(4000) Y
C0003 RAW(2000) Y
C0004 NUMBER Y
C0005 NUMBER Y
C0006 VARCHAR2(4000) Y
C0007 DATE Y
C0008 DATE Y
C0009 VARCHAR2(4000) Y
C0010 VARCHAR2(4000) Y
C0011 VARCHAR2(4000) Y
C0012 VARCHAR2(4000) Y
C0013 VARCHAR2(4000) Y
C0014 NUMBER Y
无论如何,数据是完整的恢复了。