Oracle Drop表(purge)恢復(ODU)

chenoracle發表於2017-12-29


Oracle Drop 表(purge )恢復 (ODU)



透過 ODU 恢復 drop 掉的表 (purge) 基本步驟如下

1:offline表所在表空間;

2:透過 logminer 挖出被 drop 表對應 object_id

3:使用 ODU 工具將表資料抽到檔案中;

4:使用 sqlldr 將資料載入到資料庫;

5:驗證;


一:主備測試資料                

1 建立測試表 odu_test

create table odu_test (a number,b varchar2(10),c nvarchar2(30),d varchar2(20),e date,f timestamp,g binary_float,h binary_double);


2 插入測試資料

insert into odu_test

  select rownum,

         lpad('x', 10),

         'NC測試 ' || rownum,

         'ZHS測試 ' || rownum,

         sysdate + dbms_random.value(0, 100),

         systimestamp + dbms_random.value(0, 100),

         rownum + dbms_random.value(0, 10000),

         rownum + dbms_random.value(0, 10000)

    from dba_objects

   where rownum <= 10000;

commit;


3 備份並刪除表 odu_test ,模擬誤刪除

create table odu1 as select * from odu_test;

drop table odu_test purge;


二:恢復

1 offline表所在表空間

alter tablespace users offline;


2 使用 logminer 來查詢被 drop 表的object_id

select group#,status from v$log;

select member from v$logfile where group#=1;

SQL> exec sys.dbms_logmnr.start_logmnr(options=>sys.dbms_logmnr.dict_from_online_catalog);

SQL> select scn,timestamp,sql_redo from v$logmnr_contents where operation='DDL' and sql_redo like '%odu_test%' order by 2 ;

......

    990001 2017/12/27  drop table odu_test purge;

SQL> select scn,timestamp,sql_redo from v$logmnr_contents where timestamp=to_date('2017-12-27','yyyy-mm-dd') order by 1;

SQL> create table logmnr_1 as (select * from  v$logmnr_contents;

SQL> exec sys.dbms_logmnr.end_logmnr;


select *from sys.logmnr_1 where scn='990001';  ---DATA_OB# 87270

select * from sys.logmnr_1 where /*operation='DDL' and*/ LOWER(sql_redo) like '%odu_test%' order by 2 ;

/*

delete from "SYS"."OBJ$" where "OBJ#" = '87270' and "DATAOBJ#" = '87270' and "OWNER#" = '84' and "NAME" = 'ODU_TEST' and "NAMESPACE" = '1' and "SUBNAME" IS NULL and "TYPE#" = '2' and "CTIME" = TO_DATE('27-12 -17', 'DD-MON-RR') and "MTIME" = TO_DATE('27-12 -17', 'DD-MON-RR') and "STIME" = TO_DATE('27-12 -17', 'DD-MON-RR') and "STATUS" = '1' and "REMOTEOWNER" IS NULL and "LINKNAME" IS NULL and "FLAGS" = '0' and "OID$" IS NULL and "SPARE1" = '6' and "SPARE2" = '1' and "SPARE3" = '84' and "SPARE4" IS NULL and "SPARE5" IS NULL and "SPARE6" IS NULL and ROWID = 'AAAAASAABAAAVKkABB';

*/


3 修改原 control.txt 檔案

select d.TS#        ts,

       d.FILE#      fno,

       d.FILE#      fno,

       d.NAME       filename,

       d.BLOCK_SIZE block_size

  from v$datafile d

 order by ts;


0    1    1    D:\APP\ADMINISTRATOR\ORADATA\CJC\SYSTEM01.DBF  8192

1    2    2    D:\APP\ADMINISTRATOR\ORADATA\CJC\SYSAUX01.DBF  8192

2    3    3    D:\APP\ADMINISTRATOR\ORADATA\CJC\UNDOTBS01.DBF 8192

4    4    4    D:\APP\ADMINISTRATOR\ORADATA\CJC\USERS01.DBF   8192

---control.txt


4 登入 odu

 

5 掃描資料

 

--- 企業版 ODU 需要授權

--- 本次實驗使用測試版 ODU

 

6 恢復表

......

生成建立表的語句和控制檔案

這個命令生成了如下檔案

ODU_0000087270.ctl ODU_0000087270.sql

 

CREATE TABLE "ODU_0000087270"

(

    "C0001" NUMBER ,

    "C0002" VARCHAR2(4000) ,

    "C0003" NVARCHAR2(2000) ,

    "C0004" VARCHAR2(4000) ,

    "C0005" DATE ,

    "C0006" DATE ,

    "C0007" BINARY_FLOAT ,

    "C0008" BINARY_DOUBLE

);

 

7 online 表空間

alter tablespace users online;

 

8 透過 sqlldr 載入資料

 

9 驗證資料

select count(*) from ODU_0000087270;  ---10000

檢視恢復後表資料

select * from ODU_0000087270;

......

檢視備份表資料

......

 

原文連結如下:

Oracle Drop表(purge)恢復(ODU) Oracle Drop表(purge)恢復(ODU) Oracle Drop表(purge)恢復(ODU)

 

  歡迎關注我的微信公眾號"IT小Chen",共同學習,共同成長!!!

Oracle Drop表(purge)恢復(ODU)

Oracle Drop表(purge)恢復(ODU)



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29785807/viewspace-2149476/,如需轉載,請註明出處,否則將追究法律責任。

相關文章