Oracle 12C RMAN中使用until time子句对Non-CDB中的表执行按时间点恢复

在RMAN中使用until time子句对Non-CDB中的表执行按时间点恢复操作步骤如下
1.对整个Non-CDB(orcl)生成RMAN备份

RMAN> backup as compressed backupset database format '+data/backup/%d_%I_%U_%t' plus archivelog format 'arc_%d_%T_%U';

Starting backup at 10-JAN-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=13 RECID=1 STAMP=964995986
input archived log thread=1 sequence=14 RECID=2 STAMP=965007422
input archived log thread=1 sequence=15 RECID=3 STAMP=965007493
input archived log thread=1 sequence=16 RECID=4 STAMP=965007542
input archived log thread=1 sequence=17 RECID=5 STAMP=965011311
input archived log thread=1 sequence=18 RECID=6 STAMP=965011687
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/product/12.2.0/db/dbs/arc_ORCL_20180110_21so9q78_1_1 tag=TAG20180110T024807 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 10-JAN-18

Starting backup at 10-JAN-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA/orcl/datafile/users01.dbf
input datafile file number=00001 name=+DATA/orcl/datafile/system01.dbf
input datafile file number=00002 name=+DATA/orcl/datafile/sysaux01.dbf
input datafile file number=00003 name=+DATA/orcl/datafile/undotbs01.dbf
input datafile file number=00005 name=+DATA/orcl/datafile/usertbs01.dbf
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=+DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 tag=TAG20180110T024824 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 10-JAN-18

Starting backup at 10-JAN-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=19 RECID=7 STAMP=965011751
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/product/12.2.0/db/dbs/arc_ORCL_20180110_23so9q98_1_1 tag=TAG20180110T024912 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-18

Starting Control File and SPFILE Autobackup at 10-JAN-18
piece handle=+DATA/backup/c-1492772871-20180110-01 comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-18

2.在删除表t_emp之前记录当前scn与时间,在执行恢复时它们被用来指定恢复时间点

SQL> select count(*) from t_emp;

  COUNT(*)
----------
       107

1 row selected.

SQL>  select sysdate from dual;

SYSDATE
-------------------
2018-01-10 20:10:01

1 row selected.

SQL> select current_scn   from v$database;

CURRENT_SCN
-----------
     447215

1 row selected.

3.启动RMAN并使用有sysbacup或sysdba权限的用户连接到目标数据库。

[oracle@jytest3 ~]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@jytest3 ~]$ rman target/

Recovery Manager: Release 12.2.0.1.0 - Production on Wed Jan 10 02:22:13 2018

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

connected to target database: ORCL (DBID=1492772871)

4.通过使用recover table命令将要被恢复的表或表分区恢复到指定的时间点。 使用auxiliary destination子句(/ora_xtts/recover辅助数据文件存储目录)与until scn来指定恢复时间点,并且在recover命令中使用子句 dump file与datapump destination,指定包含被恢复表或表分区的导出dump文件的文件名(t_emp_recvr.dmp)与存储位置(/ora_xtts/dump)。 使用remap table子句将hr.t_emp恢复成jy.t_emp_new。使用remap tablespace子句将表t_emp从表空间users恢复到usertbs表空间

RMAN> run
2> {
3> recover table hr.t_emp
4> until time '2018-01-10 20:10:01'
5> auxiliary destination '/ora_xtts/recover'
6> datapump destination '/ora_xtts/dump'
7> dump file 't_emp_recvr.dmp'
8> remap table 'HR'.'T_EMP':'JY'.'T_EMP_NEW'
9> remap tablespace 'USERS':'USERTBS';
10> }

Starting recover at 2018-01-10 22:07:43
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=49 device type=DISK
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='BxcB'

initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=BxcB_pitr_ORCL
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=1024M
processes=120
db_create_file_dest=/ora_xtts/recover
log_archive_dest_1='location=/ora_xtts/recover'
#No auxiliary parameter file used


starting up automatic instance ORCL

Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-10 20:10:01";
# restore the controlfile
restore clone controlfile;

# mount the controlfile
sql clone 'alter database mount clone database';

# archive current online log
sql 'alter system archive log current';
}
executing Memory Script

executing command: SET until clause

Starting restore at 2018-01-10 22:09:04
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=6 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 +DATA/backup/c-1492772871-20180110-02
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/c-1492772871-20180110-02 tag=TAG20180110T200959
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
output file name=/ora_xtts/recover/ORCL/controlfile/o1_mf_f5d7n52r_.ctl
Finished restore at 2018-01-10 22:09:10

sql statement: alter database mount clone database

sql statement: alter system archive log current

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-10 20:10:01";
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  3 to new;
set newname for clone datafile  2 to new;
set newname for clone tempfile  1 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 3, 2;

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_%u_.tmp in control file

Starting restore at 2018-01-10 22:09:18
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 /ora_xtts/recover/ORCL/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_26sobn77_1_1_965074151
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_26sobn77_1_1_965074151 tag=TAG20180110T200911
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 2018-01-10 22:10:04

datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=965081404 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_system_f5d7nhmp_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=965081404 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5d7nhq5_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=965081405 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5d7nhot_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-10 20:10:01";
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  3 online";
sql clone "alter database datafile  2 online";
# recover and open database read only
recover clone database tablespace  "SYSTEM", "UNDOTBS1", "SYSAUX";
sql clone 'alter database open read only';
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  1 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  2 online

Starting recover at 2018-01-10 22:10:06
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 24 is already on disk as file +DATA/arch/orcl/1_24_964992135.dbf
archived log for thread 1 with sequence 25 is already on disk as file +DATA/arch/orcl/1_25_964992135.dbf
archived log file name=+DATA/arch/orcl/1_24_964992135.dbf thread=1 sequence=24
archived log file name=+DATA/arch/orcl/1_25_964992135.dbf thread=1 sequence=25
media recovery complete, elapsed time: 00:00:01
Finished recover at 2018-01-10 22:10:09

sql statement: alter database open read only

contents of Memory Script:
{
   sql clone "create spfile from memory";
   shutdown clone immediate;
   startup clone nomount;
   sql clone "alter system set  control_files =
  ''/ora_xtts/recover/ORCL/controlfile/o1_mf_f5d7n52r_.ctl'' comment=
 ''RMAN set'' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
# mount database
sql clone 'alter database mount clone database';
}
executing Memory Script

sql statement: create spfile from memory

database closed
database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes

sql statement: alter system set  control_files =   ''/ora_xtts/recover/ORCL/controlfile/o1_mf_f5d7n52r_.ctl'' comment= ''RMAN set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-10 20:10:01";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile  4 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  4;

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

Starting restore at 2018-01-10 22:11:13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=7 device type=DISK

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 00004 to /ora_xtts/recover/BXCB_PITR_ORCL/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_26sobn77_1_1_965074151
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_26sobn77_1_1_965074151 tag=TAG20180110T200911
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 2018-01-10 22:12:09

datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=965081529 file name=/ora_xtts/recover/BXCB_PITR_ORCL/datafile/o1_mf_users_f5d7r2q4_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-10 20:10:01";
# online the datafiles restored or switched
sql clone "alter database datafile  4 online";
# recover and open resetlogs
recover clone database tablespace  "USERS", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  4 online

Starting recover at 2018-01-10 22:12:10
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 24 is already on disk as file +DATA/arch/orcl/1_24_964992135.dbf
archived log for thread 1 with sequence 25 is already on disk as file +DATA/arch/orcl/1_25_964992135.dbf
archived log file name=+DATA/arch/orcl/1_24_964992135.dbf thread=1 sequence=24
archived log file name=+DATA/arch/orcl/1_25_964992135.dbf thread=1 sequence=25
media recovery complete, elapsed time: 00:00:00
Finished recover at 2018-01-10 22:12:14

database opened

contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/ora_xtts/dump''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/ora_xtts/dump''";
}
executing Memory Script

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/ora_xtts/dump''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/ora_xtts/dump''

Performing export of tables...
   EXPDP> Starting "SYS"."TSPITR_EXP_BxcB_tfoq":
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   EXPDP> . . exported "HR"."T_EMP"                                17.08 KB     107 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_BxcB_tfoq" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_BxcB_tfoq is:
   EXPDP>   /ora_xtts/dump/t_emp_recvr.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_BxcB_tfoq" successfully completed at Wed Jan 10 22:13:08 2018 elapsed 0 00:00:33
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
}
executing Memory Script

Oracle instance shut down

Performing import of tables...
   IMPDP> Master table "SYS"."TSPITR_IMP_BxcB_Enlv" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_BxcB_Enlv":
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "JY"."T_EMP_NEW"                            17.08 KB     107 rows
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   IMPDP> Job "SYS"."TSPITR_IMP_BxcB_Enlv" successfully completed at Wed Jan 10 22:13:48 2018 elapsed 0 00:00:33
Import completed


Removing automatic instance
Automatic instance removed
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_f5d7p27f_.tmp deleted
auxiliary instance file /ora_xtts/recover/BXCB_PITR_ORCL/onlinelog/o1_mf_3_f5d7syo5_.log deleted
auxiliary instance file /ora_xtts/recover/BXCB_PITR_ORCL/onlinelog/o1_mf_2_f5d7syng_.log deleted
auxiliary instance file /ora_xtts/recover/BXCB_PITR_ORCL/onlinelog/o1_mf_1_f5d7symr_.log deleted
auxiliary instance file /ora_xtts/recover/BXCB_PITR_ORCL/datafile/o1_mf_users_f5d7r2q4_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5d7nhot_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5d7nhq5_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_system_f5d7nhmp_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/controlfile/o1_mf_f5d7n52r_.ctl deleted
auxiliary instance file t_emp_recvr.dmp deleted
Finished recover at 2018-01-10 22:13:53

5.验证表hr.t_emp的数据是否成功恢复到表jy.t_emp_new中,从查询记录可以看到已经成功恢复到表jy.t_emp_new中。

SQL> select count(*) from jy.t_emp_new;

  COUNT(*)
----------
       107

Oracle 12c使用RMAN备份将Non-CDB中被drop的表恢复到新用户方案与新表空间中

RMAN使用recover命令来将表或表分区恢复到指定的时间点。为了从RMAN备份中恢复表与表分区,你必须提供以下信息:
.要被恢复的表或表分区
.表或表分区要被恢复到的特定时间点
.被恢复的表或表分区是否要被导入到目标数据库中

RMAN使用这些信息来自动对表或表分区执行恢复操作。作为恢复处理的一部分,RMAN会创建一个辅助数据库用来将表或表分区恢复到指定的时间点。如果被恢复的表或表分区需要被重命名,映射到新表空间或映射到新方案中, 那么必须指定新的表名,表空间名或方案名。

当从RMAN备份中自动处理表或表分区的恢复操作时RMAN将会执行以下步骤:
1.基于指定的恢复时间点来判断包含被恢复表或表分区的是那个备份文件。

2.判断在目标主机上是否有足够的空间用来创建辅助实例来执行对表或表分区的恢复操作,如果没有足够空间,那么RMAN将会显示错误信息并且退出恢复操作。

3.在目标主机上创建一个辅助数据库并且在辅助数据库中将指定的表或表分区恢复到指定的时间点。可以在目标主机上指定存储辅助数据库相关恢复数据文件的目录。

4.创建对恢复的表或表分区使用Data Pump进行导出。可以指定用来存储被恢复表或表分区元数据的dump文件的文件名与存储目录。

5.可选操作,将步骤4导出的表或表分区导入到目标数据库中。可以选择不将包含被恢复表或表分区导出dump文件导入到目标数据库中。如果选择不将导出dump文件导入目标数据库作为恢复操作的一部分,那么之后必须使用 Data Pump导入工具进行导入操作。

6.可选操作,在目标数据库中重命名被恢复的表或表分区。也可以将被恢复的对象导入与它原始表空间或方案不同的表空间或方案中。

RMAN表恢复操作时辅助数据库文件的存储目录
为了恢复指定的表或表分区,RMAN会创建一个辅助数据库在恢复操作时使用。使用以下一种方法来在目标主机上指定用来存储辅助数据库文件的目录:
.在recover命令中指定auxiliary destination子句。
.使用set newname命令。在run块中使用recover命令并且使用set newname命令来重命名数据文件。

建议通过使用auxiliary destination子句来为辅助数据库的数据文件指定存储目录。当使用set newname命令时,即使是只对恢复操作所请求的一个数据文件没有执行set newname命令,那么就不能对表或表分区执行恢复操作 。

RMAN恢复表与表分区操作中所使用的Data Pump导出dump文件
当在辅助数据库中将表或表分区恢复到指定的时间点之后,RMAN会创建包含被恢复对象的Data Pump导出dump文件。可以指定dump文件的文件名与位置或者允许RMAN使用缺省的文件名与位置。

在recover命令中使用datapump destination子句来指定创建Data Pump导出dump文件的存储目录。这个目录通常是操作系统目录路径来存储dump文件。如果忽略这个子句,dump文件会被存储在由auxiliary destination参数 所指定的目录中。如果不指定辅助目录,那么dump文件会被存储在缺省操作系统特定的目录中。在Linux操作系统中,缺省目录为$ORACLE_HOME/dbs。在Windows操作系统中,缺省目录为%ORACLE_HOME\database。

在recover命令中使用dump file子句来指定创建Data Pump导出dump文件的存储目录。如果忽略这个子句,RMAN使用缺省操作系统特定的dump文件名。在Linux与Windows操作系统中,缺省的dump文件名为tspitr_SID-of- clone_n.dmp,SID-of-clone是RMAN在执行恢复操作时所创建的辅助数据库的Oracle SID,其中n是任意随机生成的数字。如果由dump file所指定的文件名在目录中已经存在,那么恢复操作将会失败。

将被恢复的表与表分区导入到目标数据库
缺省情况下,RMAN会将存储在dump文件中的被恢复表或表分区导入到目标数据库中。然而,可以选择在recover命令中使用notableimport子句来避免将被恢复的表或表分区导入到目标数据库中。

当notableimport子句被使用时,RMAN会将表或表分区恢复到指定的时间点,然后创建导出dump文件。然而,这个dump文件不会被导入到目标数据库中。当需要时可以通过手动使用Data Pump导入工具将dump文件导入到目标数 据库。如果在导入操作时出现了错误,RMAN在表恢复操作结束时不会删除导出dump文件。这可以让你手动导入dump文件。

对被恢复的表与表分区进行重命名
当你恢复表或表分区时,可以在它们被导入到目标数据库后进行重命名。remap table子句可以用来对目标数据库中被恢复的表或表分区进行重命名。为了将被恢复的表或表分区导入与原始对象所存储的不同表空间,可以在 recover命令中使用remap tablespace子句。只有被恢复的表或表分区会被重新映射,已有的对象不会发生改变。如果目标数据库中有与被恢复对象同名的对象,RMAN会显示错误信息指示需要使用remap table子句来重命名被 恢复的表。

当恢复表分区时,每个表分区被恢复成一个单独的表。使用remap table子句来指定每个被恢复的分区在导入时所使用的表名。如果没有显式地指定表名,RMAN会通过组合被恢复的表与分区名来生成表名。生成的表名格式为 tablename_partitionname。如果表名在目标数据库中已经存在了,那么RMAN会在表名后加上_1。如果这个表名也存在了,那么就在表名后加上_2依此类推。当使用remap选项时,任何命名约束与索引不会被导入。这可以避免 与现有表发生冲突。

