关于 RMAN 对于可插拔数据库按时间点的恢复 (文档 ID 1984554.1)

文档内容


用途

适用范围

详细信息

参考


适用于:

Oracle Database - Enterprise Edition - 版本 12.1.0.1 和更高版本
本文档所含信息适用于所有平台

用途

关于如何使用 RMAN 对可插拔数据库按时间点恢复的概述 - oracle 12C 新功能。

适用范围

本文档适用于 DBA 使用 RMAN 模式备份大规模数据库(CDB 包含一个或多个 PDB)。

要求了解 RMAN 知识和 RMAN 架构。
要求先查看下面的 Note:RMAN Pluggable Database Backup and Recovery (Note 1521005.1)

详细信息

关于可插拔数据库(指的是 PDB)的时间点恢复,需要包括 undo 在内的所有文件被恢复并且恢复至指定的时间点。由于所有的 PDB 数据库均写到根节点的 UNDO 表空间,所以 PDB 数据库的时间点恢复需要使用辅助实例(auxiliary)并且将 CDB$ROOT UNDO,SYSTEM,SYSAUX 和 SYSEXT 表空间恢复至辅助实例的根节点。 PDB 数据库自身的数据文件则恢复至其原有位置。

如果配置了快速恢复区,则辅助实例被建立在快速恢复区(fast recovery area),否则通过 AUXILIARY DESTINATION 参数指定到其它位置。

通过 RMAN 来完成恢复,需连接到跟容器(root container)。
PDB 数据库必须在关闭状态下恢复,但根及其它 PDB 数据库可以是打开状态。

 SQL> select con.name, df.file#
      from v$containers con, v$datafile df
      where con.con_id = df.con_id
      order by 1, 2;

NAME                                FILE#
------------------------------ ----------
CDB$ROOT                                1
CDB$ROOT                                3
CDB$ROOT                                4
CDB$ROOT                                6
PDB$SEED                                5
PDB$SEED                                7
PDBC101                                 8
PDBC101                                 9
PDBC101                                10

9 rows selected.


 
下面就是一个使用 AUXILIARY DESTINATION 参数替代默认快速恢复区的例子。

Recovery Manager: Release 12.1.0.1.0 - Production on Tue Jul 2 12:05:51 2013

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

connected to target database: CDBC101 (DBID=958900840)

RMAN> ALTER PLUGGABLE DATABASE pdbc101 CLOSE;
2> run
3> {
4>    SET UNTIL sequence 21 thread 1;
5>    RESTORE PLUGGABLE DATABASE pdbc101;
6>    RECOVER PLUGGABLE DATABASE pdbc101
7>       AUXILIARY DESTINATION '/u02/nfs_share/ora_data';
8> }
9> ALTER PLUGGABLE DATABASE pdbc101 OPEN RESETLOGS;
10>
11>
using target database control file instead of recovery catalog
Statement processed

executing command: SET until clause

Starting restore at 02-JUL-2013 12:05:56                <--- This is the restore of the PDB datafiles
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

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 /u02/nfs_share/ora_data/CDBC101/E0749F57C768731AE043A1DCA10A2DCA/datafile/o1_mf_system_8x32r2sh_.dbf
channel ORA_DISK_1: restoring datafile 00009 to /u02/nfs_share/ora_data/CDBC101/E0749F57C768731AE043A1DCA10A2DCA/datafile/o1_mf_sysaux_8x32r2o7_.dbf
channel ORA_DISK_1: restoring datafile 00010 to /u02/nfs_share/ora_data/CDBC101/E0749F57C768731AE043A1DCA10A2DCA/datafile/o1_mf_users_8x32szkj_.dbf
channel ORA_DISK_1: reading from backup piece /u02/nfs_share/reco_area/CDBC101/E0749F57C768731AE043A1DCA10A2DCA/backupset/2013_07_01/o1_mf_nnndf_TAG20130701T175102_8x39fwqb_.bkp
channel ORA_DISK_1: piece handle=/u02/nfs_share/reco_area/CDBC101/E0749F57C768731AE043A1DCA10A2DCA/backupset/2013_07_01/o1_mf_nnndf_TAG20130701T175102_8x39fwqb_.bkp tag=TAG20130701T175102
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:46
Finished restore at 02-JUL-2013 12:06:42

Starting recover at 02-JUL-2013 12:06:42
using channel ORA_DISK_1
RMAN-05026: WARNING: presuming following set of tablespaces applies to specified Point-in-Time

List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1

Creating automatic instance, with SID='sDdj'

