oracle 12.2C+ PDB基於時間點的恢復

在12.1當中,如果PDB需要恢復到和CDB不同的時間點,比較麻煩,注意是因爲在12.1中使用的共享UNDO.PDB中的回滾段的信息存在共享undo中.

而共享undo不只是爲此PDB使用.所以在恢復的時候需要創建輔助實例,這樣可以避免共享undo在恢復的過程中對其他PDB的影響,具體步驟:

 

alter pluggable database pdb close;
run{
set until scn=161100;
restore pluggable database pdb;
recover pluggable database pdb auxiliary destination='/var/tmp';
alter pluggable database pdb open resetlogs;
}

 而在12.2中,使用了本地undo,這樣就可以避免上面的問題.下面是一個PDB基於時間點的恢復:

1.查看pdb的備份:

 

RMAN> list backup of pluggable database brent;

 

 
List of Backup Sets
===================

 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time     
------- ---- -- ---------- ----------- ------------ --------------------
58      Full    36.27M     DISK        00:00:30     29-SEP-2019 23:38:20
        BP Key: 58   Status: AVAILABLE  Compressed: YES  Tag: TAG20190929T233749
        Piece Name: /backup/3eud0v2e_1_1.bak
  List of Datafiles in backup set 58
  Container ID: 3, PDB Name: BRENT
  File LV Type Ckp SCN    Ckp Time             Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- -------------------- ----------- ------ ----
  8       Full 4094527    29-SEP-2019 23:37:50              NO    /u01/app/oracle/oradata/ORA19C/brent/system01.dbf
  36      Full 4094527    29-SEP-2019 23:37:50              NO    /u01/app/oracle/oradata/ORA19C/brent/test.dbf

 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time     
------- ---- -- ---------- ----------- ------------ --------------------
59      Full    1.09M      DISK        00:00:01     29-SEP-2019 23:38:28
        BP Key: 59   Status: AVAILABLE  Compressed: YES  Tag: TAG20190929T233749
        Piece Name: /backup/3hud0v3j_1_1.bak
  List of Datafiles in backup set 59
  Container ID: 3, PDB Name: BRENT
  File LV Type Ckp SCN    Ckp Time             Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- -------------------- ----------- ------ ----
  10      Full 4094565    29-SEP-2019 23:38:27              NO    /u01/app/oracle/oradata/ORA19C/brent/undotbs01.dbf

 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time     
------- ---- -- ---------- ----------- ------------ --------------------
68      Full    11.99M     DISK        00:00:09     29-SEP-2019 23:39:17
        BP Key: 68   Status: AVAILABLE  Compressed: YES  Tag: TAG20190929T233749
        Piece Name: /backup/3pud0v4s_1_1.bak
  List of Datafiles in backup set 68
  Container ID: 3, PDB Name: BRENT
  File LV Type Ckp SCN    Ckp Time             Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- -------------------- ----------- ------ ----
  9       Full 4094637    29-SEP-2019 23:39:08              NO    /u01/app/oracle/oradata/ORA19C/brent/sysaux01.dbf
  11      Full 4094637    29-SEP-2019 23:39:08              NO    /u01/app/oracle/oradata/ORA19C/brent/users01.dbf

 

2.查看當前CDB的scn

 

SQL> select current_scn from v$database;

 
CURRENT_SCN
-----------
    4182684

 

由上可以看到當前CDB的scn爲4182684,而備份的PDB的scn爲4094565

下面我們模擬恢復PDB的scn到這當中的任意scn:4120000

 

3.關閉pdb

首先關閉PDB

 

SQL> show pdbs  

 
    CON_ID CON_NAME           OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED           READ ONLY  NO
     3 BRENT              READ WRITE NO
     4 TESTPDB1           READ WRITE NO
     5 TESTPDB2           READ WRITE NO
     7 TESTPDB3           READ WRITE NO
SQL> alter pluggable database brent close;

 
Pluggable database altered

模擬故障PDB數據文件丟失,我們這裏直接進行刪除.

 

[oracle@ora19c ORA19C]$ cd brent
[oracle@ora19c brent]$ ls
sysaux01.dbf  system01.dbf  temp01.dbf  test.dbf  undotbs01.dbf  users01.dbf
[oracle@ora19c brent]$ rm -rf *

 

 

4.進行恢復

基於scn進行PDB的恢復,語法如下:

run{

set until scn=4120000;

restore pluggable database brent;

recover pluggable database brent;

alter pluggable database brent open resetlogs;

}

 


 
RMAN> run{
set until scn=4120000;
restore pluggable database brent;
recover pluggable database brent;
alter pluggable database brent open resetlogs;
}2> 3> 4> 5> 6> 

 
executing command: SET until clause

 
Starting restore at 30-SEP-2019 21:08:58
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4

 
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/ORA19C/brent/system01.dbf
channel ORA_DISK_1: restoring datafile 00036 to /u01/app/oracle/oradata/ORA19C/brent/test.dbf
channel ORA_DISK_1: reading from backup piece /backup/3eud0v2e_1_1.bak
channel ORA_DISK_2: starting datafile backup set restore
channel ORA_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_DISK_2: restoring datafile 00010 to /u01/app/oracle/oradata/ORA19C/brent/undotbs01.dbf
channel ORA_DISK_2: reading from backup piece /backup/3hud0v3j_1_1.bak
channel ORA_DISK_3: starting datafile backup set restore
channel ORA_DISK_3: specifying datafile(s) to restore from backup set
channel ORA_DISK_3: restoring datafile 00009 to /u01/app/oracle/oradata/ORA19C/brent/sysaux01.dbf
channel ORA_DISK_3: restoring datafile 00011 to /u01/app/oracle/oradata/ORA19C/brent/users01.dbf
channel ORA_DISK_3: reading from backup piece /backup/3pud0v4s_1_1.bak
channel ORA_DISK_2: piece handle=/backup/3hud0v3j_1_1.bak tag=TAG20190929T233749
channel ORA_DISK_2: restored backup piece 1
channel ORA_DISK_2: restore complete, elapsed time: 00:00:03
channel ORA_DISK_3: piece handle=/backup/3pud0v4s_1_1.bak tag=TAG20190929T233749
channel ORA_DISK_3: restored backup piece 1
channel ORA_DISK_3: restore complete, elapsed time: 00:00:07
channel ORA_DISK_1: piece handle=/backup/3eud0v2e_1_1.bak tag=TAG20190929T233749
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 30-SEP-2019 21:09:14

 
Starting recover at 30-SEP-2019 21:09:14
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4

 

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

 
Finished recover at 30-SEP-2019 21:09:16

 
Statement processed

 
RMAN> 

 

到此恢復就完成了.

 

SQL> show pdbs

 
    CON_ID CON_NAME           OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED           READ ONLY  NO
     3 BRENT              READ WRITE NO
     4 TESTPDB1           READ WRITE NO
     5 TESTPDB2           READ WRITE NO
     7 TESTPDB3           READ WRITE NO

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章