将表与分区恢复到新用户方案中
将表或表分区恢复到不同的用户方案中可以避免与原用户方案中已经存在的约束,索引或触发器名字发生命名冲突。从Oracle 12.2开始,可以将表或表分区恢复到与原用户方案不同的用户方案中。当将对象恢复到不同用户方案 中时,可以保留它们的原始名字或重新命名。在单个恢复操作中可以重命名表与重新映射用户方案。例如,可以将hr.employees表恢复成new_hr.employees表,hr.new_employees表或new_hr.new_employees表。remap table 子句能让你重命名对象并且将它们恢复到不同的用户方案中。在执行表恢复操作时,对recover table命令使用remap table子句来将原用户方案映射成新用户方案。在执行恢复操作之前新用户方案必须先在目标数据库中存在。 表恢复在物理备库中不支持。对于逻辑备库,在主库中执行的对象恢复也会被同步到逻辑备库。

使用RMAN备份来恢复表与表分区的限制
当使用recover命令与RMAN备份来恢复表或表分区时存在以下限制:
.sys用户方案中的表与表分区不能被恢复。
.system与sysaux表空间中的表与表分区不能被恢复。
.备库中的表与表分区不能被恢复。
.有not null约束的表在使用remap选项时不能被恢复。

恢复表与表分区所需要的准备工作
使用RMAN备份来恢复表或表分区所需要的准备工作如下:
.验证恢复表或表分区所需要的条件是否满足。
.判断表或表分区需要被恢复到的时间点。
.决定是否要将被恢复的表或表分区导入到目标数据库中。缺省情况下,RMAN会将被恢复的表或表分区导入到目标数据库中。然而可以指定RMAN不志入被恢复的对象。
.决定是否要对被恢复的表或表分区进行重命名,映射到新表空间或映射到新用户方案。

使用RMAN备份恢复表与表分区的先决条件
.目标数据库必须处于读写状态。
.目标数据库必须处于归档模式。
.对于这些对象所恢复的时间点来说被恢复的表或表分区必须有RMAN备份。
.为了恢复单个表分区,目标数据库的compatible参数必须被设置为11.1.0或更高版本。

判断表与表分区所要被恢复到的时间点
判断表或表分区所要被恢复到的时间点是非常重要的。RMAN可以使用以下一种方法来指定恢复时间点:
.SCN,将表或表分区恢复到由SCN所指定的时间点。
.Time(时间),将表或表分区恢复到指定的时间点。所使用的日期格式是由NLS_LANG与NLS_DATE_FORMAT环境变量所组成的。也可以使用数据常量比如SYSDATE来指定时间,例如SYSDATE-30。
.Sequence number(日志序列号),将表或表分区恢复到由日志序列号与日志线程号所指定的时间点。

恢复表与表分区
下面将描述对Non-CDB中的表或表分区恢复到指定时间点的操作步骤。
1.执行恢复表与表分区所需要的准备工作
.验证恢复表或表分区所需要的条件是否满足。
.判断表或表分区需要被恢复到的时间点。
.决定是否要将被恢复的表或表分区导入到目标数据库中。缺省情况下,RMAN会将被恢复的表或表分区导入到目标数据库中。然而可以指定RMAN不志入被恢复的对象。
.决定是否要对被恢复的表或表分区进行重命名,映射到新表空间或映射到新用户方案。

2.启动RMAN并使用有sysbacup或sysdba权限的用户连接到目标数据库。

3.通过使用recover table命令将要被恢复的表或表分区恢复到指定的时间点。必须使用auxiliary destination子句与以下子句中的一个用来指定恢复时间点:until time,until scn或until sequence。在recover命令中还 可以使用以下子句:
.dump file与datapump destination,指定包含被恢复表或表分区的导出dump文件的文件名与存储位置。

.notableimport,指示被恢复的表或表分区不用导入到目标数据库。

.remap table,在目标数据库中将被恢复的表或表分区进行重命名。这个子句也可用来将原用户方案中的表或表分区恢复到新用户方案中。

.remap tablespace,将表与表分区恢复到与原始表空间不同的表空间中。

使用RMAN备份将被drop的表恢复到新用户方案与新表空间中
1.对整个Non-CDB(orcl)生成RMAN备份

RMAN> backup as compressed backupset database format '+data/backup/%d_%I_%U_%t' plus archivelog format 'arc_%d_%T_%U';

Starting backup at 10-JAN-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=13 RECID=1 STAMP=964995986
input archived log thread=1 sequence=14 RECID=2 STAMP=965007422
input archived log thread=1 sequence=15 RECID=3 STAMP=965007493
input archived log thread=1 sequence=16 RECID=4 STAMP=965007542
input archived log thread=1 sequence=17 RECID=5 STAMP=965011311
input archived log thread=1 sequence=18 RECID=6 STAMP=965011687
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/product/12.2.0/db/dbs/arc_ORCL_20180110_21so9q78_1_1 tag=TAG20180110T024807 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 10-JAN-18

Starting backup at 10-JAN-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA/orcl/datafile/users01.dbf
input datafile file number=00001 name=+DATA/orcl/datafile/system01.dbf
input datafile file number=00002 name=+DATA/orcl/datafile/sysaux01.dbf
input datafile file number=00003 name=+DATA/orcl/datafile/undotbs01.dbf
input datafile file number=00005 name=+DATA/orcl/datafile/usertbs01.dbf
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=+DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 tag=TAG20180110T024824 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 10-JAN-18

Starting backup at 10-JAN-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=19 RECID=7 STAMP=965011751
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/product/12.2.0/db/dbs/arc_ORCL_20180110_23so9q98_1_1 tag=TAG20180110T024912 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-18

Starting Control File and SPFILE Autobackup at 10-JAN-18
piece handle=+DATA/backup/c-1492772871-20180110-01 comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-18

2.在删除表t_emp之前记录当前scn与时间,在执行恢复时它们被用来指定恢复时间点

SQL> select count(*) from t_emp;

  COUNT(*)
----------
       107

1 row selected.

SQL> select sysdate from dual;

SYSDATE
-------------------
2018-01-10 02:50:10

1 row selected.

SQL> select current_scn   from v$database;

CURRENT_SCN
-----------
     399411

1 row selected.

SQL> drop table t_emp;

Table dropped.

SQL> select count(*) from t_emp;

  COUNT(*)
----------
         0

1 row selected.

3.启动RMAN并使用有sysbacup或sysdba权限的用户连接到目标数据库。

[oracle@jytest3 ~]$ rman target/

Recovery Manager: Release 12.2.0.1.0 - Production on Wed Jan 10 02:22:13 2018

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

connected to target database: ORCL (DBID=1492772871)

4.通过使用recover table命令将要被恢复的表或表分区恢复到指定的时间点。 使用auxiliary destination子句(/ora_xtts/recover辅助数据文件存储目录)与until scn来指定恢复时间点,并且在recover命令中使用子句 dump file与datapump destination,指定包含被恢复表或表分区的导出dump文件的文件名(t_emp.dmp)与存储位置(/ora_xtts/dump)。 使用remap table子句将hr.t_emp恢复成jy.t_emp_recvr。使用remap tablespace子句将表t_emp从users表空间恢复到usertbs表空间

RMAN> run
2> {
3> recover table hr.t_emp
4> until scn 399411
5> auxiliary destination '/ora_xtts/recover'
6> datapump destination '/ora_xtts/dump'
7> dump file 't_emp.dmp'
8> remap table 'hr'.'t_emp':'t_emp_recvr'
9> remap tablespace 'USERS':'USERTBS';
10> }

Starting recover at 10-JAN-18
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/10/2018 19:46:50
RMAN-05063: Cannot recover specified tables
RMAN-05075: Remapped object "hr"."t_emp" is not being recovered

错误信息说hr.t_emp表不能被恢复,其实是表名要使用大写

RMAN> run
2> {
3> recover table hr.t_emp
4> until scn 399411
5> auxiliary destination '/ora_xtts/recover'
6> datapump destination '/ora_xtts/dump'
7> dump file 't_emp_recvr.dmp'
8> remap table 'HR'.'T_EMP':'JY'.'T_EMP_RECVR'
9> remap tablespace 'USERS':'USERTBS';
10> }

Starting recover at 10-JAN-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=118 device type=DISK
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='goBv'

initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=goBv_pitr_ORCL
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=1024M
processes=120
db_create_file_dest=/ora_xtts/recover
log_archive_dest_1='location=/ora_xtts/recover'
#No auxiliary parameter file used


starting up automatic instance ORCL

Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# restore the controlfile
restore clone controlfile;

# mount the controlfile
sql clone 'alter database mount clone database';

# archive current online log
sql 'alter system archive log current';
}
executing Memory Script

executing command: SET until clause

Starting restore at 10-JAN-18
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=6 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 +DATA/backup/c-1492772871-20180110-01
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/c-1492772871-20180110-01 tag=TAG20180110T024913
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:05
output file name=/ora_xtts/recover/ORCL/controlfile/o1_mf_f5czvqq3_.ctl
Finished restore at 10-JAN-18

sql statement: alter database mount clone database

sql statement: alter system archive log current

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  3 to new;
set newname for clone datafile  2 to new;
set newname for clone tempfile  1 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 3, 2;

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_%u_.tmp in control file

Starting restore at 10-JAN-18
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 /ora_xtts/recover/ORCL/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 tag=TAG20180110T024824
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 10-JAN-18

datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=965073457 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_system_f5czw3w1_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=965073457 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5czw3x5_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=965073457 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5czw3wm_.dbf

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  3 online";
sql clone "alter database datafile  2 online";
# recover and open database read only
recover clone database tablespace  "SYSTEM", "UNDOTBS1", "SYSAUX";
sql clone 'alter database open read only';
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  1 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  2 online

Starting recover at 10-JAN-18
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 19 is already on disk as file +DATA/arch/orcl/1_19_964992135.dbf
archived log for thread 1 with sequence 20 is already on disk as file +DATA/arch/orcl/1_20_964992135.dbf
archived log file name=+DATA/arch/orcl/1_19_964992135.dbf thread=1 sequence=19
archived log file name=+DATA/arch/orcl/1_20_964992135.dbf thread=1 sequence=20
media recovery complete, elapsed time: 00:00:01
Finished recover at 10-JAN-18

sql statement: alter database open read only

contents of Memory Script:
{
   sql clone "create spfile from memory";
   shutdown clone immediate;
   startup clone nomount;
   sql clone "alter system set  control_files =
  ''/ora_xtts/recover/ORCL/controlfile/o1_mf_f5czvqq3_.ctl'' comment=
 ''RMAN set'' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
# mount database
sql clone 'alter database mount clone database';
}
executing Memory Script

sql statement: create spfile from memory

database closed
database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes

sql statement: alter system set  control_files =   ''/ora_xtts/recover/ORCL/controlfile/o1_mf_f5czvqq3_.ctl'' comment= ''RMAN set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile  4 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  4;

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

Starting restore at 10-JAN-18
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=7 device type=DISK

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 00004 to /ora_xtts/recover/GOBV_PITR_ORCL/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 tag=TAG20180110T024824
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:56
Finished restore at 10-JAN-18

datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=965073585 file name=/ora_xtts/recover/GOBV_PITR_ORCL/datafile/o1_mf_users_f5czzt3r_.dbf

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# online the datafiles restored or switched
sql clone "alter database datafile  4 online";
# recover and open resetlogs
recover clone database tablespace  "USERS", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  4 online

Starting recover at 10-JAN-18
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 19 is already on disk as file +DATA/arch/orcl/1_19_964992135.dbf
archived log for thread 1 with sequence 20 is already on disk as file +DATA/arch/orcl/1_20_964992135.dbf
archived log file name=+DATA/arch/orcl/1_19_964992135.dbf thread=1 sequence=19
archived log file name=+DATA/arch/orcl/1_20_964992135.dbf thread=1 sequence=20
media recovery complete, elapsed time: 00:00:00
Finished recover at 10-JAN-18

database opened

contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/ora_xtts/dump''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/ora_xtts/dump''";
}
executing Memory Script

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/ora_xtts/dump''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/ora_xtts/dump''

Performing export of tables...
   EXPDP> Starting "SYS"."TSPITR_EXP_goBv_vFCd":
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   EXPDP> . . exported "HR"."T_EMP"                                17.08 KB     107 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_goBv_vFCd" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_goBv_vFCd is:
   EXPDP>   /ora_xtts/dump/t_emp_recvr.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_goBv_vFCd" successfully completed at Wed Jan 10 20:00:44 2018 elapsed 0 00:00:33
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
}
executing Memory Script

Oracle instance shut down

Performing import of tables...
   IMPDP> Master table "SYS"."TSPITR_IMP_goBv_apfb" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_goBv_apfb":
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "JY"."T_EMP_RECVR"                          17.08 KB     107 rows
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   IMPDP> Job "SYS"."TSPITR_IMP_goBv_apfb" successfully completed at Wed Jan 10 20:01:32 2018 elapsed 0 00:00:40
Import completed


Removing automatic instance
Automatic instance removed
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_f5czxpvw_.tmp deleted
auxiliary instance file /ora_xtts/recover/GOBV_PITR_ORCL/onlinelog/o1_mf_3_f5d01ojq_.log deleted
auxiliary instance file /ora_xtts/recover/GOBV_PITR_ORCL/onlinelog/o1_mf_2_f5d01oj5_.log deleted
auxiliary instance file /ora_xtts/recover/GOBV_PITR_ORCL/onlinelog/o1_mf_1_f5d01ohd_.log deleted
auxiliary instance file /ora_xtts/recover/GOBV_PITR_ORCL/datafile/o1_mf_users_f5czzt3r_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5czw3wm_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5czw3x5_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_system_f5czw3w1_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/controlfile/o1_mf_f5czvqq3_.ctl deleted
auxiliary instance file t_emp_recvr.dmp deleted
Finished recover at 10-JAN-18

5.验证表hr.t_emp的数据是否成功恢复到表jy.t_emp_recvr中,从查询记录可以看到已经成功恢复到表jy.t_emp_recvr中。

SQL> select count(*) from jy.t_emp_recvr;

  COUNT(*)
----------
       107

Oracle 12c使用RMAN备份对Non-CDB中的表按时间点进行恢复

RMAN使用recover命令来将表或表分区恢复到指定的时间点。为了从RMAN备份中恢复表与表分区,你必须提供以下信息:
.要被恢复的表或表分区
.表或表分区要被恢复到的特定时间点
.被恢复的表或表分区是否要被导入到目标数据库中

RMAN使用这些信息来自动对表或表分区执行恢复操作。作为恢复处理的一部分,RMAN会创建一个辅助数据库用来将表或表分区恢复到指定的时间点。如果被恢复的表或表分区需要被重命名,映射到新表空间或映射到新方案中,那么必须指定新的表名,表空间名或方案名。

当从RMAN备份中自动处理表或表分区的恢复操作时RMAN将会执行以下步骤:
1.基于指定的恢复时间点来判断包含被恢复表或表分区的是那个备份文件。

