全部博文(389)
分类: Oracle
2014-10-18 17:48:34
ORACLE 12C PDB的PITR恢复
在使用cdb模式的12c中,单个pdb可以进行PITR恢复,不会影响到整个到cdb.
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 READ WRITE
在pdb1中创建表t1
SQL> alter session set container=pdb1;
Session altered.
SQL> create table t1 as select * from dba_tables;
Table created.
当前的scn号是5924809,
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
5924809
现在使用rman对于整个cdb做一个备份,同时还需要备份归档日志
[oracle@localhost ~]$ $ORACLE_HOME/bin/rman target / nocatalog
RMAN> run
2> {
3> allocate channel c1 device type disk;
4> backup database plus archivelog;
5> release channel c1;
6> }
allocated channel: c1
channel c1: SID=592 device type=DISK
Starting backup at 18-OCT-14
current log archived
Starting backup at 18-OCT-14
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=220 RECID=179 STAMP=857858571
input archived log thread=1 sequence=221 RECID=180 STAMP=857865915
................
手动删除表1,模拟灾难发生.
SQL> drop table t1;
Table dropped.
SQL> alter session set container=cdb$root;
Session altered.
在对pluggable database做恢复时需要关闭,这和non-cbd模式的恢复的原则也类似.
SQL> alter pluggable database pdb1 close;
Pluggable database altered.
使用rman对pdb1执行PITR
RMAN> run
2> {
3> set until scn 5924809;
4> restore pluggable database pdb1;
5> recover pluggable database pdb1;
6> }
executing command: SET until clause
Starting restore at 18-OCT-14
configuration for DISK channel 2 is ignored
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=592 device type=DISK
..............
Removing automatic instance
Automatic instance removed
auxiliary instance file /usr/tmp/T2/datafile/o1_mf_sysaux_b44f8zvx_.dbf deleted
auxiliary instance file /usr/tmp/T2/controlfile/o1_mf_b44f8q03_.ctl deleted
Finished recover at 18-OCT-14
恢复完成,打开pluggable database pdb1
SQL> alter pluggable database pdb1 open;
alter pluggable database pdb1 open
*
ERROR at line 1:
ORA-01113: file 10 needs media recovery
由于是PITR恢复,pluggable database 也需要以resetlogs方式来打开
SQL> alter pluggable database pdb1 open resetlogs;
Pluggable database altered.
SQL> alter session set container=pdb1;
Session altered.
SQL> select count(*) from t1;
COUNT(*)
----------
2338
可以看到被删除的表已经被恢复回来,实验没有考虑rman的单表恢复新特性.
值得注意的是对pdb做PITR时,在rman的run语句块中不能显式分配通道,否则会报以下错误
RMAN> run
2> {
3> allocate channel c1 device type disk;
4> allocate channel c2 device type disk;
5> set until scn 5924809;
6> restore pluggable database pdb1;
7> recover pluggable database pdb1;
8> release channel c1;
9> release channel c2;
10> }
............
executing command: SET until clause
Starting restore at 18-OCT-14
Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
released channel: c1
released channel: c2
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/18/2014 09:35:40
RMAN-03015: error occurred in stored script Memory Script
RMAN-06034: at least 1 channel must be allocated to execute this command