在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:20BP Key: 58 Status: AVAILABLE Compressed: YES Tag: TAG20190929T233749Piece Name: /backup/3eud0v2e_1_1.bakList of Datafiles in backup set 58Container ID: 3, PDB Name: BRENTFile 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.dbf36 Full 4094527 29-SEP-2019 23:37:50 NO /u01/app/oracle/oradata/ORA19C/brent/test.dbfBS Key Type LV Size Device Type Elapsed Time Completion Time------- ---- -- ---------- ----------- ------------ --------------------59 Full 1.09M DISK 00:00:01 29-SEP-2019 23:38:28BP Key: 59 Status: AVAILABLE Compressed: YES Tag: TAG20190929T233749Piece Name: /backup/3hud0v3j_1_1.bakList of Datafiles in backup set 59Container ID: 3, PDB Name: BRENTFile 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.dbfBS Key Type LV Size Device Type Elapsed Time Completion Time------- ---- -- ---------- ----------- ------------ --------------------68 Full 11.99M DISK 00:00:09 29-SEP-2019 23:39:17BP Key: 68 Status: AVAILABLE Compressed: YES Tag: TAG20190929T233749Piece Name: /backup/3pud0v4s_1_1.bakList of Datafiles in backup set 68Container ID: 3, PDB Name: BRENTFile 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.dbf11 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 pdbsCON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 BRENT READ WRITE NO4 TESTPDB1 READ WRITE NO5 TESTPDB2 READ WRITE NO7 TESTPDB3 READ WRITE NOSQL> alter pluggable database brent close;Pluggable database altered
模拟故障PDB数据文件丢失,我们这里直接进行删除.
[oracle@ora19c ORA19C]$ cd brent[oracle@ora19c brent]$ lssysaux01.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 clauseStarting restore at 30-SEP-2019 21:08:58using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4channel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/ORA19C/brent/system01.dbfchannel ORA_DISK_1: restoring datafile 00036 to /u01/app/oracle/oradata/ORA19C/brent/test.dbfchannel ORA_DISK_1: reading from backup piece /backup/3eud0v2e_1_1.bakchannel ORA_DISK_2: starting datafile backup set restorechannel ORA_DISK_2: specifying datafile(s) to restore from backup setchannel ORA_DISK_2: restoring datafile 00010 to /u01/app/oracle/oradata/ORA19C/brent/undotbs01.dbfchannel ORA_DISK_2: reading from backup piece /backup/3hud0v3j_1_1.bakchannel ORA_DISK_3: starting datafile backup set restorechannel ORA_DISK_3: specifying datafile(s) to restore from backup setchannel ORA_DISK_3: restoring datafile 00009 to /u01/app/oracle/oradata/ORA19C/brent/sysaux01.dbfchannel ORA_DISK_3: restoring datafile 00011 to /u01/app/oracle/oradata/ORA19C/brent/users01.dbfchannel ORA_DISK_3: reading from backup piece /backup/3pud0v4s_1_1.bakchannel ORA_DISK_2: piece handle=/backup/3hud0v3j_1_1.bak tag=TAG20190929T233749channel ORA_DISK_2: restored backup piece 1channel ORA_DISK_2: restore complete, elapsed time: 00:00:03channel ORA_DISK_3: piece handle=/backup/3pud0v4s_1_1.bak tag=TAG20190929T233749channel ORA_DISK_3: restored backup piece 1channel ORA_DISK_3: restore complete, elapsed time: 00:00:07channel ORA_DISK_1: piece handle=/backup/3eud0v2e_1_1.bak tag=TAG20190929T233749channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:15Finished restore at 30-SEP-2019 21:09:14Starting recover at 30-SEP-2019 21:09:14using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4starting media recoverymedia recovery complete, elapsed time: 00:00:01Finished recover at 30-SEP-2019 21:09:16Statement processedRMAN>
到此恢复就完成了.
SQL> show pdbsCON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 BRENT READ WRITE NO4 TESTPDB1 READ WRITE NO5 TESTPDB2 READ WRITE NO7 TESTPDB3 READ WRITE NO