2.判断在目标主机上是否有足够的空间用来创建辅助实例来执行对表或表分区的恢复操作,如果没有足够空间,那么RMAN将会显示错误信息并且退出恢复操作。

3.在目标主机上创建一个辅助数据库并且在辅助数据库中将指定的表或表分区恢复到指定的时间点。可以在目标主机上指定存储辅助数据库相关恢复数据文件的目录。

4.创建对恢复的表或表分区使用Data Pump进行导出。可以指定用来存储被恢复表或表分区元数据的dump文件的文件名与存储目录。

5.可选操作,将步骤4导出的表或表分区导入到目标数据库中。可以选择不将包含被恢复表或表分区导出dump文件导入到目标数据库中。如果选择不将导出dump文件导入目标数据库作为恢复操作的一部分,那么之后必须使用Data Pump导入工具进行导入操作。

6.可选操作,在目标数据库中重命名被恢复的表或表分区。也可以将被恢复的对象导入与它原始表空间或方案不同的表空间或方案中。

RMAN表恢复操作时辅助数据库文件的存储目录
为了恢复指定的表或表分区,RMAN会创建一个辅助数据库在恢复操作时使用。使用以下一种方法来在目标主机上指定用来存储辅助数据库文件的目录:
.在recover命令中指定auxiliary destination子句。
.使用set newname命令。在run块中使用recover命令并且使用set newname命令来重命名数据文件。

建议通过使用auxiliary destination子句来为辅助数据库的数据文件指定存储目录。当使用set newname命令时,即使是只对恢复操作所请求的一个数据文件没有执行set newname命令,那么就不能对表或表分区执行恢复操作。

RMAN恢复表与表分区操作中所使用的Data Pump导出dump文件
当在辅助数据库中将表或表分区恢复到指定的时间点之后,RMAN会创建包含被恢复对象的Data Pump导出dump文件。可以指定dump文件的文件名与位置或者允许RMAN使用缺省的文件名与位置。在recover命令中使用datapump destination子句来指定创建Data Pump导出dump文件的存储目录。这个目录通常是操作系统目录路径来存储dump文件。如果忽略这个子句,dump文件会被存储在由auxiliary destination参数所指定的目录中。如果不指定辅助目录,那么dump文件会被存储在缺省操作系统特定的目录中。在Linux操作系统中,缺省目录为$ORACLE_HOME/dbs。在Windows操作系统中,缺省目录为%ORACLE_HOME\database。在recover命令中使用dump file子句来指定创建Data Pump导出dump文件的存储目录。如果忽略这个子句,RMAN使用缺省操作系统特定的dump文件名。在Linux与Windows操作系统中,缺省的dump文件名为tspitr_SID-of-clone_n.dmp,SID-of-clone是RMAN在执行恢复操作时所创建的辅助数据库的Oracle SID,其中n是任意随机生成的数字。如果由dump file所指定的文件名在目录中已经存在,那么恢复操作将会失败。

将被恢复的表与表分区导入到目标数据库
缺省情况下,RMAN会将存储在dump文件中的被恢复表或表分区导入到目标数据库中。然而,可以选择在recover命令中使用notableimport子句来避免将被恢复的表或表分区导入到目标数据库中。当notableimport子句被使用时,RMAN会将表或表分区恢复到指定的时间点,然后创建导出dump文件。然而,这个dump文件不会被导入到目标数据库中。当需要时可以通过手动使用Data Pump导入工具将dump文件导入到目标数据库。如果在导入操作时出现了错误,RMAN在表恢复操作结束时不会删除导出dump文件。这可以让你手动导入dump文件。

对被恢复的表与表分区进行重命名
当你恢复表或表分区时,可以在它们被导入到目标数据库后进行重命名。remap table子句可以用来对目标数据库中被恢复的表或表分区进行重命名。为了将被恢复的表或表分区导入与原始对象所存储的不同表空间,可以在recover命令中使用remap tablespace子句。只有被恢复的表或表分区会被重新映射,已有的对象不会发生改变。如果目标数据库中有与被恢复对象同名的对象,RMAN会显示错误信息指示需要使用remap table子句来重命名被恢复的表。当恢复表分区时,每个表分区被恢复成一个单独的表。使用remap table子句来指定每个被恢复的分区在导入时所使用的表名。如果没有显式地指定表名,RMAN会通过组合被恢复的表与分区名来生成表名。生成的表名格式为tablename_partitionname。如果表名在目标数据库中已经存在了,那么RMAN会在表名后加上_1。如果这个表名也存在了,那么就在表名后加上_2依此类推。当使用remap选项时,任何命名约束与索引不会被导入。这可以避免与现有表发生冲突。

将表与分区恢复到新用户方案中
将表或表分区恢复到不同的用户方案中可以避免与原用户方案中已经存在的约束,索引或触发器名字发生命名冲突。从Oracle 12.2开始,可以将表或表分区恢复到与原用户方案不同的用户方案中。当将对象恢复到不同用户方案中时,可以保留它们的原始名字或重新命名。在单个恢复操作中可以重命名表与重新映射用户方案。例如,可以将hr.employees表恢复成new_hr.employees表,hr.new_employees表或new_hr.new_employees表。remap table子句能让你重命名对象并且将它们恢复到不同的用户方案中。在执行表恢复操作时,对recover table命令使用remap table子句来将原用户方案映射成新用户方案。在执行恢复操作之前新用户方案必须先在目标数据库中存在。表恢复在物理备库中不支持。对于逻辑备库,在主库中执行的对象恢复也会被同步到逻辑备库。

使用RMAN备份来恢复表与表分区的限制
当使用recover命令与RMAN备份来恢复表或表分区时存在以下限制:
.sys用户方案中的表与表分区不能被恢复。
.system与sysaux表空间中的表与表分区不能被恢复。
.备库中的表与表分区不能被恢复。
.有not null约束的表在使用remap选项时不能被恢复。

恢复表与表分区所需要的准备工作
使用RMAN备份来恢复表或表分区所需要的准备工作如下:
.验证恢复表或表分区所需要的条件是否满足。
.判断表或表分区需要被恢复到的时间点。
.决定是否要将被恢复的表或表分区导入到目标数据库中。缺省情况下,RMAN会将被恢复的表或表分区导入到目标数据库中。然而可以指定RMAN不志入被恢复的对象。
.决定是否要对被恢复的表或表分区进行重命名,映射到新表空间或映射到新用户方案。

使用RMAN备份恢复表与表分区的先决条件
.目标数据库必须处于读写状态。
.目标数据库必须处于归档模式。
.对于这些对象所恢复的时间点来说被恢复的表或表分区必须有RMAN备份。
.为了恢复单个表分区,目标数据库的compatible参数必须被设置为11.1.0或更高版本。

判断表与表分区所要被恢复到的时间点
判断表或表分区所要被恢复到的时间点是非常重要的。RMAN可以使用以下一种方法来指定恢复时间点:
.SCN,将表或表分区恢复到由SCN所指定的时间点。
.Time(时间),将表或表分区恢复到指定的时间点。所使用的日期格式是由NLS_LANG与NLS_DATE_FORMAT环境变量所组成的。也可以使用数据常量比如SYSDATE来指定时间,例如SYSDATE-30。
.Sequence number(日志序列号),将表或表分区恢复到由日志序列号与日志线程号所指定的时间点。

恢复表与表分区
下面将描述对Non-CDB中的表或表分区恢复到指定时间点的操作步骤。
1.执行恢复表与表分区所需要的准备工作
.验证恢复表或表分区所需要的条件是否满足。
.判断表或表分区需要被恢复到的时间点。
.决定是否要将被恢复的表或表分区导入到目标数据库中。缺省情况下,RMAN会将被恢复的表或表分区导入到目标数据库中。然而可以指定RMAN不志入被恢复的对象。
.决定是否要对被恢复的表或表分区进行重命名,映射到新表空间或映射到新用户方案。

2.启动RMAN并使用有sysbacup或sysdba权限的用户连接到目标数据库。

3.通过使用recover table命令将要被恢复的表或表分区恢复到指定的时间点。必须使用auxiliary destination子句与以下子句中的一个用来指定恢复时间点:until time,until scn或until sequence。在recover命令中还

可以使用以下子句:
.dump file与datapump destination,指定包含被恢复表或表分区的导出dump文件的文件名与存储位置。

.notableimport,指示被恢复的表或表分区不用导入到目标数据库。

.remap table,在目标数据库中将被恢复的表或表分区进行重命名。这个子句也可用来将原用户方案中的表或表分区恢复到新用户方案中。

.remap tablespace,将表与表分区恢复到与原始表空间不同的表空间中。

下面的例子使用RMAN备份对表t_emp进行按时间点恢复
1.对整个Non-CDB(orcl)生成RMAN备份

RMAN> backup as compressed backupset database format '+data/backup/%d_%I_%U_%t' plus archivelog format 'arc_%d_%T_%U';

Starting backup at 10-JAN-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=13 RECID=1 STAMP=964995986
input archived log thread=1 sequence=14 RECID=2 STAMP=965007422
input archived log thread=1 sequence=15 RECID=3 STAMP=965007493
input archived log thread=1 sequence=16 RECID=4 STAMP=965007542
input archived log thread=1 sequence=17 RECID=5 STAMP=965011311
input archived log thread=1 sequence=18 RECID=6 STAMP=965011687
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/product/12.2.0/db/dbs/arc_ORCL_20180110_21so9q78_1_1 tag=TAG20180110T024807 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 10-JAN-18

Starting backup at 10-JAN-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA/orcl/datafile/users01.dbf
input datafile file number=00001 name=+DATA/orcl/datafile/system01.dbf
input datafile file number=00002 name=+DATA/orcl/datafile/sysaux01.dbf
input datafile file number=00003 name=+DATA/orcl/datafile/undotbs01.dbf
input datafile file number=00005 name=+DATA/orcl/datafile/usertbs01.dbf
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=+DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 tag=TAG20180110T024824 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 10-JAN-18

Starting backup at 10-JAN-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=19 RECID=7 STAMP=965011751
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/product/12.2.0/db/dbs/arc_ORCL_20180110_23so9q98_1_1 tag=TAG20180110T024912 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-18

Starting Control File and SPFILE Autobackup at 10-JAN-18
piece handle=+DATA/backup/c-1492772871-20180110-01 comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-18

2.在删除表t_emp中记录之前记录当前scn与时间,在执行恢复时它们被用来指定恢复时间点

SQL> select count(*) from t_emp;

  COUNT(*)
----------
       107

1 row selected.

SQL> select sysdate from dual;

SYSDATE
-------------------
2018-01-10 02:50:10

1 row selected.

SQL> select current_scn   from v$database;

CURRENT_SCN
-----------
     399411

1 row selected.

SQL> delete from t_emp;

107 rows deleted.

SQL> commit;

Commit complete.

SQL> select count(*) from t_emp;

  COUNT(*)
----------
         0

1 row selected.

3.启动RMAN并使用有sysbacup或sysdba权限的用户连接到目标数据库。

[oracle@jytest3 ~]$ rman target/

Recovery Manager: Release 12.2.0.1.0 - Production on Wed Jan 10 02:22:13 2018

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

connected to target database: ORCL (DBID=1492772871)

4.通过使用recover table命令将要被恢复的表或表分区恢复到指定的时间点。 使用auxiliary destination子句(/ora_xtts/recover辅助数据文件存储目录)与until scn来指定恢复时间点,并且在recover命令中使用子句dump file与datapump destination,指定包含被恢复表或表分区的导出dump文件的文件名(t_emp.dmp)与存储位置(/ora_xtts/dump)。使用notableimport子句指示被恢复的表或表分区不用导入到目标数据库。

RMAN> run
2> {
3> recover table hr.t_emp
4> until scn 399411
5> auxiliary destination '/ora_xtts/recover'
6> datapump destination '/ora_xtts/dump'
7> dump file 't_emp.dmp'
8> notableimport;
9> }

Starting recover at 10-JAN-18
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='fcsj'

initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=fcsj_pitr_ORCL
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=1024M
processes=120
db_create_file_dest=/ora_xtts/recover
log_archive_dest_1='location=/ora_xtts/recover'
#No auxiliary parameter file used


starting up automatic instance ORCL

Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# restore the controlfile
restore clone controlfile;
 
# mount the controlfile
sql clone 'alter database mount clone database';
 
# archive current online log 
sql 'alter system archive log current';
}
executing Memory Script

executing command: SET until clause

Starting restore at 10-JAN-18
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=6 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 +DATA/backup/c-1492772871-20180110-01
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/c-1492772871-20180110-01 tag=TAG20180110T024913
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:05
output file name=/ora_xtts/recover/ORCL/controlfile/o1_mf_f5b4xmpo_.ctl
Finished restore at 10-JAN-18

sql statement: alter database mount clone database

sql statement: alter system archive log current

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  3 to new;
set newname for clone datafile  2 to new;
set newname for clone tempfile  1 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 3, 2;
 
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_%u_.tmp in control file

Starting restore at 10-JAN-18
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 /ora_xtts/recover/ORCL/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 tag=TAG20180110T024824
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 10-JAN-18

datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=965013098 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_system_f5b4xwvo_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=965013098 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5b4xwx2_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=965013098 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5b4xwwj_.dbf

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  3 online";
sql clone "alter database datafile  2 online";
# recover and open database read only
recover clone database tablespace  "SYSTEM", "UNDOTBS1", "SYSAUX";
sql clone 'alter database open read only';
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  1 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  2 online

Starting recover at 10-JAN-18
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 19 is already on disk as file +DATA/arch/orcl/1_19_964992135.dbf
archived log for thread 1 with sequence 20 is already on disk as file +DATA/arch/orcl/1_20_964992135.dbf
archived log file name=+DATA/arch/orcl/1_19_964992135.dbf thread=1 sequence=19
archived log file name=+DATA/arch/orcl/1_20_964992135.dbf thread=1 sequence=20
media recovery complete, elapsed time: 00:00:00
Finished recover at 10-JAN-18

sql statement: alter database open read only

contents of Memory Script:
{
   sql clone "create spfile from memory";
   shutdown clone immediate;
   startup clone nomount;
   sql clone "alter system set  control_files = 
  ''/ora_xtts/recover/ORCL/controlfile/o1_mf_f5b4xmpo_.ctl'' comment=
 ''RMAN set'' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
# mount database
sql clone 'alter database mount clone database';
}
executing Memory Script

sql statement: create spfile from memory

database closed
database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes

sql statement: alter system set  control_files =   ''/ora_xtts/recover/ORCL/controlfile/o1_mf_f5b4xmpo_.ctl'' comment= ''RMAN set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile  4 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  4;
 
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

Starting restore at 10-JAN-18
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=7 device type=DISK

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 00004 to /ora_xtts/recover/FCSJ_PITR_ORCL/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 tag=TAG20180110T024824
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 10-JAN-18

datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=965013242 file name=/ora_xtts/recover/FCSJ_PITR_ORCL/datafile/o1_mf_users_f5b51h8p_.dbf

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# online the datafiles restored or switched
sql clone "alter database datafile  4 online";
# recover and open resetlogs
recover clone database tablespace  "USERS", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  4 online

