Oracle技術:使用rman進行資料表空間基於時間點的恢複

來源:互聯網
上載者:User

執行個體說明:

(1)先建立2個資料表空間。

create tablespace user01 datafile '+DG1' size 1M;

create tablespace user02 datafile '+DG1' size 1M;

(2)在每個資料表空間上各建立一張表。

create table scott.customers

(cust_id int,cust_name varchar2(10)) tablespace user01;

create table scott.sales

(id int,cust_name varchar2(10),sales_amount number(8,2)) tablespace user02;

(3)在每個表中插入2條記錄,提交。檢查當前的時間點,待會資料表空間user01要恢複到目前時間點。

insert into scott.customers values(1,'SOCTT');

insert into scott.customers values(2,'SMITH');

insert into scott.sales values(1,'SCOTT',8000);

insert into scott.sales values(1,'SMITH',10000);

COMMIT;

ALTER SYSTEM SWITCH LOGFILE;

ALTER SYSTEM SWITCH LOGFILE;

ALTER SYSTEM SWITCH LOGFILE;

date

2010年 03月 11日 星期四 21:44:52 CST

(4) truncate 表1,往表2中插入2條記錄。在資料表空間1中再建立一個表。

truncate table scott.customers;

insert into scott.sales values(3,'SCOTT',6000);

insert into scott.sales values(4,'BLAKE',6700);

commit;

create table scott.employee(id int,name varchar2(10)) tablespace user01;

(5) 利用rman進行資料表空間1基於時間點的恢複。

--rman部分恢複資料表空間

recover tablespace user01

until time "to_timestamp('2010-03-11 21:44:52','yyyy-mm-dd hh24:mi:ss')"

auxiliary destination '/home/oracle/backup';

(6)將資料表空間user01 聯機,檢查表1的資料是否找回來,檢查表2的資料是否是4條,檢查新建立的表是否已經不存在。

alter tablespace user01 online;

select * from scott.customers;

CUST_ID CUST_NAME

---------- ----------

1 SOCTT

2 SMITH

select * from scott.sales;

ID CUST_NAME SALES_AMOUNT

---------- ---------- ------------

1 SCOTT 8000

1 SMITH 10000

3 SCOTT 6000

4 BLAKE 6700

select * from dba_tables where owner = 'SCOTT' and table_name='EMPLOYEE';

no rows selected

一切如我們所願,此時,資料表空間不完全恢複完成。

注意:

更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/

只有自包含的資料表空間,才能基於單獨不完全恢複。所謂自包含,是指該資料表空間中的對象不依賴於其它資料表空間中的對象,如該資料表空間中索引的基本在其它資料表空間,該表中

某些表的lob列放在其它資料表空間。

如在上例中,執行:

create index scott.idx_customers on scott.customers(cust_name) tablespace user02;

begin

dbms_tts.transport_set_check('user02',true);

end;

select * from transport_set_violations;

會提示:Index SCOTT.IDX_CUSTOMERS in tablespace USER02 points to table SCOTT.CUSTOMERS in tablespace USER01.

begin

dbms_tts.transport_set_check('USER01,user02',true);

end;

select * from transport_set_violations;

不會有任何提示,因為user01/user02資料表空間作為一個集合,是自包含的。

上面這

個過程看起來簡單,但是資料庫在步驟5時,自己做了很多的工作,所有以前人工需要做的它一步也沒有少做,具體如下:

(1)建立參數檔案

(2)啟動輔助instance到nomount狀態

(3)恢複輔助instance控制檔案

(4)啟動輔助instance到mount,restore資料表空間對應的資料檔案及輔助檔案(資料表空間system和undo的檔案)

(5)將上面的幾個資料檔案online,恢複資料表空間user01,system和undo

(6)open 次要資料庫(resetlogs)

(7)exp 匯出資料表空間user01;

(8)關閉輔助庫

(9)imp 資料表空間user01;

(10)刪除輔助庫對應的資料檔案及其它檔案。

作者:51cto Oracle小混子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.