【備份恢復】閃回資料庫(五)RMAN 命令列閃回資料庫

不一樣的天空w發表於2016-10-17

RMAN 命令列閃回資料庫常用方法
1) 基於時間(與在 SQLPLUS 下基於時間的閃回非常相似,只是格式稍有變化,就不重複測試了)
RMAN> FLASHBACK DATABASE TO TIME = "TO_DATE('2012-08-03 14:51:13','YYYY-MM-DDHH24:MI:SS')";
2) 基於 SCN(與在 SQLPLUS 下基於 SCN 的閃回非常相似,只是格式稍有變化,就不重複測試了)
RMAN> FLASHBACK DATABASE TO SCN=23565;
3) 基於:歸檔序號
RMAN> FLASHBACK DATABASE TO SEQUENCE=223 THREAD=1;


測試基於歸檔序號閃回資料庫
1) 檢視當前的日誌序號為1

YS@ORA11GR2>archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     1

Next log sequence to archive   1

Current log sequence           1


2) SCOTT 下建立測試表及插入一條記錄,此時所產生的日誌資料都存在序列號為1 的日誌檔案中

SYS@ORA11GR2>conn scott/tiger

Connected.

SCOTT@ORA11GR2>create table fbdb_rman_seq as select * from fbdb_scn where 1=2;

 

Table created.

 

SCOTT@ORA11GR2>insert into fbdb_rman_seq select 1 as id,dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;

 

1 row created.

 

SCOTT@ORA11GR2>commit;

 

Commit complete.

 

SCOTT@ORA11GR2>select * from fbdb_rman_seq;

 

        ID        SCN DD

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

         1    1879882 01-OCT-16

 

3) 手工歸檔當前日誌,歸檔後,當前日誌的序號為 2

SYS@ORA11GR2>alter system switch logfile;(或者alter system archive log current

 

System altered.

 

SYS@ORA11GR2>archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     1

Next log sequence to archive   2

Current log sequence           2


4) 再次向 scott.fbdb_rman_seq 插入一條記錄,此時的日誌資訊都存在序號為 2 的日誌檔案中

SYS@ORA11GR2>insert into scott.fbdb_rman_seq select 2 as id,dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;

 

1 row created.

 

SYS@ORA11GR2>commit;

 

Commit complete.

 

SYS@ORA11GR2>select * from scott.fbdb_rman_seq;

 

        ID        SCN DD

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

         1    1879882 01-OCT-16

         2    1880119 01-OCT-16

 

--既然測試,就稍微狠點兒,把表徹底刪除

SYS@ORA11GR2>drop table scott.fbdb_rman_seq;

 

Table dropped.

 

5) 恢復操作:登陸 RMAN 將資料庫啟動到 mount 模式下(在 SQLPLUS 下執行這步也是一樣的)

[oracle@wang admin]$ rman target /

 

Recovery Manager: Release 11.2.0.4.0 - Production on Sat Oct 1 09:02:45 2016

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

connected to target database: ORA11GR2 (DBID=237843809)

 

RMAN> shutdown immediate;

 

using target database control file instead of recovery catalog

database closed

database dismounted

Oracle instance shut down

RMAN> startup mount;

 

connected to target database (not started)

Oracle instance started

database mounted

 

Total System Global Area     730714112 bytes

 

Fixed Size                     2256832 bytes

Variable Size                452984896 bytes

Database Buffers             272629760 bytes

Redo Buffers                   2842624 bytes

 

6) RMAN 命令列下執行閃回,基於序號為 1的歸檔, 1 號執行緒

RMAN> flashback database to sequence =1 thread=1;

 

Starting flashback at 01-OCT-16

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=18 device type=DISK

 

 

starting media recovery

media recovery complete, elapsed time: 00:00:01

 

Finished flashback at 01-OCT-16

 

7) resetlogs 方式開啟資料庫

RMAN> alter database open resetlogs;

 

database opened

 

8) 回到 SQLPLUS 驗證測試表fbdb_rman_seq

SYS@ORA11GR2>select * from scott.fbdb_rman_seq;

 

        ID        SCN DD

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

         1    1879882 01-OCT-16

 

 注意事項
1) 當閃回資料庫操作完成後,開啟資料庫:
- 在只讀模式下驗證是否使用了正確的目標時間或 SCN
- 使用 RESETLOGS 選項以允 DML 操作。
2) 閃回相反的是恢復
3) 在下列情況下,您不能使用閃回資料庫:
- 已恢復或重建控制檔案。
- 表空間被刪除。
- 資料檔案已被減小尺寸。
4) 使用 TO BEFORE RESETLOGS 子句閃回到最後一次 RESETLOGS 操作

 

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

相關文章