Starting recover at 10-JAN-18
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 19 is already on disk as file +DATA/arch/orcl/1_19_964992135.dbf
archived log for thread 1 with sequence 20 is already on disk as file +DATA/arch/orcl/1_20_964992135.dbf
archived log file name=+DATA/arch/orcl/1_19_964992135.dbf thread=1 sequence=19
archived log file name=+DATA/arch/orcl/1_20_964992135.dbf thread=1 sequence=20
media recovery complete, elapsed time: 00:00:01
Finished recover at 10-JAN-18

database opened

contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/ora_xtts/dump''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/ora_xtts/dump''";
}
executing Memory Script

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/ora_xtts/dump''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/ora_xtts/dump''

Performing export of tables...
   EXPDP> Starting "SYS"."TSPITR_EXP_fcsj_pkfh":  
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   EXPDP> Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   EXPDP> Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
   EXPDP> . . exported "HR"."T_EMP"                                17.08 KB     107 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_fcsj_pkfh" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_fcsj_pkfh is:
   EXPDP>   /ora_xtts/dump/t_emp.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_fcsj_pkfh" successfully completed at Wed Jan 10 03:15:08 2018 elapsed 0 00:00:32
Export completed

Not performing table import after point-in-time recovery

Removing automatic instance
shutting down automatic instance 
Oracle instance shut down
Automatic instance removed
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_f5b4zhf9_.tmp deleted
auxiliary instance file /ora_xtts/recover/FCSJ_PITR_ORCL/onlinelog/o1_mf_3_f5b53yp4_.log deleted
auxiliary instance file /ora_xtts/recover/FCSJ_PITR_ORCL/onlinelog/o1_mf_2_f5b53yol_.log deleted
auxiliary instance file /ora_xtts/recover/FCSJ_PITR_ORCL/onlinelog/o1_mf_1_f5b53ynw_.log deleted
auxiliary instance file /ora_xtts/recover/FCSJ_PITR_ORCL/datafile/o1_mf_users_f5b51h8p_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5b4xwwj_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5b4xwx2_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_system_f5b4xwvo_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/controlfile/o1_mf_f5b4xmpo_.ctl deleted
Finished recover at 10-JAN-18

如果会使用remap table子句将hr.t_emp恢复成jy.t_emp_recvr。使用remap tablespace子句将表t_emp从users表空间恢复到usertbs表空间。那么可以执行下面的命令来进行恢复就不需要执行步骤5

RMAN> run
2> {
3> recover table hr.t_emp
4> until scn 399411
5> auxiliary destination '/ora_xtts/recover'
6> datapump destination '/ora_xtts/dump'
7> dump file 't_emp_recvr.dmp'
8> remap table 'HR'.'T_EMP':'JY'.'T_EMP_NEW'
9> remap tablespace 'USERS':'USERTBS';
10> }

Starting recover at 10-JAN-18
current log archived
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='jzdF'

initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=jzdF_pitr_ORCL
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=1024M
processes=120
db_create_file_dest=/ora_xtts/recover
log_archive_dest_1='location=/ora_xtts/recover'
#No auxiliary parameter file used


starting up automatic instance ORCL

Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# restore the controlfile
restore clone controlfile;
 
# mount the controlfile
sql clone 'alter database mount clone database';
 
# archive current online log 
sql 'alter system archive log current';
}
executing Memory Script

executing command: SET until clause

Starting restore at 10-JAN-18
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=6 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 +DATA/backup/c-1492772871-20180110-02
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/c-1492772871-20180110-02 tag=TAG20180110T200959
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
output file name=/ora_xtts/recover/ORCL/controlfile/o1_mf_f5d2402v_.ctl
Finished restore at 10-JAN-18

sql statement: alter database mount clone database

sql statement: alter system archive log current

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  3 to new;
set newname for clone datafile  2 to new;
set newname for clone tempfile  1 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 3, 2;
 
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_%u_.tmp in control file

Starting restore at 10-JAN-18
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 /ora_xtts/recover/ORCL/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_26sobn77_1_1_965074151
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_26sobn77_1_1_965074151 tag=TAG20180110T200911
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 10-JAN-18

datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=965075765 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_system_f5d248q8_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=965075766 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5d248r7_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=965075766 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5d248qv_.dbf

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  3 online";
sql clone "alter database datafile  2 online";
# recover and open database read only
recover clone database tablespace  "SYSTEM", "UNDOTBS1", "SYSAUX";
sql clone 'alter database open read only';
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  1 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  2 online

Starting recover at 10-JAN-18
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 24 is already on disk as file +DATA/arch/orcl/1_24_964992135.dbf
archived log for thread 1 with sequence 25 is already on disk as file +DATA/arch/orcl/1_25_964992135.dbf
archived log file name=+DATA/arch/orcl/1_24_964992135.dbf thread=1 sequence=24
archived log file name=+DATA/arch/orcl/1_25_964992135.dbf thread=1 sequence=25
media recovery complete, elapsed time: 00:00:01
Finished recover at 10-JAN-18

sql statement: alter database open read only

contents of Memory Script:
{
   sql clone "create spfile from memory";
   shutdown clone immediate;
   startup clone nomount;
   sql clone "alter system set  control_files = 
  ''/ora_xtts/recover/ORCL/controlfile/o1_mf_f5d2402v_.ctl'' comment=
 ''RMAN set'' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
# mount database
sql clone 'alter database mount clone database';
}
executing Memory Script

sql statement: create spfile from memory

database closed
database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes

sql statement: alter system set  control_files =   ''/ora_xtts/recover/ORCL/controlfile/o1_mf_f5d2402v_.ctl'' comment= ''RMAN set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile  4 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  4;
 
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

Starting restore at 10-JAN-18
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=7 device type=DISK

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 00004 to /ora_xtts/recover/JZDF_PITR_ORCL/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_26sobn77_1_1_965074151
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_26sobn77_1_1_965074151 tag=TAG20180110T200911
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 10-JAN-18

datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=965075892 file name=/ora_xtts/recover/JZDF_PITR_ORCL/datafile/o1_mf_users_f5d27wvd_.dbf

contents of Memory Script:
{
# set requested point in time
set until  scn 399411;
# online the datafiles restored or switched
sql clone "alter database datafile  4 online";
# recover and open resetlogs
recover clone database tablespace  "USERS", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  4 online

Starting recover at 10-JAN-18
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 24 is already on disk as file +DATA/arch/orcl/1_24_964992135.dbf
archived log for thread 1 with sequence 25 is already on disk as file +DATA/arch/orcl/1_25_964992135.dbf
archived log file name=+DATA/arch/orcl/1_24_964992135.dbf thread=1 sequence=24
archived log file name=+DATA/arch/orcl/1_25_964992135.dbf thread=1 sequence=25
media recovery complete, elapsed time: 00:00:00
Finished recover at 10-JAN-18

database opened

contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/ora_xtts/dump''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/ora_xtts/dump''";
}
executing Memory Script

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/ora_xtts/dump''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/ora_xtts/dump''

Performing export of tables...
   EXPDP> Starting "SYS"."TSPITR_EXP_jzdF_fxiC":  
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   EXPDP> . . exported "HR"."T_EMP"                                17.08 KB     107 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_jzdF_fxiC" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_jzdF_fxiC is:
   EXPDP>   /ora_xtts/dump/t_emp_recvr.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_jzdF_fxiC" successfully completed at Wed Jan 10 20:39:09 2018 elapsed 0 00:00:32
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
}
executing Memory Script

Oracle instance shut down

Performing import of tables...
   IMPDP> Master table "SYS"."TSPITR_IMP_jzdF_BDce" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_jzdF_BDce":  
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "JY"."T_EMP_NEW"                            17.08 KB     107 rows
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   IMPDP> Job "SYS"."TSPITR_IMP_jzdF_BDce" successfully completed at Wed Jan 10 20:39:47 2018 elapsed 0 00:00:31
Import completed


Removing automatic instance
Automatic instance removed
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_f5d25tp8_.tmp deleted
auxiliary instance file /ora_xtts/recover/JZDF_PITR_ORCL/onlinelog/o1_mf_3_f5d29sj0_.log deleted
auxiliary instance file /ora_xtts/recover/JZDF_PITR_ORCL/onlinelog/o1_mf_2_f5d29shf_.log deleted
auxiliary instance file /ora_xtts/recover/JZDF_PITR_ORCL/onlinelog/o1_mf_1_f5d29sgs_.log deleted
auxiliary instance file /ora_xtts/recover/JZDF_PITR_ORCL/datafile/o1_mf_users_f5d27wvd_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5d248qv_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5d248r7_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_system_f5d248q8_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/controlfile/o1_mf_f5d2402v_.ctl deleted
auxiliary instance file t_emp_recvr.dmp deleted
Finished recover at 10-JAN-18

5.通过t_emp.dmp文件将表t_emp中的数据导入

[oracle@jytest3 dump]$ impdp hr/hr@orcl dumpfile=dump_dir:t_emp.dmp