initialization parameters used for automatic instance:
db_name=CDBC101
db_unique_name=sDdj_pitr_pdbc101_CDBC101
compatible=12.1.0.0.0
db_block_size=8192
db_files=200
sga_target=1G
processes=80
diagnostic_dest=/u01/app/oracle
db_create_file_dest=/u02/nfs_share/ora_data
log_archive_dest_1='location=/u02/nfs_share/ora_data'
enable_pluggable_database=true
_clone_one_pdb_recovery=true
#No auxiliary parameter file used


starting up automatic instance CDBC101                             <---- Starting another instance (besides the current running original database).

Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2296576 bytes
Variable Size                293602560 bytes
Database Buffers             767557632 bytes
Redo Buffers                   5480448 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  logseq 21 thread 1;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
}
executing Memory Script

executing command: SET until clause

Starting restore at 02-JUL-2013 12:06:57
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=111 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/nfs_share/reco_area/CDBC101/autobackup/2013_07_01/o1_mf_s_819654840_8x39jtc8_.bkp
channel ORA_AUX_DISK_1: piece handle=/u02/nfs_share/reco_area/CDBC101/autobackup/2013_07_01/o1_mf_s_819654840_8x39jtc8_.bkp tag=TAG20130701T175400
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
output file name=/u02/nfs_share/ora_data/CDBC101/controlfile/o1_mf_8x59l3sl_.ctl
Finished restore at 02-JUL-2013 12:07:05

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  logseq 21 thread 1;
# switch to valid datafilecopies
switch clone datafile  8 to datafilecopy  "/u02/nfs_share/ora_data/CDBC101/E0749F57C768731AE043A1DCA10A2DCA/datafile/o1_mf_system_8x32r2sh_.dbf";
switch clone datafile  9 to datafilecopy  "/u02/nfs_share/ora_data/CDBC101/E0749F57C768731AE043A1DCA10A2DCA/datafile/o1_mf_sysaux_8x32r2o7_.dbf";
switch clone datafile  10 to datafilecopy  "/u02/nfs_share/ora_data/CDBC101/E0749F57C768731AE043A1DCA10A2DCA/datafile/o1_mf_users_8x32szkj_.dbf";
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  4 to new;
set newname for clone datafile  3 to new;
set newname for clone datafile  6 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 4, 3, 6;
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

datafile 8 switched to datafile copy
input datafile copy RECID=3 STAMP=819720431 file name=/u02/nfs_share/ora_data/CDBC101/E0749F57C768731AE043A1DCA10A2DCA/datafile/o1_mf_system_8x32r2sh_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=4 STAMP=819720431 file name=/u02/nfs_share/ora_data/CDBC101/E0749F57C768731AE043A1DCA10A2DCA/datafile/o1_mf_sysaux_8x32r2o7_.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=5 STAMP=819720431 file name=/u02/nfs_share/ora_data/CDBC101/E0749F57C768731AE043A1DCA10A2DCA/datafile/o1_mf_users_8x32szkj_.dbf

executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME

Starting restore at 02-JUL-2013 12:07:11                     <---- This is the restore of the Root Container Database
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u02/nfs_share/ora_data/CDBC101/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u02/nfs_share/ora_data/CDBC101/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u02/nfs_share/ora_data/CDBC101/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u02/nfs_share/ora_data/CDBC101/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/nfs_share/reco_area/CDBC101/backupset/2013_07_01/o1_mf_nnndf_TAG20130701T175102_8x39c78w_.bkp
channel ORA_AUX_DISK_1: piece handle=/u02/nfs_share/reco_area/CDBC101/backupset/2013_07_01/o1_mf_nnndf_TAG20130701T175102_8x39c78w_.bkp tag=TAG20130701T175102
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 02-JUL-2013 12:08:27

datafile 1 switched to datafile copy
input datafile copy RECID=10 STAMP=819720507 file name=/u02/nfs_share/ora_data/CDBC101/datafile/o1_mf_system_8x59ljbm_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=11 STAMP=819720507 file name=/u02/nfs_share/ora_data/CDBC101/datafile/o1_mf_undotbs1_8x59ljgm_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=12 STAMP=819720507 file name=/u02/nfs_share/ora_data/CDBC101/datafile/o1_mf_sysaux_8x59ljf6_.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=13 STAMP=819720507 file name=/u02/nfs_share/ora_data/CDBC101/datafile/o1_mf_users_8x59ljjy_.dbf