Import: Release 12.2.0.1.0 - Production on Wed Jan 10 03:23:34 2018

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Master table "HR"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "HR"."SYS_IMPORT_FULL_01":  hr/********@orcl dumpfile=dump_dir:t_emp.dmp 
Processing object type TABLE_EXPORT/TABLE/TABLE
ORA-39151: Table "HR"."T_EMP" exists. All dependent metadata and data will be skipped due to table_exists_action of skip

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
Job "HR"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Wed Jan 10 03:23:51 2018 elapsed 0 00:00:10

报错是因为表t_emp已经存在,impdp的缺省操作就是跳过对这张表进行导入操作,所以需要使用选项table_exists_action=truncate来进行导入。

[oracle@jytest3 dump]$ impdp hr/hr@orcl dumpfile=dump_dir:t_emp.dmp table_exists_action=truncate

Import: Release 12.2.0.1.0 - Production on Wed Jan 10 03:29:10 2018

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Master table "HR"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "HR"."SYS_IMPORT_FULL_01":  hr/********@orcl dumpfile=dump_dir:t_emp.dmp table_exists_action=truncate 
Processing object type TABLE_EXPORT/TABLE/TABLE
Table "HR"."T_EMP" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "HR"."T_EMP"                                17.08 KB     107 rows
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
Job "HR"."SYS_IMPORT_FULL_01" successfully completed at Wed Jan 10 03:29:30 2018 elapsed 0 00:00:18

6.验证表t_emp中的记录,可以看到已经成功恢复到被删了记录之前的状态。

SQL> select count(*) from t_emp;

  COUNT(*)
----------
       107

12C还原使用旧版本RMAN所创建的备份

可以还原使用旧版本RMAN所创建的备份,最旧版本为9.2.0.8。在创建备份的数据库版本与还原备份的数据库版本之间必须有支持的升级路径存在。比如,源数据库的版本为11gr2并且配置使用spfile参数文件。数据库启用了归档与快速闪回区。控制文件也被配置为自动备份。对源数据库创建了RMAN备份,并且包含了归档重做日志。要还原这些备份的主机上运行的是Oracle 12cr2的数据库版本。

还原使用旧版本RMAN所创建备份到当前目标数据库版本(12.2)的操作步骤如下:
1.验证创建备份的数据库版本与还原备份的数据库版本之间是否存在升级路径。例如,将Oracle 11.2.0.4所创建的RMAN备份还原到Oracle 12.2,那么必须支持从11.2.0.4升级到12.2,根据Oracle的升级指南,11.2.0.3及以后版本可以直接升级到Oracle 12.2。

2.对源数据库(jyrac为rac数据库)创建RMAN备份

RMAN> backup as compressed backupset database format '/acfs1/rman_back/jyrac_%u_%d_%t_%s_%p'  plus archivelog format '/acfs1/rman_back/arch_%d_%T_%U';


Starting backup at 29-DEC-17
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=497 RECID=1044 STAMP=964006170
input archived log thread=2 sequence=540 RECID=1045 STAMP=964006171
channel ORA_DISK_1: starting piece 1 at 29-DEC-17
channel ORA_DISK_1: finished piece 1 at 29-DEC-17
piece handle=/acfs1/rman_back/arch_JYRAC_20171229_0isnb48r_1_1 tag=TAG20171229T112931 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-DEC-17

Starting backup at 29-DEC-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00012 name=+DATADG/jyrac/datafile/ldjc01
input datafile file number=00002 name=+DATADG/jyrac/datafile/sysaux.258.930413055
input datafile file number=00011 name=+DATADG/jyrac/datafile/cdzj01
input datafile file number=00001 name=+DATADG/jyrac/datafile/system.259.930413057
input datafile file number=00003 name=+DATADG/jyrac/datafile/undotbs1.262.930413057
input datafile file number=00008 name=+DATADG/jyrac/datafile/sales_test_01.dbf
input datafile file number=00005 name=+DATADG/jyrac/datafile/example.260.930413057
input datafile file number=00006 name=+DATADG/jyrac/datafile/undotbs2.261.930413057
input datafile file number=00007 name=+DATADG/jyrac/datafile/test01.dbf
input datafile file number=00009 name=+DATADG/jyrac/datafile/emp_test_01.dbf
input datafile file number=00010 name=+DATADG/jyrac/datafile/orders_test_01.dbf
input datafile file number=00004 name=+DATADG/jyrac/datafile/users.263.930413057
channel ORA_DISK_1: starting piece 1 at 29-DEC-17
channel ORA_DISK_1: finished piece 1 at 29-DEC-17
piece handle=/acfs1/rman_back/jyrac_0jsnb48u_JYRAC_964006174_19_1 tag=TAG20171229T112933 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:09:06
Finished backup at 29-DEC-17

Starting backup at 29-DEC-17
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=498 RECID=1046 STAMP=964006723
input archived log thread=2 sequence=541 RECID=1047 STAMP=964006720
channel ORA_DISK_1: starting piece 1 at 29-DEC-17
channel ORA_DISK_1: finished piece 1 at 29-DEC-17
piece handle=/acfs1/rman_back/arch_JYRAC_20171229_0ksnb4q5_1_1 tag=TAG20171229T113845 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-DEC-17

Starting Control File and SPFILE Autobackup at 29-DEC-17
piece handle=/acfs1/rman_back/c-2655496871-20171229-00 comment=NONE
Finished Control File and SPFILE Autobackup at 29-DEC-17



RMAN> list backup;


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


BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
9       24.50K     DISK        00:00:01     29-DEC-17      
        BP Key: 9   Status: AVAILABLE  Compressed: YES  Tag: TAG20171229T112931
        Piece Name: /acfs1/rman_back/arch_JYRAC_20171229_0isnb48r_1_1

  List of Archived Logs in backup set 9
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    497     14690299647719 29-DEC-17 14690299647943 29-DEC-17
  2    540     14690299647723 29-DEC-17 14690299647960 29-DEC-17

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10      Full    1.82G      DISK        00:09:05     29-DEC-17      
        BP Key: 10   Status: AVAILABLE  Compressed: YES  Tag: TAG20171229T112933
        Piece Name: /acfs1/rman_back/jyrac_0jsnb48u_JYRAC_964006174_19_1
  List of Datafiles in backup set 10
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/system.259.930413057
  2       Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/sysaux.258.930413055
  3       Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/undotbs1.262.930413057
  4       Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/users.263.930413057
  5       Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/example.260.930413057
  6       Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/undotbs2.261.930413057
  7       Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/test01.dbf
  8       Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/sales_test_01.dbf
  9       Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/emp_test_01.dbf
  10      Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/orders_test_01.dbf
  11      Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/cdzj01
  12      Full 14690299647966 29-DEC-17 +DATADG/jyrac/datafile/ldjc01

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
11      92.50K     DISK        00:00:01     29-DEC-17      
        BP Key: 11   Status: AVAILABLE  Compressed: YES  Tag: TAG20171229T113845
        Piece Name: /acfs1/rman_back/arch_JYRAC_20171229_0ksnb4q5_1_1

  List of Archived Logs in backup set 11
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    498     14690299647943 29-DEC-17 14690299648779 29-DEC-17
  2    541     14690299647960 29-DEC-17 14690299648994 29-DEC-17

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
12      Full    17.89M     DISK        00:00:08     29-DEC-17      
        BP Key: 12   Status: AVAILABLE  Compressed: NO  Tag: TAG20171229T113847
        Piece Name: /acfs1/rman_back/c-2655496871-20171229-00
  SPFILE Included: Modification time: 29-DEC-17
  SPFILE db_unique_name: JYRAC
  Control File Included: Ckp SCN: 14690299650469   Ckp time: 29-DEC-17


[grid@jyrac1 rman_back]$ ls -lrt
total 1929424
-rw-r----- 1 oracle asmadmin      25600 Dec 29 11:29 arch_JYRAC_20171229_0isnb48r_1_1
-rw-r----- 1 oracle asmadmin 1951571968 Dec 29 11:38 jyrac_0jsnb48u_JYRAC_964006174_19_1
-rw-r----- 1 oracle asmadmin      95232 Dec 29 11:38 arch_JYRAC_20171229_0ksnb4q5_1_1
-rw-r----- 1 oracle asmadmin   18776064 Dec 29 11:38 c-2655496871-20171229-00

3.将步骤2生成的RMAN备份文件拷贝到目标主机相应目录(/ora_xtts/rman)中

[oracle@jytest3 rman]$ scp oracle@10.138.130.151:/acfs1/rman_back/* /ora_xtts/rman/
The authenticity of host '10.138.130.151 (10.138.130.151)' can't be established.
RSA key fingerprint is 92:b7:e1:f5:a4:99:5a:de:d5:d3:f2:25:f7:98:0a:a1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.138.130.151' (RSA) to the list of known hosts.
oracle@10.138.130.151's password: 
arch_JYRAC_20171229_0isnb48r_1_1                                                                                                                                                              

            100%   25KB  25.0KB/s   00:00    
arch_JYRAC_20171229_0ksnb4q5_1_1                                                                                                                                                              

            100%   93KB  93.0KB/s   00:00    
c-2655496871-20171229-00                                                                                                                                                                      

            100%   18MB  17.9MB/s   00:01    
jyrac_0jsnb48u_JYRAC_964006174_19_1                                                                                                                                                           

            100% 1861MB  38.0MB/s   00:49    
[oracle@jytest3 rman]$ ls -lrt
total 1924300
-rw-r-----. 1 oracle oinstall      25600 Dec 30 01:48 arch_JYRAC_20171229_0isnb48r_1_1
-rw-r-----. 1 oracle oinstall      95232 Dec 30 01:48 arch_JYRAC_20171229_0ksnb4q5_1_1
-rw-r-----. 1 oracle oinstall   18776064 Dec 30 01:48 c-2655496871-20171229-00
-rw-r-----. 1 oracle oinstall 1951571968 Dec 30 01:49 jyrac_0jsnb48u_JYRAC_964006174_19_1

4.在目标主机上,设置ORACLE_SID为源数据库的SID(jyrac1为单实例数据库)

[oracle@jytest3 ~]$ export ORACLE_SID=jyrac1

5.在目标主机上启动RMAN并连接到目标数据库

[oracle@jytest3 ~]$ rman target/ nocatalog

Recovery Manager: Release 12.2.0.1.0 - Production on Sat Dec 30 02:06:59 2017

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

connected to target database (not started)

6.设置DBID,该值为源数据库的DBID

RMAN> set DBID 2655496871

executing command: SET DBID

7.启动目标数据库到nomount状态

RMAN> startup nomount

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/12.2.0/db/dbs/initjyrac1.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area    1073741824 bytes

Fixed Size                     8628936 bytes
Variable Size                293602616 bytes
Database Buffers             763363328 bytes
Redo Buffers                   8146944 bytes

RMAN查找spfile参数文件失败,因为它还没有被还原,然而,实例将会使用虚拟参数文件来进行启动。

8.从源数据库的自动备份文件中还原spfile参数文件
因为源数据库启用了控制文件自动备份,所以spfile参数文件会被包含在自动备份文件中。为了还原非缺省格式的自动备份,需要执行set controlfile autobackup format命令来指定格式。下面的命令将设置控制文件自动备份格式,将源数据库的spfile参数文件还原为/u01/app/oracle/product/12.2.0/db/dbs/initjyrac1.ora文件,然后关闭目标数据库。

RMAN> run
2> {
3> set controlfile autobackup format for device type disk to '/ora_xtts/rman/%F';
4> restore spfile to pfile '/u01/app/oracle/product/12.2.0/db/dbs/initjyrac1.ora' from autobackup;
5> shutdown abort;
6> }

executing command: SET CONTROLFILE AUTOBACKUP FORMAT

Starting restore at 30-DEC-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=6 device type=DISK

channel ORA_DISK_1: looking for AUTOBACKUP on day: 20171230
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20171229
channel ORA_DISK_1: AUTOBACKUP found: /ora_xtts/rman/c-2655496871-20171229-00
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /ora_xtts/rman/c-2655496871-20171229-00
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 30-DEC-17

Oracle instance shut down

9.编辑pfile参数文件并修改所需要的参数。这包括compatible参数,如果目标数据库的compatible参数不同于源数据库的设置,那么在目标数据库版本中这个参数会被弃用。更新以_DEST结尾的参数来反映新的目录结构。

[oracle@jytest3 dbs]$ mv initjyrac1.ora initjyrac1.ora.bak
[oracle@jytest3 dbs]$ vi initjyrac1.ora

*.audit_file_dest='/u01/app/oracle/admin/jyrac/adump'
*.audit_trail='db'
*.cluster_database=false
*.compatible='11.2.0.4.0'
*.control_files='+DATA/jyrac/controlfile/current.257.930412709'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_name='jyrac'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=jyracXDB)'
jyrac1.dispatchers='(PROTOCOL=TCP) (SERVICE=jyrac1XDB)'
jyrac1.instance_number=1
*.job_queue_processes=1000
*.log_archive_dest_1='location=+data/arch/jyrac'
*.open_cursors=300
*.pga_aggregate_target=836763648
*.processes=150
*.remote_login_passwordfile='exclusive'
*.sga_target=2510290944
jyrac2.thread=2
jyrac1.thread=1
jyrac1.undo_tablespace='UNDOTBS1'
jyrac2.undo_tablespace='UNDOTBS2'

10.使用编辑后的pfile参数文件来启动实例到nomount状态

RMAN> startup force nomount pfile='/u01/app/oracle/product/12.2.0/db/dbs/initjyrac1.ora'

Oracle instance started

Total System Global Area    2516582400 bytes

Fixed Size                     8623832 bytes
Variable Size                637536552 bytes
Database Buffers            1862270976 bytes
Redo Buffers                   8151040 bytes

11.从控制文件自动备份文件中还原控制文件并将目标数据库启动到mount状态,为了还原非缺省格式的自动备份,需要执行set controlfile autobackup format命令来指定格式。

RMAN> run
2> {
3> set controlfile autobackup format for device type disk to '/ora_xtts/rman/%F';
4> restore controlfile from autobackup;
5> alter database mount;
6> }

executing command: SET CONTROLFILE AUTOBACKUP FORMAT

Starting restore at 30-DEC-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=6 device type=DISK

channel ORA_DISK_1: looking for AUTOBACKUP on day: 20171230
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20171229
channel ORA_DISK_1: AUTOBACKUP found: /ora_xtts/rman/c-2655496871-20171229-00
channel ORA_DISK_1: restoring control file from AUTOBACKUP /ora_xtts/rman/c-2655496871-20171229-00
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=+DATA/JYRAC/CONTROLFILE/current.329.964063767
Finished restore at 30-DEC-17

Statement processed
released channel: ORA_DISK_1

控制文件会被还原到pfile参数文件中control_files参数所指定的目录中。

12.在目标主机上将源数据库的备份文件注册到rman档案库中。如果目录中的所有文件有共同的前缀,那么可以使用catalog start with命令。如果想要单独指定文件名来进行注册,那么执行catalog datafilecopy命令。我这里所有的备份文件存储在/ora_xtts/rman目录中,因此使用catalog start with命令进行注册。

RMAN> catalog start with '/ora_xtts/rman/';

searching for all files that match the pattern /ora_xtts/rman/

List of Files Unknown to the Database
=====================================
File Name: /ora_xtts/rman/arch_JYRAC_20171229_0isnb48r_1_1
File Name: /ora_xtts/rman/arch_JYRAC_20171229_0ksnb4q5_1_1
File Name: /ora_xtts/rman/c-2655496871-20171229-00
File Name: /ora_xtts/rman/jyrac_0jsnb48u_JYRAC_964006174_19_1

Do you really want to catalog the above files (enter YES or NO)? YES
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /ora_xtts/rman/arch_JYRAC_20171229_0isnb48r_1_1
File Name: /ora_xtts/rman/arch_JYRAC_20171229_0ksnb4q5_1_1
File Name: /ora_xtts/rman/c-2655496871-20171229-00
File Name: /ora_xtts/rman/jyrac_0jsnb48u_JYRAC_964006174_19_1

13.还原与恢复源数据库
如果数据文件要被还原到目标主机上的目录与源数据库所在的目录不相同,那么必须使用set newname命令来对还原的数据文件指定新的目录路径。如果联机重做日志将创建在与源数据库不相同的目录中,那么必须使用alter database rename file命令来为每个联机重做日志指定新的目录路径,在这里使用set newname for database命令来为所有被还原的数据文件指定新目录,新的联机重做日志文件使用alter database rename file命令来指定,并且指定恢复目标scn。

RMAN> run
2> {
3> set newname for database to '+data/jyrac/datafile/%U';
4> alter database rename file '+DATADG/jyrac/onlinelog/group_1.264.930413221' to '+data/jyrac/onlinelog/redo1.log';
5> alter database rename file '+DATADG/jyrac/onlinelog/group_2.265.930413225' to '+data/jyrac/onlinelog/redo2.log';
6> alter database rename file '+DATADG/jyrac/onlinelog/group_3.266.930413227' to '+data/jyrac/onlinelog/redo3.log';
7> alter database rename file '+DATADG/jyrac/onlinelog/group_4.267.930413231' to '+data/jyrac/onlinelog/redo4.log';
8> set until scn 14690299648200;
9> restore database;
10> switch datafile all;
11> recover database;
12> }

executing command: SET NEWNAME

Statement processed

Statement processed

Statement processed

Statement processed

executing command: SET until clause

Starting restore at 30-DEC-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=93 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 00001 to +data/jyrac/datafile/data_D-JYRAC_TS-SYSTEM_FNO-1
channel ORA_DISK_1: restoring datafile 00002 to +data/jyrac/datafile/data_D-JYRAC_TS-SYSAUX_FNO-2
channel ORA_DISK_1: restoring datafile 00003 to +data/jyrac/datafile/data_D-JYRAC_TS-UNDOTBS1_FNO-3
channel ORA_DISK_1: restoring datafile 00004 to +data/jyrac/datafile/data_D-JYRAC_TS-USERS_FNO-4
channel ORA_DISK_1: restoring datafile 00005 to +data/jyrac/datafile/data_D-JYRAC_TS-EXAMPLE_FNO-5
channel ORA_DISK_1: restoring datafile 00006 to +data/jyrac/datafile/data_D-JYRAC_TS-UNDOTBS2_FNO-6
channel ORA_DISK_1: restoring datafile 00007 to +data/jyrac/datafile/data_D-JYRAC_TS-TEST_FNO-7
channel ORA_DISK_1: restoring datafile 00008 to +data/jyrac/datafile/data_D-JYRAC_TS-SALES_TEST_FNO-8
channel ORA_DISK_1: restoring datafile 00009 to +data/jyrac/datafile/data_D-JYRAC_TS-EMP_TEST_FNO-9
channel ORA_DISK_1: restoring datafile 00010 to +data/jyrac/datafile/data_D-JYRAC_TS-ORDERS_TEST_FNO-10
channel ORA_DISK_1: restoring datafile 00011 to +data/jyrac/datafile/data_D-JYRAC_TS-CDZJ_FNO-11
channel ORA_DISK_1: restoring datafile 00012 to +data/jyrac/datafile/data_D-JYRAC_TS-LDJC_FNO-12
channel ORA_DISK_1: reading from backup piece /acfs1/rman_back/jyrac_0jsnb48u_JYRAC_964006174_19_1
channel ORA_DISK_1: errors found reading piece handle=/acfs1/rman_back/jyrac_0jsnb48u_JYRAC_964006174_19_1
channel ORA_DISK_1: failover to piece handle=/ora_xtts/rman/jyrac_0jsnb48u_JYRAC_964006174_19_1 tag=TAG20171229T112933
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:09:55
Finished restore at 30-DEC-17

datafile 1 switched to datafile copy
input datafile copy RECID=14 STAMP=964064400 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-system_fno-1
datafile 2 switched to datafile copy
input datafile copy RECID=15 STAMP=964064401 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-sysaux_fno-2
datafile 3 switched to datafile copy
input datafile copy RECID=16 STAMP=964064401 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-undotbs1_fno-3
datafile 4 switched to datafile copy
input datafile copy RECID=17 STAMP=964064401 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-users_fno-4
datafile 5 switched to datafile copy
input datafile copy RECID=18 STAMP=964064402 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-example_fno-5
datafile 6 switched to datafile copy
input datafile copy RECID=19 STAMP=964064402 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-undotbs2_fno-6
datafile 7 switched to datafile copy
input datafile copy RECID=20 STAMP=964064402 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-test_fno-7
datafile 8 switched to datafile copy
input datafile copy RECID=21 STAMP=964064403 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-sales_test_fno-8
datafile 9 switched to datafile copy
input datafile copy RECID=22 STAMP=964064403 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-emp_test_fno-9
datafile 10 switched to datafile copy
input datafile copy RECID=23 STAMP=964064403 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-orders_test_fno-10
datafile 11 switched to datafile copy
input datafile copy RECID=24 STAMP=964064404 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-cdzj_fno-11
datafile 12 switched to datafile copy
input datafile copy RECID=25 STAMP=964064404 file name=+DATA/jyrac/datafile/data_d-jyrac_ts-ldjc_fno-12

Starting recover at 30-DEC-17
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=498
channel ORA_DISK_1: restoring archived log
archived log thread=2 sequence=541
channel ORA_DISK_1: reading from backup piece /acfs1/rman_back/arch_JYRAC_20171229_0ksnb4q5_1_1
channel ORA_DISK_1: errors found reading piece handle=/acfs1/rman_back/arch_JYRAC_20171229_0ksnb4q5_1_1
channel ORA_DISK_1: failover to piece handle=/ora_xtts/rman/arch_JYRAC_20171229_0ksnb4q5_1_1 tag=TAG20171229T113845
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=+DATA/arch/jyrac/1_498_930413221.dbf thread=1 sequence=498
archived log file name=+DATA/arch/jyrac/2_541_930413221.dbf thread=2 sequence=541
media recovery complete, elapsed time: 00:00:02
Finished recover at 30-DEC-17

14.使用resetlogs与upgrade选项来打开数据库

RMAN> alter database open resetlogs upgrade;

Statement processed
RMAN-06900: warning: unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row
RMAN-06901: warning: disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT rows
ORACLE error from target database: 
ORA-04023: Object SYS.STANDARD could not be validated or authorized

错误信息是由于数据库相关plsql包作为升级处理需要被重新验证。

15.退出RMAN

RMAN> exit


Recovery Manager complete.

16.对还原后的目标数据库升级

SQL> shutdown abort
ORACLE instance shut down.
SQL> startup upgrade
ORACLE instance started.

Total System Global Area 2516582400 bytes
Fixed Size                  8623832 bytes
Variable Size             637536552 bytes
Database Buffers         1862270976 bytes
Redo Buffers                8151040 bytes
Database mounted.
Database opened.
SQL> @$ORACLE_HOME/rdbms/admin/catupgrd.sql
DOC>######################################################################
DOC>######################################################################
DOC>                                 ERROR
DOC>
DOC>
DOC>    As of 12.2, customers must use the parallel upgrade utility, catctl.pl,
DOC>    to invoke catupgrd.sql when upgrading the database dictionary.
DOC>    Running catupgrd.sql directly from SQL*Plus is no longer supported.
DOC>
DOC>    For Example:
DOC>
DOC>          cd $ORACLE_HOME/rdbms/admin
DOC>          catctl
DOC>
DOC>          or
DOC>
DOC>          cd $ORACLE_HOME/rdbms/admin
DOC>          $ORACLE_HOME/perl/bin/perl catctl.pl catupgrd.sql
DOC>
DOC>    Refer to the Oracle Database Upgrade Guide for more information.
DOC>
DOC>
DOC>######################################################################
DOC>######################################################################
DOC>#
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

12cr2升级方法与之前不同,要执行如下命令:

[oracle@jytest3 admin]$ cd $ORACLE_HOME/rdbms/admin
[oracle@jytest3 admin]$ $ORACLE_HOME/perl/bin/perl catctl.pl catupgrd.sql

Argument list for [catctl.pl]
Run in                c = 0
Do not run in         C = 0
Input Directory       d = 0
Echo OFF              e = 1
Simulate              E = 0
Forced cleanup        F = 0
Log Id                i = 0
Child Process         I = 0
Log Dir               l = 0
Priority List Name    L = 0
Upgrade Mode active   M = 0
SQL Process Count     n = 0
SQL PDB Process Count N = 0
Open Mode Normal      o = 0
Start Phase           p = 0
End Phase             P = 0
Reverse Order         r = 0
AutoUpgrade Resume    R = 0
Script                s = 0
Serial Run            S = 0
RO User Tablespaces   T = 0
Display Phases        y = 0
Debug catcon.pm       z = 0
Debug catctl.pl       Z = 0

catctl.pl VERSION: [12.2.0.1.0]
           STATUS: [production]
            BUILD: [RDBMS_12.2.0.1.0_LINUX.X64_170125]


/u01/app/oracle/product/12.2.0/db/rdbms/admin/orahome = [/u01/app/oracle/product/12.2.0/db]
/u01/app/oracle/product/12.2.0/db/bin/orabasehome = [/u01/app/oracle/product/12.2.0/db]
catctlGetOrabase = [/u01/app/oracle/product/12.2.0/db]

Analyzing file /u01/app/oracle/product/12.2.0/db/rdbms/admin/catupgrd.sql

Log file directory = [/tmp/cfgtoollogs/upgrade20171230035616]

catcon: ALL catcon-related output will be written to [/tmp/cfgtoollogs/upgrade20171230035616/catupgrd_catcon_11460.lst]
catcon: See [/tmp/cfgtoollogs/upgrade20171230035616/catupgrd*.log] files for output generated by scripts
catcon: See [/tmp/cfgtoollogs/upgrade20171230035616/catupgrd_*.lst] files for spool files, if any

Number of Cpus        = 6
Database Name         = jyrac
DataBase Version      = 11.2.0.4.0
catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db/cfgtoollogs/jyrac/upgrade20171230035617/catupgrd_catcon_11460.lst]
catcon: See [/u01/app/oracle/product/12.2.0/db/cfgtoollogs/jyrac/upgrade20171230035617/catupgrd*.log] files for output generated by scripts
catcon: See [/u01/app/oracle/product/12.2.0/db/cfgtoollogs/jyrac/upgrade20171230035617/catupgrd_*.lst] files for spool files, if any

Log file directory = [/u01/app/oracle/product/12.2.0/db/cfgtoollogs/jyrac/upgrade20171230035617]

Parallel SQL Process Count            = 4
Components in [jyrac]
    Installed [APEX APS CATALOG CATJAVA CATPROC CONTEXT EM JAVAVM ORDIM OWM RAC SDO XDB XML XOQ]
Not Installed [DV MGW ODM OLS WK]
....省略....

使用RMAN对PDB执行按时间点恢复

对PDB执行按时间点恢复类似于执行数据库按时间点恢复。当对一个或多个PDB恢复到指定时间点时,CDB中的其它PDB不受影响。在恢复之后,PDB原来的保留的旧备份仍然有效可以在出现介质恢复时使用,不需要创建新的备份。当对使用共享UNDO的CDB中的一个或多个PDB执行数据库按时间点恢复时,对于包含被恢复PDB的CDB的root与CDB seed(PDB$SEES)需要有备份。从Oracle 12.2开始,如果compatible参数被设置为12.2,那么可以跨PDB闪回操作或PDB按时间点恢复来对CDB执行闪回数据库操作。在DG环境中,对于备库将跟随主库PDB会被恢复到指定的时间点,你可以闪回整个备库,恢复PDB或对PDB执行闪回。

对PDB执行按时间点恢复的操作步骤如下:
1.登录数据库记录当前SCN号,然后将表t1中的数据删除。

SQL> conn jy/jy@jypdb
Connected.
SQL> SELECT CURRENT_SCN   FROM V$DATABASE;

CURRENT_SCN
-----------
    6255735

SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

Session altered.

SQL> select sysdate from dual;

SYSDATE
-------------------
2017-12-20 16:52:31

SQL> select count(*) from t1;

  COUNT(*)
----------
        39

SQL> truncate table t1;

Table truncated.

SQL> select count(*) from t1;

  COUNT(*)
----------
         0

2.如果使用时间表达式来代替目标SCN,那么在调用RMAN之前设置时间格式环境变量

[oracle@jytest1 ~]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'

3.使用RMAN连接到root容器

[oracle@jytest1 ~]$ rman target/ catalog rco/xxzx7817600@jypdb_173

Recovery Manager: Release 12.2.0.1.0 - Production on Wed Dec 20 16:53:26 2017

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

connected to target database: JY (DBID=979425723)
connected to recovery catalog database

4.将要执行恢复的PDB关闭,其它的PDB与CDB仍然处于open状态

RMAN> alter pluggable database jypdb close immediate;

starting full resync of recovery catalog
full resync complete
Statement processed
starting full resync of recovery catalog
full resync complete

5.使用RUN块来执行以下操作
a.对于数据库按时间点鶋,使用set until来指定恢复的目标时间,scn或日志序列号,或者使用set to来指定还原点。如果指定时间那么使用环境变量nls_lang与nls_date_format中所指定的日期格式。

b.如果RMAN没有配置自动通道,那么需要手动分配磁盘与磁带通道。

c.还原与恢复CDB

下面的命令将PDB(jypdb)恢复到SCN=6255735所在的状态

RMAN> run
2> {
3>    set until scn 6255735;
4>    restore pluggable database jypdb;
5>    recover pluggable database jypdb;
6> }

executing command: SET until clause

Starting restore at 2017-12-20 17:00:38
using channel ORA_DISK_1

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 00010 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.271.962209649
channel ORA_DISK_1: restoring datafile 00011 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.316.962209649
channel ORA_DISK_1: restoring datafile 00012 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.264.962209649
channel ORA_DISK_1: restoring datafile 00013 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.268.962209649
channel ORA_DISK_1: restoring datafile 00014 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.278.962209649
channel ORA_DISK_1: restoring datafile 00015 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.275.962210609
channel ORA_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_962563516_11slv3ds_1_1
channel ORA_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_962563516_11slv3ds_1_1 tag=TAG20171212T184328
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 2017-12-20 17:01:15

Starting recover at 2017-12-20 17:01:16
current log archived
using channel ORA_DISK_1


starting media recovery

archived log for thread 1 with sequence 38 is already on disk as file +TEST/arch/1_38_961976319.dbf
archived log for thread 1 with sequence 39 is already on disk as file +TEST/arch/1_39_961976319.dbf
archived log for thread 1 with sequence 40 is already on disk as file +TEST/arch/1_40_961976319.dbf
archived log for thread 1 with sequence 41 is already on disk as file +TEST/arch/1_41_961976319.dbf
archived log for thread 1 with sequence 42 is already on disk as file +TEST/arch/1_42_961976319.dbf
archived log for thread 1 with sequence 43 is already on disk as file +TEST/arch/1_43_961976319.dbf
archived log for thread 1 with sequence 44 is already on disk as file +TEST/arch/1_44_961976319.dbf
archived log for thread 1 with sequence 45 is already on disk as file +TEST/arch/1_45_961976319.dbf
archived log for thread 1 with sequence 46 is already on disk as file +TEST/arch/1_46_961976319.dbf
archived log for thread 1 with sequence 47 is already on disk as file +TEST/arch/1_47_961976319.dbf
archived log for thread 1 with sequence 48 is already on disk as file +TEST/arch/1_48_961976319.dbf
archived log for thread 1 with sequence 49 is already on disk as file +TEST/arch/1_49_961976319.dbf
archived log for thread 1 with sequence 50 is already on disk as file +TEST/arch/1_50_961976319.dbf
archived log for thread 1 with sequence 51 is already on disk as file +TEST/arch/1_51_961976319.dbf
archived log for thread 1 with sequence 52 is already on disk as file +TEST/arch/1_52_961976319.dbf
archived log for thread 1 with sequence 53 is already on disk as file +TEST/arch/1_53_961976319.dbf
archived log for thread 1 with sequence 54 is already on disk as file +TEST/arch/1_54_961976319.dbf
archived log for thread 1 with sequence 55 is already on disk as file +TEST/arch/1_55_961976319.dbf
archived log for thread 1 with sequence 56 is already on disk as file +TEST/arch/1_56_961976319.dbf
archived log for thread 1 with sequence 57 is already on disk as file +TEST/arch/1_57_961976319.dbf
archived log for thread 2 with sequence 32 is already on disk as file +TEST/arch/2_32_961976319.dbf
archived log for thread 2 with sequence 33 is already on disk as file +TEST/arch/2_33_961976319.dbf
archived log for thread 2 with sequence 34 is already on disk as file +TEST/arch/2_34_961976319.dbf
archived log for thread 2 with sequence 35 is already on disk as file +TEST/arch/2_35_961976319.dbf
archived log for thread 2 with sequence 36 is already on disk as file +TEST/arch/2_36_961976319.dbf
archived log for thread 2 with sequence 37 is already on disk as file +TEST/arch/2_37_961976319.dbf
archived log for thread 2 with sequence 38 is already on disk as file +TEST/arch/2_38_961976319.dbf
archived log for thread 2 with sequence 39 is already on disk as file +TEST/arch/2_39_961976319.dbf
archived log for thread 2 with sequence 40 is already on disk as file +TEST/arch/2_40_961976319.dbf
archived log for thread 2 with sequence 41 is already on disk as file +TEST/arch/2_41_961976319.dbf
archived log for thread 2 with sequence 42 is already on disk as file +TEST/arch/2_42_961976319.dbf
archived log for thread 2 with sequence 43 is already on disk as file +TEST/arch/2_43_961976319.dbf
archived log for thread 2 with sequence 44 is already on disk as file +TEST/arch/2_44_961976319.dbf
archived log for thread 2 with sequence 45 is already on disk as file +TEST/arch/2_45_961976319.dbf
archived log for thread 2 with sequence 46 is already on disk as file +TEST/arch/2_46_961976319.dbf
archived log for thread 2 with sequence 47 is already on disk as file +TEST/arch/2_47_961976319.dbf
archived log for thread 2 with sequence 48 is already on disk as file +TEST/arch/2_48_961976319.dbf
archived log for thread 2 with sequence 49 is already on disk as file +TEST/arch/2_49_961976319.dbf
archived log for thread 2 with sequence 50 is already on disk as file +TEST/arch/2_50_961976319.dbf
archived log for thread 2 with sequence 51 is already on disk as file +TEST/arch/2_51_961976319.dbf
archived log for thread 2 with sequence 52 is already on disk as file +DATA/JY/ONLINELOG/group_4.262.961976705
archived log for thread 2 with sequence 53 is already on disk as file +DATA/JY/ONLINELOG/group_3.263.961976697
media recovery complete, elapsed time: 00:04:03
Finished recover at 2017-12-20 17:05:30
starting full resync of recovery catalog
full resync complete

6. 以读写方式打开PDB,放弃目标SCN之后的所有改变,执行以下命令

RMAN> alter pluggable database jypdb open resetlogs;

Statement processed
starting full resync of recovery catalog
full resync complete



SQL> conn jy/jy@jypdb
Connected.
SQL> select count(*) from t1;

  COUNT(*)
----------
        39

使用RMAN对CDB执行按时间点恢复

使用RMAN对CDB和PDB执行按时间点恢复
RMAN能够对CDB与PDB执行按时间点恢复操作。但是PDB只能使用RMAN来执行按时间点恢复。如是没有使用恢复目录数据库,建议启用自动控制文件备份。否则当对PDB执行按时间点恢复时,当RMAN需要增加与删除undo数据文件时不能有效的执行。

PDB按时间点恢复与快速恢复区
当对PDB执行数据库按时间点恢复时,对于这个PDB所有的数据文件都将被执行恢复操作。然而,为了将PDB恢复到指定的时间点,RMAN在恢复目标时间点也是需要有UNDO表空间存在的。因为undo表空间是被所有PDB所共享的,它不能被恢复。RMAN会将root中的undo,system与sysaux表空间还原到辅助实例中,然后使用undo信息来将pdb恢复到指定的时间点。如果配置了快速恢复区,Oracle将会使用它作为辅助实例的存储目录。如果快速恢复区没有被配置,那么必须使用auxiliary destination子句来指定辅助实例数据库文件的存储目录。确保在快速恢复区有足够的空间可以用来还原root表空间与undo表空间。如果快速恢复区没有足够的空间,可以通过使用auxiliary destination子句来指定其它的目录。

对CDB执行数据库按时间点恢复
1.登录数据库记录当前SCN号,然后将表t1中的数据删除。

SQL> conn jy/jy@jypdb
Connected.
SQL> SELECT CURRENT_SCN   FROM V$DATABASE;

CURRENT_SCN
-----------
    6041183

SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

Session altered.

SQL> select sysdate from dual;

SYSDATE
-------------------
2017-12-18 18:28:30

SQL> select count(*) from t1;

  COUNT(*)
----------
        39

SQL> truncate table t1;

Table truncated.

SQL> select count(*) from t1;

  COUNT(*)
----------
         0

2.如果使用时间表达式来代替目标SCN,那么在调用RMAN之前设置时间格式环境变量

[oracle@jytest1 ~]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'

3.使用RMAN连接到root容器

[oracle@jytest1 ~]$ rman target/ catalog rco/xxzx7817600@jypdb_173

Recovery Manager: Release 12.2.0.1.0 - Production on Mon Dec 18 18:32:00 2017

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

connected to target database: JY (DBID=979425723)
connected to recovery catalog database

4.将CDB重启到mount状态

RMAN> shutdown immediate

starting full resync of recovery catalog
full resync complete
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    6442450944 bytes

Fixed Size                     8807168 bytes
Variable Size               1895828736 bytes
Database Buffers            4529848320 bytes
Redo Buffers                   7966720 bytes
starting full resync of recovery catalog
full resync complete

5.使用RUN块来执行以下操作
a.对于数据库按时间点鶋,使用set until来指定恢复的目标时间,scn或日志序列号,或者使用set to来指定还原点。如果指定时间那么使用环境变量nls_lang与nls_date_format中所指定的日期格式。

b.如果RMAN没有配置自动通道,那么需要手动分配磁盘与磁带通道。

c.还原与恢复CDB

下面的命令将CDB恢复到SCN=6041183所在的状态

RMAN> run
2> {
3>    set until scn 6041183;
4>    restore database;
5>    recover database;
6> }

executing command: SET until clause

Starting restore at 2017-12-18 18:46:50
flashing back control file to SCN 6041183
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=764 instance=jy1 device type=DISK

skipping datafile 5; already restored to file +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/system.256.962209675
skipping datafile 6; already restored to file +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.270.962209675
skipping datafile 8; already restored to file +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.296.962209675
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 00001 to +DATA/JY/DATAFILE/system.317.962209603
channel ORA_DISK_1: restoring datafile 00003 to +DATA/JY/DATAFILE/sysaux.298.962209605
channel ORA_DISK_1: restoring datafile 00004 to +DATA/JY/DATAFILE/undotbs1.277.962209605
channel ORA_DISK_1: restoring datafile 00007 to +DATA/JY/DATAFILE/users.301.962209605
channel ORA_DISK_1: restoring datafile 00009 to +DATA/JY/DATAFILE/undotbs2.312.962209605
channel ORA_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_962563410_10slv3ai_1_1
channel ORA_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_962563410_10slv3ai_1_1 tag=TAG20171212T184328
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:05
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 00010 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.271.962209649
channel ORA_DISK_1: restoring datafile 00011 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.316.962209649
channel ORA_DISK_1: restoring datafile 00012 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.264.962209649
channel ORA_DISK_1: restoring datafile 00013 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.268.962209649
channel ORA_DISK_1: restoring datafile 00014 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.278.962209649
channel ORA_DISK_1: restoring datafile 00015 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.275.962210609
channel ORA_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_962563516_11slv3ds_1_1
channel ORA_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_962563516_11slv3ds_1_1 tag=TAG20171212T184328
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
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 00016 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/system.260.962469409
channel ORA_DISK_1: restoring datafile 00017 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.259.962469409
channel ORA_DISK_1: restoring datafile 00018 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.265.962469409
channel ORA_DISK_1: restoring datafile 00019 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.266.962469409
channel ORA_DISK_1: restoring datafile 00020 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.267.962469409
channel ORA_DISK_1: restoring datafile 00021 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.269.962469409
channel ORA_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_962563551_12slv3ev_1_1
channel ORA_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_962563551_12slv3ev_1_1 tag=TAG20171212T184328
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 2017-12-18 18:49:09

Starting recover at 2017-12-18 18:49:11
using channel ORA_DISK_1
applied offline range to datafile 00010
offline range RECID=80 STAMP=963072332
applied offline range to datafile 00011
offline range RECID=79 STAMP=963072332
applied offline range to datafile 00012
offline range RECID=78 STAMP=963072332
applied offline range to datafile 00013
offline range RECID=77 STAMP=963072332
applied offline range to datafile 00014
offline range RECID=76 STAMP=963072332
applied offline range to datafile 00015
offline range RECID=75 STAMP=963072332
applied offline range to datafile 00016
offline range RECID=86 STAMP=963072332
applied offline range to datafile 00017
offline range RECID=85 STAMP=963072332
applied offline range to datafile 00018
offline range RECID=84 STAMP=963072332
applied offline range to datafile 00019
offline range RECID=83 STAMP=963072332
applied offline range to datafile 00020
offline range RECID=82 STAMP=963072332
applied offline range to datafile 00021
offline range RECID=81 STAMP=963072332

starting media recovery

archived log for thread 1 with sequence 34 is already on disk as file +TEST/arch/1_34_961976319.dbf
archived log for thread 1 with sequence 35 is already on disk as file +TEST/arch/1_35_961976319.dbf
archived log for thread 1 with sequence 36 is already on disk as file +TEST/arch/1_36_961976319.dbf
archived log for thread 1 with sequence 37 is already on disk as file +TEST/arch/1_37_961976319.dbf
archived log for thread 1 with sequence 38 is already on disk as file +TEST/arch/1_38_961976319.dbf
archived log for thread 1 with sequence 39 is already on disk as file +TEST/arch/1_39_961976319.dbf
archived log for thread 1 with sequence 40 is already on disk as file +TEST/arch/1_40_961976319.dbf
archived log for thread 1 with sequence 41 is already on disk as file +TEST/arch/1_41_961976319.dbf
archived log for thread 1 with sequence 42 is already on disk as file +TEST/arch/1_42_961976319.dbf
archived log for thread 1 with sequence 43 is already on disk as file +TEST/arch/1_43_961976319.dbf
archived log for thread 1 with sequence 44 is already on disk as file +TEST/arch/1_44_961976319.dbf
archived log for thread 1 with sequence 45 is already on disk as file +TEST/arch/1_45_961976319.dbf
archived log for thread 1 with sequence 46 is already on disk as file +TEST/arch/1_46_961976319.dbf
archived log for thread 1 with sequence 47 is already on disk as file +TEST/arch/1_47_961976319.dbf
archived log for thread 1 with sequence 48 is already on disk as file +TEST/arch/1_48_961976319.dbf
archived log for thread 1 with sequence 49 is already on disk as file +TEST/arch/1_49_961976319.dbf
archived log for thread 1 with sequence 50 is already on disk as file +TEST/arch/1_50_961976319.dbf
archived log for thread 1 with sequence 51 is already on disk as file +TEST/arch/1_51_961976319.dbf
archived log for thread 1 with sequence 52 is already on disk as file +DATA/JY/ONLINELOG/group_2.302.961976321
archived log for thread 1 with sequence 53 is already on disk as file +DATA/JY/ONLINELOG/group_1.261.961976319
archived log for thread 2 with sequence 28 is already on disk as file +TEST/arch/2_28_961976319.dbf
archived log for thread 2 with sequence 29 is already on disk as file +TEST/arch/2_29_961976319.dbf
archived log for thread 2 with sequence 30 is already on disk as file +TEST/arch/2_30_961976319.dbf
archived log for thread 2 with sequence 31 is already on disk as file +TEST/arch/2_31_961976319.dbf
archived log for thread 2 with sequence 32 is already on disk as file +TEST/arch/2_32_961976319.dbf
archived log for thread 2 with sequence 33 is already on disk as file +TEST/arch/2_33_961976319.dbf
archived log for thread 2 with sequence 34 is already on disk as file +TEST/arch/2_34_961976319.dbf
archived log for thread 2 with sequence 35 is already on disk as file +TEST/arch/2_35_961976319.dbf
archived log for thread 2 with sequence 36 is already on disk as file +TEST/arch/2_36_961976319.dbf
archived log for thread 2 with sequence 37 is already on disk as file +TEST/arch/2_37_961976319.dbf
archived log for thread 2 with sequence 38 is already on disk as file +TEST/arch/2_38_961976319.dbf
archived log for thread 2 with sequence 39 is already on disk as file +TEST/arch/2_39_961976319.dbf
archived log for thread 2 with sequence 40 is already on disk as file +TEST/arch/2_40_961976319.dbf
archived log for thread 2 with sequence 41 is already on disk as file +TEST/arch/2_41_961976319.dbf
archived log for thread 2 with sequence 42 is already on disk as file +TEST/arch/2_42_961976319.dbf
archived log for thread 2 with sequence 43 is already on disk as file +TEST/arch/2_43_961976319.dbf
archived log for thread 2 with sequence 44 is already on disk as file +TEST/arch/2_44_961976319.dbf
archived log for thread 2 with sequence 45 is already on disk as file +TEST/arch/2_45_961976319.dbf
archived log for thread 2 with sequence 46 is already on disk as file +TEST/arch/2_46_961976319.dbf
archived log for thread 2 with sequence 47 is already on disk as file +TEST/arch/2_47_961976319.dbf
archived log for thread 2 with sequence 48 is already on disk as file +TEST/arch/2_48_961976319.dbf
archived log for thread 2 with sequence 49 is already on disk as file +TEST/arch/2_49_961976319.dbf
archived log for thread 2 with sequence 50 is already on disk as file +TEST/arch/2_50_961976319.dbf
archived log for thread 2 with sequence 51 is already on disk as file +TEST/arch/2_51_961976319.dbf
archived log for thread 2 with sequence 52 is already on disk as file +DATA/JY/ONLINELOG/group_4.262.961976705
archived log for thread 2 with sequence 53 is already on disk as file +DATA/JY/ONLINELOG/group_3.263.961976697
archived log file name=+TEST/arch/1_34_961976319.dbf thread=1 sequence=34
archived log file name=+TEST/arch/2_28_961976319.dbf thread=2 sequence=28
archived log file name=+TEST/arch/1_35_961976319.dbf thread=1 sequence=35
archived log file name=+TEST/arch/2_29_961976319.dbf thread=2 sequence=29
archived log file name=+TEST/arch/1_36_961976319.dbf thread=1 sequence=36
archived log file name=+TEST/arch/2_30_961976319.dbf thread=2 sequence=30
archived log file name=+TEST/arch/2_31_961976319.dbf thread=2 sequence=31
archived log file name=+TEST/arch/1_37_961976319.dbf thread=1 sequence=37
archived log file name=+TEST/arch/2_32_961976319.dbf thread=2 sequence=32
archived log file name=+TEST/arch/1_38_961976319.dbf thread=1 sequence=38
archived log file name=+TEST/arch/2_33_961976319.dbf thread=2 sequence=33
archived log file name=+TEST/arch/1_39_961976319.dbf thread=1 sequence=39
archived log file name=+TEST/arch/2_34_961976319.dbf thread=2 sequence=34
archived log file name=+TEST/arch/1_40_961976319.dbf thread=1 sequence=40
archived log file name=+TEST/arch/2_35_961976319.dbf thread=2 sequence=35
archived log file name=+TEST/arch/1_41_961976319.dbf thread=1 sequence=41
archived log file name=+TEST/arch/2_36_961976319.dbf thread=2 sequence=36
archived log file name=+TEST/arch/1_42_961976319.dbf thread=1 sequence=42
archived log file name=+TEST/arch/2_37_961976319.dbf thread=2 sequence=37
archived log file name=+TEST/arch/2_38_961976319.dbf thread=2 sequence=38
archived log file name=+TEST/arch/1_43_961976319.dbf thread=1 sequence=43
archived log file name=+TEST/arch/2_39_961976319.dbf thread=2 sequence=39
archived log file name=+TEST/arch/1_44_961976319.dbf thread=1 sequence=44
archived log file name=+TEST/arch/2_40_961976319.dbf thread=2 sequence=40
archived log file name=+TEST/arch/1_45_961976319.dbf thread=1 sequence=45
archived log file name=+TEST/arch/2_41_961976319.dbf thread=2 sequence=41
archived log file name=+TEST/arch/1_46_961976319.dbf thread=1 sequence=46
archived log file name=+TEST/arch/2_42_961976319.dbf thread=2 sequence=42
archived log file name=+TEST/arch/2_43_961976319.dbf thread=2 sequence=43
archived log file name=+TEST/arch/1_47_961976319.dbf thread=1 sequence=47
archived log file name=+TEST/arch/2_44_961976319.dbf thread=2 sequence=44
archived log file name=+TEST/arch/2_45_961976319.dbf thread=2 sequence=45
archived log file name=+TEST/arch/1_48_961976319.dbf thread=1 sequence=48
archived log file name=+TEST/arch/2_46_961976319.dbf thread=2 sequence=46
archived log file name=+TEST/arch/1_49_961976319.dbf thread=1 sequence=49
archived log file name=+TEST/arch/2_47_961976319.dbf thread=2 sequence=47
archived log file name=+TEST/arch/2_48_961976319.dbf thread=2 sequence=48
archived log file name=+TEST/arch/1_50_961976319.dbf thread=1 sequence=50
archived log file name=+TEST/arch/2_49_961976319.dbf thread=2 sequence=49
archived log file name=+TEST/arch/1_51_961976319.dbf thread=1 sequence=51
archived log file name=+TEST/arch/2_50_961976319.dbf thread=2 sequence=50
archived log file name=+TEST/arch/2_51_961976319.dbf thread=2 sequence=51
media recovery complete, elapsed time: 00:08:44
Finished recover at 2017-12-18 18:58:02

6.执行以下互斥操作
.以读写方式打开CDB,放弃目标SCN之后的所有改变。在这种情况下,你必须将CDB重启到mount状态后,然后执行以下命令

alter database open resetlogs

.使用Data Pump导出CDB中你所需要的对象。然后将CDB恢复到当前时间点并重新导入对象,因此可以将需要的对象进行恢复而不用放弃所有其它对象所发生的改变。

RMAN> alter database open read only;

Statement processed


RMAN> alter pluggable database all open read only;

Statement processed



SQL> conn jy/jy@jypdb
Connected.
SQL> select count(*) from t1;

  COUNT(*)
----------
        39

RMAN> shutdown immediate

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    6442450944 bytes

Fixed Size                     8807168 bytes
Variable Size               1895828736 bytes
Database Buffers            4529848320 bytes
Redo Buffers                   7966720 bytes

RMAN> recover database;

Starting recover at 2017-12-18 22:26:55
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 instance=jy1 device type=DISK

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

Finished recover at 2017-12-18 22:27:05

RMAN> alter database open;

Statement processed
starting full resync of recovery catalog
full resync complete

RMAN> alter pluggable database all open read write;

Statement processed
starting full resync of recovery catalog
full resync complete

使用RMAN对PDB执行闪回数据库操作

可以对多租户数据库中的单个PDB执行闪回操作。对特定的PDB执行闪回数据库操作只会修改与这个PDB相关文件中的数据。CDB中的其它PDB不受影响处于可读写状态。如果使用还原点,在执行闪回数据库操作时可以使用CDB还原点,PDB还原点,PDB清晰还原点或PDB受保证的还原点。对PDB执行闪回数据库操作的步骤如下:
1.使用有sysdba或sysbackup权限的公共用户连接到root容器

SQL> conn / as sysdba
Connected.

2.确保CDB处于open状态

SQL> SELECT open_mode from V$DATABASE;

OPEN_MODE
--------------------
READ WRITE

3.登录PDB(jypdb)记录当前SCN号,然后删除表t1中的数据

SQL> conn jy/jy@jypdb
Connected.
SQL> SELECT CURRENT_SCN   FROM V$DATABASE;

CURRENT_SCN
-----------
    6024220

SQL> select count(*) from t1;

  COUNT(*)
----------
        39

SQL> delete from t1;

39 rows deleted.

SQL> commit;

Commit complete.

SQL> select count(*) from t1;

  COUNT(*)
----------
         0

4.确保要执行闪回数据库的PDB(jypdb)处于close状态。

SQL> conn / as sysdba
Connected.
SQL> alter pluggable database jypdb close immediate;

Pluggable database altered.

SQL> select name,open_mode from v$pdbs;

NAME                                                                                                                             OPEN_MODE
-------------------------------------------------------------------------------------------------------------------------------- ----------
PDB$SEED                                                                                                                         READ ONLY
JYPDB                                                                                                                            MOUNTED
TESTPDB                                                                                                                          READ WRITE

5.将PDB(jypdb)闪回到scn=6024220所在的状态

RMAN> flashback pluggable database jypdb to scn 6024220;

Starting flashback at 18-DEC-17
starting full resync of recovery catalog
full resync complete
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=11 instance=jy1 device type=DISK


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

Finished flashback at 18-DEC-17

6. 将CDB设置为只读状态

RMAN> alter pluggable database jypdb open read only;

Statement processed

7.检查闪回数据库操作的结果是否满足要求

SQL> conn jy/jy@jypdb
Connected.
SQL> select count(*) from t1;

  COUNT(*)
----------
        39

8.如果闪回操作后满足你所要求的结果,那么可以执行以下两个相互排斥的选项:
.使用resetlogs选项将数据库打开。如果当前数据库为只读状态,那么使用SQL*Plus执行以下命令:

alter pluggable database jypdb close immediate;
alter pluggable database jypdb open resetlogs;

.使用Oracle Data Pump导出你所需要的对象,然后使用RMAN来恢复数据库到当前时间,通过对数据库重新应用重做日志中的所有改变来将
数据库恢复到当前时间点从而撤消闪回数据库所做的改变。

RMAN> recover pluggable database jypdb ;

Starting recover at 18-DEC-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=11 instance=jy1 device type=DISK

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

Finished recover at 18-DEC-17

RMAN> alter pluggable database jypdb open read write;

Statement processed
starting full resync of recovery catalog
full resync complete

使用RMAN对CDB执行闪回数据库操作

对CDB执行闪回数据库与对non-CDB执行闪回数据库操作是类似的,具体操作步骤如下:
1.使用SQL*Plus连接到目标数据库来判断闪回操作的的目标SCN,还原点或时间点

SQL> SELECT OLDEST_FLASHBACK_SCN, OLDEST_FLASHBACK_TIME   FROM V$FLASHBACK_DATABASE_LOG;

OLDEST_FLASHBACK_SCN OLDEST_FLASH
-------------------- ------------
             5090113 17-DEC-17



SQL> SELECT CURRENT_SCN   FROM V$DATABASE;

CURRENT_SCN
-----------
    6003920

2.删除表t1中的数据

SQL> select count(*) from t1;

  COUNT(*)
----------
        39

SQL> delete from t1;

39 rows deleted.

SQL> commit;

Commit complete.

3.关闭数据库,并确保没有任何实例打开数据库,然后启动到mount状态

SQL> shutdown  immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 6442450944 bytes
Fixed Size                  8807168 bytes
Variable Size            1895828736 bytes
Database Buffers         4529848320 bytes
Redo Buffers                7966720 bytes
Database mounted.

4.运行flashback database命令将整个CDB闪回到指定的时间点

SQL> flashback database to scn 6003920;

Flashback complete.

5.在SQL*Plus命令窗口中将CDB设置为只读状态

SQL> alter database open read only;

Database altered.

6.如果闪回操作后满足你所要求的结果,那么可以执行以下两个相互排斥的选项:
.使用resetlogs选项将数据库打开。如果当前数据库为只读状态,那么使用SQL*Plus执行以下命令:

shutdown immediate
startup mount
alter database open resetlogs

.使用Oracle Data Pump导出你所需要的对象,然后使用RMAN来恢复数据库到当前时间,通过对数据库重新应用重做日志中的所有改变来将
数据库恢复到当前时间点从而撤消闪回数据库所做的改变。

RMAN> recover database;

Starting recover at 18-DEC-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=11 instance=jy1 device type=DISK

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

Finished recover at 18-DEC-17

Media recovery complete.
SQL> alter database open;

Database altered.

SQL> alter pluggable database all open read write;

Pluggable database altered.

使用RMAN对PDB中的表空间或数据文件执行完全恢复

因为不同PDB中的表空间可以有相同的名字,为了消除这种混淆你必须直接连接到PDB来恢复PDB的表空间。相反,因为数据文件号与路径名是跨CDB唯一标识的,所以可以连接到root容器或PDB来恢复PDB的数据文件。如果连接到CDB的root容器,那么可以使用单个命令来恢复多个PDB中的数据文件。如果连接到PDB,只能恢复PDB中的数据文件。

还原与恢复PDB中的non-SYSTEM表空间
1.启动RMAN并连接到目标数据库

[oracle@jytest1 ~]$ rman target sys/xxxxx@jypdb

Recovery Manager: Release 12.2.0.1.0 - Production on Mon Dec 11 17:59:27 2017

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

connected to target database: JY:JYPDB (DBID=4203494064)

2.如果数据库的状态为open,那么将要恢复的表空间置于脱机状态

SQL> alter tablespace test offline immediate;

Tablespace altered.

3.使用show命令来查看是否配置了预先设置的通道。如果需要的设置类型与通道被配置,那么不需要执行任何操作。否则可以使用configure命令来配置自动通道,或都使用包含allocate channel命令的run块

RMAN> show all;

RMAN configuration parameters for database with db_unique_name JY are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '+test/rman_backup/%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '+test/jy/snapcf_jy.f';

4.还原与恢复表空间
.如果将数据文件还原到原始位置,那么执行restore tablespace与recover tablespace命令

.如果将数据文件还原到新目录,那么在run命令块中执行restore tablespace与recover tablespace命令,并且使用set newname命令来重命名数据文件。

RMAN> restore tablespace 'TEST';

Starting restore at 11-DEC-17
using channel ORA_DISK_1

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 00015 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.275.962210609
channel ORA_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_20171211_0osls830_1_1
channel ORA_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_20171211_0osls830_1_1 tag=TAG20171211T164446
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 11-DEC-17

RMAN> recover tablespace 'TEST';

Starting recover at 11-DEC-17
using channel ORA_DISK_1

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

Finished recover at 11-DEC-17

5.检查输出结果查看是否恢复成功。如果恢复成功将表空间设置为联机状态

RMAN> alter tablespace test online;

Statement processed

还原与恢复PDB中的SYSTEM表空间
1.启动RMAN并使用有sysdba或sysbackup权限的公共用户连接到root容器。

[oracle@jytest1 ~]$ rman target/ catalog rco/xxzx7817600@jypdb_173

Recovery Manager: Release 12.2.0.1.0 - Production on Mon Dec 11 18:11:55 2017

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

connected to target database: JY (DBID=979425723)
connected to recovery catalog database

2.关闭CDB并重启到mount状态

SQL> conn / as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 6442450944 bytes
Fixed Size                  8807168 bytes
Variable Size            1895828736 bytes
Database Buffers         4529848320 bytes
Redo Buffers                7966720 bytes
Database mounted.

3.还原与恢复PDB中SYSTEM表空间的数据文件

[oracle@jytest1 ~]$ rman target/ catalog rco/xxzx7817600@jypdb_173

Recovery Manager: Release 12.2.0.1.0 - Production on Mon Dec 11 18:20:30 2017

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

connected to target database: JY (DBID=979425723, not open)
connected to recovery catalog database

RMAN> report schema;

starting full resync of recovery catalog
full resync complete
Report of database schema for database with db_unique_name JY

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    830      SYSTEM               YES     +DATA/JY/DATAFILE/system.317.962209603
3    1230     SYSAUX               NO      +DATA/JY/DATAFILE/sysaux.298.962209605
4    75       UNDOTBS1             YES     +DATA/JY/DATAFILE/undotbs1.277.962209605
5    250      PDB$SEED:SYSTEM      NO      +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/system.256.962209675
6    340      PDB$SEED:SYSAUX      NO      +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.270.962209675
7    5        USERS                NO      +DATA/JY/DATAFILE/users.301.962209605
8    100      PDB$SEED:UNDOTBS1    NO      +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.296.962209675
9    50       UNDOTBS2             YES     +DATA/JY/DATAFILE/undotbs2.312.962209605
10   260      JYPDB:SYSTEM         YES     +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.271.962209649
11   460      JYPDB:SYSAUX         NO      +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.316.962209649
12   100      JYPDB:UNDOTBS1       YES     +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.264.962209649
13   100      JYPDB:UNDO_2         YES     +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.268.962209649
14   5        JYPDB:USERS          NO      +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.278.962209649
15   100      JYPDB:TEST           NO      +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.275.962210609
16   260      TESTPDB:SYSTEM       YES     +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/system.260.962469409
17   460      TESTPDB:SYSAUX       NO      +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.259.962469409
18   100      TESTPDB:UNDOTBS1     YES     +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.265.962469409
19   100      TESTPDB:UNDO_2       YES     +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.266.962469409
20   5        TESTPDB:USERS        NO      +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.267.962469409
21   100      TESTPDB:TEST         NO      +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.269.962469409

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    142      TEMP                 32767       +DATA/JY/TEMPFILE/temp.299.961976339
2    64       PDB$SEED:TEMP        32767       +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/TEMPFILE/temp.297.962209865
3    135      JYPDB:TEMP           32767       +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/TEMPFILE/temp.276.962210519
4    135      TESTPDB:TEMP         32767       +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/TEMPFILE/temp.258.962469435

RMAN> restore tablespace 'JYPDB:SYSTEM';

Starting restore at 11-DEC-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 instance=jy1 device type=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 12/11/2017 18:21:09
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20202: Tablespace not found in the recovery catalog
RMAN-06019: could not translate tablespace name "JYPDB:SYSTEM"

这里在还原SYSTEM表空间时使用表空间名时会报错,如是使用restore datafile与recover datafile方法来还原与恢复SYSTEM表空间

RMAN> restore datafile 10;

Starting restore at 11-DEC-17
using channel ORA_DISK_1

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 00010 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.271.962209649
channel ORA_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_20171211_0osls830_1_1
channel ORA_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_20171211_0osls830_1_1 tag=TAG20171211T164446
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 11-DEC-17

RMAN> recover datafile 10;

Starting recover at 11-DEC-17
using channel ORA_DISK_1

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

Finished recover at 11-DEC-17

4.打开CDB中的所有PDB

RMAN> alter database open;

Statement processed
starting full resync of recovery catalog
full resync complete

RMAN> alter pluggable database all open read write;

Statement processed
starting full resync of recovery catalog
full resync complete

使用RMAN来PDB执行完全恢复

可以对一个或多个PDB执行完全恢复而不影响其它为open状态的PDB的操作。RMAN有两种方法来恢复PDB:
.连接到CDB的root容器,然后使用restore pluggable database与recover pluggable database命令。这种方法能让你使用单个命令来恢复多个PDB。

.连接到PDB并使用restore database与recover database语句,这种方法只能恢复单个PDB并且能让你使用相同的命令来恢复non-CDB数据库

使用RMAN恢复一个或多个PDB
1.启动RMAN并使用有sysdba或sysbackup权限的公共用户连接到root容器

[oracle@jytest1 ~]$ rman target/ catalog rco/xxxxx@jypdb 

Recovery Manager: Release 12.2.0.1.0 - Production on Mon Dec 11 16:56:58 2017

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

connected to target database: JY (DBID=979425723)
connected to recovery catalog database

2.关闭你要执行恢复操作的PDB

SQL> alter pluggable database jypdb,testpdb close immediate;

Pluggable database altered.


SQL> select name,open_mode from v$pdbs;

NAME                                                                                                                             OPEN_MODE
-------------------------------------------------------------------------------------------------------------------------------- ----------
PDB$SEED                                                                                                                         READ ONLY
JYPDB                                                                                                                            MOUNTED
TESTPDB                                                                                                                          MOUNTED

SQL> 

3.可选操作,使用configure命令来配置缺省设备类型与自动通道

4.执行restore pluggable database与recover pluggable database命令,下面的语句恢复 jypdb,testpdb

RMAN> restore pluggable database  jypdb,testpdb;

Starting restore at 11-DEC-17
starting full resync of recovery catalog
full resync complete
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=2279 instance=jy1 device type=DISK

skipping datafile 5; already restored to file +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/system.256.962209675
skipping datafile 6; already restored to file +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.270.962209675
skipping datafile 8; already restored to file +DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.296.962209675
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 00010 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.271.962209649
channel ORA_DISK_1: restoring datafile 00011 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.316.962209649
channel ORA_DISK_1: restoring datafile 00012 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.264.962209649
channel ORA_DISK_1: restoring datafile 00013 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.268.962209649
channel ORA_DISK_1: restoring datafile 00014 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.278.962209649
channel ORA_DISK_1: restoring datafile 00015 to +DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.275.962210609
channel ORA_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_20171211_0osls830_1_1
channel ORA_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_20171211_0osls830_1_1 tag=TAG20171211T164446
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
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 00016 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/system.260.962469409
channel ORA_DISK_1: restoring datafile 00017 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.259.962469409
channel ORA_DISK_1: restoring datafile 00018 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.265.962469409
channel ORA_DISK_1: restoring datafile 00019 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.266.962469409
channel ORA_DISK_1: restoring datafile 00020 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.267.962469409
channel ORA_DISK_1: restoring datafile 00021 to +DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.269.962469409
channel ORA_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_20171211_0psls843_1_1
channel ORA_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_20171211_0psls843_1_1 tag=TAG20171211T164446
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:36
Finished restore at 11-DEC-17


RMAN> recover pluggable database jypdb,testpdb;

Starting recover at 11-DEC-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=2279 instance=jy1 device type=DISK

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

Finished recover at 11-DEC-17

5.open PDB(jypdb,testpdb)

SQL> alter pluggable database jypdb,testpdb open;

Pluggable database altered.

SQL> select name,open_mode from v$pdbs;

NAME                                                                                                                             OPEN_MODE
-------------------------------------------------------------------------------------------------------------------------------- ----------
PDB$SEED                                                                                                                         READ ONLY
JYPDB                                                                                                                            READ WRITE
TESTPDB                                                                                                                          READ WRITE