contents of Memory Script:
{
# set requested point in time
set until  logseq 21 thread 1;
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  4 online";
sql clone "alter database datafile  3 online";
sql clone 'PDBC101' "alter database datafile 8 online";
sql clone 'PDBC101' "alter database datafile 9 online";
sql clone 'PDBC101' "alter database datafile 10 online";
sql clone "alter database datafile  6 online";
# recover pdb
recover clone database tablespace  "SYSTEM", "UNDOTBS1", "SYSAUX", "USERS" pluggable database
 'PDBC101'   delete archivelog;
sql clone 'alter database open read only';
plsql <<    add_dropped_ts;
end; >>>;
plsql <<    save_pdb_clean_scn;
end; >>>;
# shutdown clone before import
shutdown clone abort
plsql <<    pdbpitr_inspect(pdbname =>  'PDBC101');
end; >>>;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  1 online
sql statement: alter database datafile  4 online
sql statement: alter database datafile  3 online
sql statement: alter database datafile  8 online
sql statement: alter database datafile  9 online
sql statement: alter database datafile  10 online
sql statement: alter database datafile  6 online

Starting recover at 02-JUL-2013 12:08:28
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 16 is already on disk as file /u02/nfs_share/reco_area/CDBC101/archivelog/2013_07_01/o1_mf_1_16_8x39jq8g_.arc
archived log for thread 1 with sequence 17 is already on disk as file /u02/nfs_share/reco_area/CDBC101/archivelog/2013_07_01/o1_mf_1_17_8x3r1zf6_.arc
archived log for thread 1 with sequence 18 is already on disk as file /u02/nfs_share/reco_area/CDBC101/archivelog/2013_07_01/o1_mf_1_18_8x3r6pqc_.arc
archived log for thread 1 with sequence 19 is already on disk as file /u02/nfs_share/reco_area/CDBC101/archivelog/2013_07_01/o1_mf_1_19_8x3rcrrv_.arc
archived log for thread 1 with sequence 20 is already on disk as file /u02/nfs_share/reco_area/CDBC101/archivelog/2013_07_02/o1_mf_1_20_8x4620tk_.arc
archived log file name=/u02/nfs_share/reco_area/CDBC101/archivelog/2013_07_01/o1_mf_1_16_8x39jq8g_.arc thread=1 sequence=16
archived log file name=/u02/nfs_share/reco_area/CDBC101/archivelog/2013_07_01/o1_mf_1_17_8x3r1zf6_.arc thread=1 sequence=17
archived log file name=/u02/nfs_share/reco_area/CDBC101/archivelog/2013_07_01/o1_mf_1_18_8x3r6pqc_.arc thread=1 sequence=18
archived log file name=/u02/nfs_share/reco_area/CDBC101/archivelog/2013_07_01/o1_mf_1_19_8x3rcrrv_.arc thread=1 sequence=19
archived log file name=/u02/nfs_share/reco_area/CDBC101/archivelog/2013_07_02/o1_mf_1_20_8x4620tk_.arc thread=1 sequence=20
media recovery complete, elapsed time: 00:00:21
Finished recover at 02-JUL-2013 12:08:52

sql statement: alter database open read only


Oracle instance shut down


Removing automatic instance
Automatic instance removed
auxiliary instance file /u02/nfs_share/ora_data/CDBC101/datafile/o1_mf_sysaux_8x59ljf6_.dbf deleted
auxiliary instance file /u02/nfs_share/ora_data/CDBC101/controlfile/o1_mf_8x59l3sl_.ctl deleted
Finished recover at 02-JUL-2013 12:09:02

Statement processed

Recovery Manager complete.

 

如果您想更多的控制辅助库的配置,则您可以使用辅助参数文件。

下面列出了需要包含的主要参数:

db_name=CDBC101                              <--- 与原始 CDB 相同名字
db_unique_name=sDdj_pitr_pdbc101_CDBC101     <--- 唯一名字,在这个主机必须唯一。
compatible=12.1.0.0.0                        <--- 与原始 CDB 相同名字
db_block_size=8192                           <--- 与原始 CDB 相同名字
db_files=200                                 <--- 与原始 CD B相同或者更高的值
sga_target=1G                                <--- 可配置
processes=80                                 <--- 确保足够大,如果使用 ASM,还需要额外的进程
diagnostic_dest=/u01/app/oracle              <--- 可配置
enable_pluggable_database=true               <--- 强制!!
_clone_one_pdb_recovery=true                 <--- 强制!!

 

相关的命令如下:

RMAN>  ALTER PLUGGABLE DATABASE pdbc101 CLOSE;
run
{
   SET AUXILIARY INSTANCE PARAMETER FILE TO '/tmp/auxpfile.ora';

   SET UNTIL sequence 21 thread 1;
   RESTORE PLUGGABLE DATABASE pdbc101;
   RECOVER PLUGGABLE DATABASE pdbc101
      AUXILIARY DESTINATION '/u02/nfs_share/ora_data';
}
ALTER PLUGGABLE DATABASE pdbc101 OPEN RESETLOGS;

参考

NOTE:1521005.1 - RMAN Pluggable Database Backup and Recovery in a Multitenant Environment

请使用浏览器的分享功能分享到微信等