Oracle 12C使用RMAN将PDB中分表的多个分区恢复到新用户方案中

Oracle 12C使用RMAN将PDB中分表的多个分区恢复到新用户方案中的操作如下
1.对整个CDB(jy)生成RMAN备份

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

Recovery Manager: Release 12.2.0.1.0 - Production on Thu Jan 11 00:43:42 2018

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

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

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


Starting backup at 2018-01-11 00:43:49
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=393 instance=jy1 device type=DISK
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=2 sequence=70 RECID=184 STAMP=965090640
input archived log thread=1 sequence=95 RECID=183 STAMP=965090635
channel ORA_DISK_1: starting piece 1 at 2018-01-11 00:44:03
channel ORA_DISK_1: finished piece 1 at 2018-01-11 00:44:18
piece handle=+TEST/rman_backup/arc_jy_20180111_18soc7aj_1_1 tag=TAG20180111T004402 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 2018-01-11 00:44:18

Starting backup at 2018-01-11 00:44: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=00003 name=+DATA/JY/DATAFILE/sysaux.298.962209605
input datafile file number=00001 name=+DATA/JY/DATAFILE/system.317.962209603
input datafile file number=00004 name=+DATA/JY/DATAFILE/undotbs1.277.962209605
input datafile file number=00009 name=+DATA/JY/DATAFILE/undotbs2.312.962209605
input datafile file number=00007 name=+DATA/JY/DATAFILE/users.301.962209605
channel ORA_DISK_1: starting piece 1 at 2018-01-11 00:44:20
channel ORA_DISK_1: finished piece 1 at 2018-01-11 00:46:05
piece handle=+TEST/rman_backup/jy_979425723_19soc7b4_1_1_965090660 tag=TAG20180111T004418 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:45
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00014 name=+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/users.278.962209649
input datafile file number=00011 name=+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/sysaux.316.962209649
input datafile file number=00010 name=+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/system.271.962209649
input datafile file number=00012 name=+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undotbs1.264.962209649
input datafile file number=00013 name=+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/undo_2.268.962209649
input datafile file number=00015 name=+DATA/JY/5F9AC6865E87549FE053AB828A0ADE94/DATAFILE/test.275.962210609
channel ORA_DISK_1: starting piece 1 at 2018-01-11 00:46:06
channel ORA_DISK_1: finished piece 1 at 2018-01-11 00:47:01
piece handle=+TEST/rman_backup/jy_979425723_1asoc7ee_1_1_965090766 tag=TAG20180111T004418 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00017 name=+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/sysaux.259.962469409
input datafile file number=00016 name=+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/system.260.962469409
input datafile file number=00018 name=+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undotbs1.265.962469409
input datafile file number=00019 name=+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/undo_2.266.962469409
input datafile file number=00021 name=+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/test.269.962469409
input datafile file number=00020 name=+DATA/JY/600D6F56DEB669CCE053AB828A0AAB7E/DATAFILE/users.267.962469409
channel ORA_DISK_1: starting piece 1 at 2018-01-11 00:47:01
channel ORA_DISK_1: finished piece 1 at 2018-01-11 00:47:46
piece handle=+TEST/rman_backup/jy_979425723_1bsoc7g5_1_1_965090821 tag=TAG20180111T004418 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/sysaux.270.962209675
input datafile file number=00005 name=+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/system.256.962209675
input datafile file number=00008 name=+DATA/JY/5F9AA264B21F3ED9E053AB828A0A6088/DATAFILE/undotbs1.296.962209675
channel ORA_DISK_1: starting piece 1 at 2018-01-11 00:47:47
channel ORA_DISK_1: finished piece 1 at 2018-01-11 00:48:32
piece handle=+TEST/rman_backup/jy_979425723_1csoc7hj_1_1_965090867 tag=TAG20180111T004418 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 2018-01-11 00:48:32

Starting backup at 2018-01-11 00:48:32
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=96 RECID=185 STAMP=965090913
input archived log thread=2 sequence=71 RECID=186 STAMP=965090913
channel ORA_DISK_1: starting piece 1 at 2018-01-11 00:48:37
channel ORA_DISK_1: finished piece 1 at 2018-01-11 00:48:38
piece handle=+TEST/rman_backup/arc_jy_20180111_1dsoc7j5_1_1 tag=TAG20180111T004835 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2018-01-11 00:48:38

Starting Control File and SPFILE Autobackup at 2018-01-11 00:48:38
piece handle=+TEST/rman_backup/c-979425723-20180111-00 comment=NONE
Finished Control File and SPFILE Autobackup at 2018-01-11 00:48:46

2.在删除表sh.sales的SALES_Q3_1998与SALES_Q4_1998分区中的数据之前记录当前时间,在执行恢复时它们被用来指定恢复时间点

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

Session altered.

SQL> select count(*) from sales partition(SALES_Q3_1998);

  COUNT(*)
----------
     50515

SQL> select count(*) from sales partition(SALES_Q4_1998);

  COUNT(*)
----------
     48874

SQL> select sysdate from dual;

SYSDATE
-------------------
2018-01-11 01:03:47

SQL> select current_scn   from v$database;

CURRENT_SCN
-----------
    8629695

SQL> delete from sales partition(SALES_Q3_1998);

50515 rows deleted.

SQL> delete from sales partition(SALES_Q4_1998);

48874 rows deleted.

SQL> commit;

Commit complete.

SQL> select count(*) from sales partition(SALES_Q3_1998);

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

SQL> select count(*) from sales partition(SALES_Q4_1998);

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

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

[oracle@jytest1 ~]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@jytest1 ~]$ rman target/ catalog rco/abcd@jypdb_173

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子句(/run/recover辅助数据文件存储目录)与until scn来指定恢复时间点,并且在recover命令中使用子句dump file与datapump destination,指定包含被恢复表或表分区的导出dump文件的文件名(t_emp_recvr.dmp)与存储位置(/run/dump)。 使用remap table子句将分区SH.SALES:SALES_Q3_1998恢复成表JY.SALES_Q3_1998,分区 SH.SALES:SALES_Q4_1998恢复成表JY.SALES_Q4_1998使用remap tablespace子句将sh用户方案中的表分区从表空间users恢复到表空间test中

RMAN> run
2> {
3> recover table SH.SALES:SALES_Q3_1998, SH.SALES:SALES_Q4_1998 of pluggable database jypdb
4> until time '2018-01-11 01:03:47'
5> auxiliary destination '/run/recover'
6> datapump destination '/run/dump'
7> dump file 't_emp_recvr.dmp'
8> remap table SH.SALES:SALES_Q3_1998:JY.SALES_Q3_1998,SH.SALES:SALES_Q4_1998:JY.SALES_Q4_1998
9> remap tablespace 'USERS':'TEST';
10> }

Starting recover at 2018-01-11 01:46:51
using channel ORA_DISK_1

Creating automatic instance, with SID='lCEx'

initialization parameters used for automatic instance:
db_name=JY
db_unique_name=lCEx_pitr_jypdb_JY
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=2048M
processes=200
db_create_file_dest=/run/recover
log_archive_dest_1='location=/run/recover'
enable_pluggable_database=true
_clone_one_pdb_recovery=true
#No auxiliary parameter file used


starting up automatic instance JY

Oracle instance started

Total System Global Area    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size                553651488 bytes
Database Buffers            1577058304 bytes
Redo Buffers                   7979008 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-11 01:03:47";
# 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';
# resync catalog
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 2018-01-11 01:47:37
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=211 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 +TEST/rman_backup/c-979425723-20180111-00
channel ORA_AUX_DISK_1: piece handle=+TEST/rman_backup/c-979425723-20180111-00 tag=TAG20180111T004839
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:05
output file name=/run/recover/JY/controlfile/o1_mf_f5dnfy2z_.ctl
Finished restore at 2018-01-11 01:47:43

sql statement: alter database mount clone database

sql statement: alter system archive log current

starting full resync of recovery catalog
full resync complete

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

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

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /run/recover/JY/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 2018-01-11 01:47:55
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 /run/recover/JY/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /run/recover/JY/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00009 to /run/recover/JY/datafile/o1_mf_undotbs2_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /run/recover/JY/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_19soc7b4_1_1_965090660
channel ORA_AUX_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_19soc7b4_1_1_965090660 tag=TAG20180111T004418
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:55
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 00010 to /run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00012 to /run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00013 to /run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_undo_2_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00011 to /run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_1asoc7ee_1_1_965090766
channel ORA_AUX_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_1asoc7ee_1_1_965090766 tag=TAG20180111T004418
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-11 01:50:35

datafile 10 switched to datafile copy
input datafile copy RECID=12 STAMP=965094635 file name=/run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_system_f5dnkync_.dbf
datafile 1 switched to datafile copy
input datafile copy RECID=13 STAMP=965094635 file name=/run/recover/JY/datafile/o1_mf_system_f5dngcjj_.dbf
datafile 12 switched to datafile copy
input datafile copy RECID=14 STAMP=965094635 file name=/run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_undotbs1_f5dnkynd_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=15 STAMP=965094635 file name=/run/recover/JY/datafile/o1_mf_undotbs1_f5dngcjk_.dbf
datafile 13 switched to datafile copy
input datafile copy RECID=16 STAMP=965094635 file name=/run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_undo_2_f5dnkynd_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=17 STAMP=965094635 file name=/run/recover/JY/datafile/o1_mf_undotbs2_f5dngcjl_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=18 STAMP=965094635 file name=/run/recover/JY/datafile/o1_mf_sysaux_f5dngcjh_.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=19 STAMP=965094635 file name=/run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_sysaux_f5dnkynb_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-11 01:03:47";
# online the datafiles restored or switched
sql clone 'JYPDB' "alter database datafile
 10 online";
sql clone "alter database datafile  1 online";
sql clone 'JYPDB' "alter database datafile
 12 online";
sql clone "alter database datafile  4 online";
sql clone 'JYPDB' "alter database datafile
 13 online";
sql clone "alter database datafile  9 online";
sql clone "alter database datafile  3 online";
sql clone 'JYPDB' "alter database datafile
 11 online";
# recover and open database read only
recover clone database tablespace  "JYPDB":"SYSTEM", "SYSTEM", "JYPDB":"UNDOTBS1", "UNDOTBS1", "JYPDB":"UNDO_2", "UNDOTBS2", "SYSAUX", "JYPDB":"SYSAUX";
sql clone 'alter database open read only';
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  10 online

sql statement: alter database datafile  1 online

sql statement: alter database datafile  12 online

sql statement: alter database datafile  4 online

sql statement: alter database datafile  13 online

sql statement: alter database datafile  9 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  11 online

Starting recover at 2018-01-11 01:50:36
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 96 is already on disk as file +TEST/arch/1_96_961976319.dbf
archived log for thread 1 with sequence 97 is already on disk as file +TEST/arch/1_97_961976319.dbf
archived log for thread 2 with sequence 71 is already on disk as file +TEST/arch/2_71_961976319.dbf
archived log for thread 2 with sequence 72 is already on disk as file +TEST/arch/2_72_961976319.dbf
archived log file name=+TEST/arch/1_96_961976319.dbf thread=1 sequence=96
archived log file name=+TEST/arch/2_71_961976319.dbf thread=2 sequence=71
archived log file name=+TEST/arch/1_97_961976319.dbf thread=1 sequence=97
archived log file name=+TEST/arch/2_72_961976319.dbf thread=2 sequence=72
media recovery complete, elapsed time: 00:00:01
Finished recover at 2018-01-11 01:50:39

sql statement: alter database open read only

contents of Memory Script:
{
sql clone 'alter pluggable database  JYPDB open read only';
}
executing Memory Script

sql statement: alter pluggable database  JYPDB 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 =
  ''/run/recover/JY/controlfile/o1_mf_f5dnfy2z_.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    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size                553651488 bytes
Database Buffers            1577058304 bytes
Redo Buffers                   7979008 bytes

sql statement: alter system set  control_files =   ''/run/recover/JY/controlfile/o1_mf_f5dnfy2z_.ctl'' comment= ''RMAN set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    2147483648 bytes

Fixed Size                     8794848 bytes
Variable Size                553651488 bytes
Database Buffers            1577058304 bytes
Redo Buffers                   7979008 bytes

sql statement: alter database mount clone database

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

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

Starting restore at 2018-01-11 01:51:49
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=211 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 00014 to /run/recover/LCEX_PITR_JYPDB_JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +TEST/rman_backup/jy_979425723_1asoc7ee_1_1_965090766
channel ORA_AUX_DISK_1: piece handle=+TEST/rman_backup/jy_979425723_1asoc7ee_1_1_965090766 tag=TAG20180111T004418
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:49
Finished restore at 2018-01-11 01:52:39

datafile 14 switched to datafile copy
input datafile copy RECID=21 STAMP=965094759 file name=/run/recover/LCEX_PITR_JYPDB_JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_users_f5dnot2n_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-11 01:03:47";
# online the datafiles restored or switched
sql clone 'JYPDB' "alter database datafile
 14 online";
# recover and open resetlogs
recover clone database tablespace  "JYPDB":"USERS", "JYPDB":"SYSTEM", "SYSTEM", "JYPDB":"UNDOTBS1", "UNDOTBS1", "JYPDB":"UNDO_2", "UNDOTBS2", "SYSAUX", "JYPDB":"SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  14 online

Starting recover at 2018-01-11 01:52:39
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 96 is already on disk as file +TEST/arch/1_96_961976319.dbf
archived log for thread 1 with sequence 97 is already on disk as file +TEST/arch/1_97_961976319.dbf
archived log for thread 2 with sequence 71 is already on disk as file +TEST/arch/2_71_961976319.dbf
archived log for thread 2 with sequence 72 is already on disk as file +TEST/arch/2_72_961976319.dbf
archived log file name=+TEST/arch/1_96_961976319.dbf thread=1 sequence=96
archived log file name=+TEST/arch/2_71_961976319.dbf thread=2 sequence=71
archived log file name=+TEST/arch/1_97_961976319.dbf thread=1 sequence=97
archived log file name=+TEST/arch/2_72_961976319.dbf thread=2 sequence=72
media recovery complete, elapsed time: 00:00:01
Finished recover at 2018-01-11 01:52:42

database opened

contents of Memory Script:
{
sql clone 'alter pluggable database  JYPDB open';
}
executing Memory Script

sql statement: alter pluggable database  JYPDB open

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

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

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

Performing export of tables...
   EXPDP> Starting "SYS"."TSPITR_EXP_lCEx_rDzp":
   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> Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
   EXPDP> Processing object type TABLE_EXPORT/TABLE/COMMENT
   EXPDP> . . exported "SH"."SALES":"SALES_Q3_1998"                1.634 MB   50515 rows
   EXPDP> . . exported "SH"."SALES":"SALES_Q4_1998"                1.581 MB   48874 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_lCEx_rDzp" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_lCEx_rDzp is:
   EXPDP>   /run/dump/t_emp_recvr.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_lCEx_rDzp" successfully completed at Thu Jan 11 01:53:35 2018 elapsed 0 00:00:41
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_lCEx_pFDE" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_lCEx_pFDE":
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "JY"."SALES_Q3_1998"                        1.634 MB   50515 rows
   IMPDP> . . imported "JY"."SALES_Q4_1998"                        1.581 MB   48874 rows
   IMPDP> Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
   IMPDP> ORA-39083: Object type OBJECT_GRANT failed to create with error:
ORA-00942: table or view does not exist

Failing sql is:
GRANT SELECT ON "JY"."SALES" TO "BI"

   IMPDP> Processing object type TABLE_EXPORT/TABLE/COMMENT
   IMPDP> ORA-39083: Object type COMMENT failed to create with error:
ORA-00942: table or view does not exist

Failing sql is:
 COMMENT ON TABLE "JY"."SALES"  IS 'facts table, without a primary key; all rows are uniquely identified by the combination of all foreign keys'

ORA-39083: Object type COMMENT:"PROD_ID" failed to create with error:
ORA-00942: table or view does not exist

Failing sql is:
 COMMENT ON COLUMN "JY"."SALES"."PROD_ID" IS 'FK to the products dimension table'

ORA-39083: Object type COMMENT:"CUST_ID" failed to create with error:
ORA-00942: table or view does not exist

Failing sql is:
 COMMENT ON COLUMN "JY"."SALES"."CUST_ID" IS 'FK to the customers dimension table'

ORA-39083: Object type COMMENT:"TIME_ID" failed to create with error:
ORA-00942: table or view does not exist

Failing sql is:
 COMMENT ON COLUMN "JY"."SALES"."TIME_ID" IS 'FK to the times dimension table'

ORA-39083: Object type COMMENT:"CHANNEL_ID" failed to create with error:
ORA-00942: table or view does not exist

Failing sql is:
 COMMENT ON COLUMN "JY"."SALES"."CHANNEL_ID" IS 'FK to the channels dimension table'

ORA-39083: Object type COMMENT:"PROMO_ID" failed to create with error:
ORA-00942: table or view does not exist

Failing sql is:
 COMMENT ON COLUMN "JY"."SALES"."PROMO_ID" IS 'promotion identifier, without FK constraint (intentionally) to show outer join optimization'

ORA-39083: Object type COMMENT:"QUANTITY_SOLD" failed to create with error:
ORA-00942: table or view does not exist

Failing sql is:
 COMMENT ON COLUMN "JY"."SALES"."QUANTITY_SOLD" IS 'product quantity sold with the transaction'

ORA-39083: Object type COMMENT:"AMOUNT_SOLD" failed to create with error:
ORA-00942: table or view does not exist

Failing sql is:
 COMMENT ON COLUMN "JY"."SALES"."AMOUNT_SOLD" IS 'invoiced amount to the customer'

   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   IMPDP> Job "SYS"."TSPITR_IMP_lCEx_pFDE" completed with 9 error(s) at Thu Jan 11 01:55:38 2018 elapsed 0 00:01:38
import completed with errors; Oracle Data Pump dump file t_emp_recvr.dmp is retained

Removing automatic instance
Automatic instance removed
auxiliary instance file /run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_temp_f5dnmkjx_.tmp deleted
auxiliary instance file /run/recover/JY/datafile/o1_mf_temp_f5dnmj7f_.tmp deleted
auxiliary instance file /run/recover/LCEX_PITR_JYPDB_JY/onlinelog/o1_mf_4_f5dnqbjt_.log deleted
auxiliary instance file /run/recover/LCEX_PITR_JYPDB_JY/onlinelog/o1_mf_3_f5dnqbhs_.log deleted
auxiliary instance file /run/recover/LCEX_PITR_JYPDB_JY/onlinelog/o1_mf_2_f5dnqbh8_.log deleted
auxiliary instance file /run/recover/LCEX_PITR_JYPDB_JY/onlinelog/o1_mf_1_f5dnqbgj_.log deleted
auxiliary instance file /run/recover/LCEX_PITR_JYPDB_JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_users_f5dnot2n_.dbf deleted
auxiliary instance file /run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_sysaux_f5dnkynb_.dbf deleted
auxiliary instance file /run/recover/JY/datafile/o1_mf_sysaux_f5dngcjh_.dbf deleted
auxiliary instance file /run/recover/JY/datafile/o1_mf_undotbs2_f5dngcjl_.dbf deleted
auxiliary instance file /run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_undo_2_f5dnkynd_.dbf deleted
auxiliary instance file /run/recover/JY/datafile/o1_mf_undotbs1_f5dngcjk_.dbf deleted
auxiliary instance file /run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_undotbs1_f5dnkynd_.dbf deleted
auxiliary instance file /run/recover/JY/datafile/o1_mf_system_f5dngcjj_.dbf deleted
auxiliary instance file /run/recover/JY/5F9AC6865E87549FE053AB828A0ADE94/datafile/o1_mf_system_f5dnkync_.dbf deleted
auxiliary instance file /run/recover/JY/controlfile/o1_mf_f5dnfy2z_.ctl deleted
Finished recover at 2018-01-11 01:55:46
starting full resync of recovery catalog
full resync complete
5.验证是否分区SH.SALES:SALES_Q3_1998被恢复成表JY.SALES_Q3_1998,分区SH.SALES:SALES_Q4_1998被恢复成表JY.SALES_Q4_1998,从查询记录可以看到已经成功恢复
SQL> select count(*) from JY.SALES_Q3_1998;

  COUNT(*)
----------
     50515

SQL> select count(*) from JY.SALES_Q4_1998;

  COUNT(*)
----------
     48874

Oracle 12C使用RMAN将Non-CDB中分表的多个分区恢复到新用户方案中

Oracle 12C使用RMAN将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.在删除表sh.sales的SALES_Q3_1998与SALES_Q4_1998分区中的数据之前记录当前时间,在执行恢复时它们被用来指定恢复时间点

SQL> select count(*) from sales partition(SALES_Q3_1998);

  COUNT(*)
----------
     50515

1 row selected.

SQL> select count(*) from sales partition(SALES_Q4_1998);

  COUNT(*)
----------
     48874

1 row selected.

SQL> select sysdate from dual;

SYSDATE
-------------------
2018-01-11 03:11:06

1 row selected.

SQL> select current_scn   from v$database;

CURRENT_SCN
-----------
     525382

SQL> delete from sales partition(SALES_Q3_1998);

50515 rows deleted.

SQL> delete from sales partition(SALES_Q4_1998);

48874 rows deleted.

SQL> commit;

Commit complete.

SQL> select count(*) from sales partition(SALES_Q3_1998);

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

1 row selected.

SQL> select count(*) from sales partition(SALES_Q4_1998);

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

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子句将分区SH.SALES:SALES_Q3_1998恢复成表 JY.SALES_Q3_1998,分区SH.SALES:SALES_Q4_1998恢复成表JY.SALES_Q4_1998使用remap tablespace子句将sh用户方案中的表分区从user表空间恢复到usertbs表空间中

RMAN> run
{
2> 3> recover table SH.SALES:SALES_Q3_1998, SH.SALES:SALES_Q4_1998
4> until time '2018-01-11 03:11:06'
5> auxiliary destination '/ora_xtts/recover'
6> datapump destination '/ora_xtts/dump'
7> dump file 't_emp_recvr.dmp'
8> remap table SH.SALES:SALES_Q3_1998:JY.SALES_Q3_1998,SH.SALES:SALES_Q4_1998:JY.SALES_Q4_1998
9> remap tablespace 'USERS':'USERTBS';
10> }

Starting recover at 2018-01-11 03:21:12
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='xDyx'

initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=xDyx_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-11 03:11:06";
# 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-11 03:22:20
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:05
output file name=/ora_xtts/recover/ORCL/controlfile/o1_mf_f5dszl5f_.ctl
Finished restore at 2018-01-11 03:22:27

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-11 03:11:06";
# 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-11 03:22:34
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-11 03:23:20

datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=965100201 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_system_f5dszvs1_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=965100201 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5dszvt5_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=965100201 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5dszvsm_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-11 03:11:06";
# 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-11 03:23:22
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 for thread 1 with sequence 26 is already on disk as file +DATA/arch/orcl/1_26_964992135.dbf
archived log for thread 1 with sequence 27 is already on disk as file +DATA/arch/orcl/1_27_964992135.dbf
archived log for thread 1 with sequence 28 is already on disk as file +DATA/arch/orcl/1_28_964992135.dbf
archived log for thread 1 with sequence 29 is already on disk as file +DATA/arch/orcl/1_29_964992135.dbf
archived log for thread 1 with sequence 30 is already on disk as file +DATA/arch/orcl/1_30_964992135.dbf
archived log for thread 1 with sequence 31 is already on disk as file +DATA/arch/orcl/1_31_964992135.dbf
archived log for thread 1 with sequence 32 is already on disk as file +DATA/arch/orcl/1_32_964992135.dbf
archived log for thread 1 with sequence 33 is already on disk as file +DATA/arch/orcl/1_33_964992135.dbf
archived log for thread 1 with sequence 34 is already on disk as file +DATA/arch/orcl/1_34_964992135.dbf
archived log for thread 1 with sequence 35 is already on disk as file +DATA/arch/orcl/1_35_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
archived log file name=+DATA/arch/orcl/1_26_964992135.dbf thread=1 sequence=26
archived log file name=+DATA/arch/orcl/1_27_964992135.dbf thread=1 sequence=27
archived log file name=+DATA/arch/orcl/1_28_964992135.dbf thread=1 sequence=28
archived log file name=+DATA/arch/orcl/1_29_964992135.dbf thread=1 sequence=29
archived log file name=+DATA/arch/orcl/1_30_964992135.dbf thread=1 sequence=30
archived log file name=+DATA/arch/orcl/1_31_964992135.dbf thread=1 sequence=31
archived log file name=+DATA/arch/orcl/1_32_964992135.dbf thread=1 sequence=32
archived log file name=+DATA/arch/orcl/1_33_964992135.dbf thread=1 sequence=33
archived log file name=+DATA/arch/orcl/1_34_964992135.dbf thread=1 sequence=34
archived log file name=+DATA/arch/orcl/1_35_964992135.dbf thread=1 sequence=35
media recovery complete, elapsed time: 00:00:51
Finished recover at 2018-01-11 03:24:16

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_f5dszl5f_.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_f5dszl5f_.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-11 03:11:06";
# 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-11 03:25:26
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/XDYX_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-11 03:26:22

datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=965100383 file name=/ora_xtts/recover/XDYX_PITR_ORCL/datafile/o1_mf_users_f5dt57w8_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-11 03:11:06";
# 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-11 03:26:23
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 for thread 1 with sequence 26 is already on disk as file +DATA/arch/orcl/1_26_964992135.dbf
archived log for thread 1 with sequence 27 is already on disk as file +DATA/arch/orcl/1_27_964992135.dbf
archived log for thread 1 with sequence 28 is already on disk as file +DATA/arch/orcl/1_28_964992135.dbf
archived log for thread 1 with sequence 29 is already on disk as file +DATA/arch/orcl/1_29_964992135.dbf
archived log for thread 1 with sequence 30 is already on disk as file +DATA/arch/orcl/1_30_964992135.dbf
archived log for thread 1 with sequence 31 is already on disk as file +DATA/arch/orcl/1_31_964992135.dbf
archived log for thread 1 with sequence 32 is already on disk as file +DATA/arch/orcl/1_32_964992135.dbf
archived log for thread 1 with sequence 33 is already on disk as file +DATA/arch/orcl/1_33_964992135.dbf
archived log for thread 1 with sequence 34 is already on disk as file +DATA/arch/orcl/1_34_964992135.dbf
archived log for thread 1 with sequence 35 is already on disk as file +DATA/arch/orcl/1_35_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
archived log file name=+DATA/arch/orcl/1_26_964992135.dbf thread=1 sequence=26
archived log file name=+DATA/arch/orcl/1_27_964992135.dbf thread=1 sequence=27
archived log file name=+DATA/arch/orcl/1_28_964992135.dbf thread=1 sequence=28
archived log file name=+DATA/arch/orcl/1_29_964992135.dbf thread=1 sequence=29
archived log file name=+DATA/arch/orcl/1_30_964992135.dbf thread=1 sequence=30
archived log file name=+DATA/arch/orcl/1_31_964992135.dbf thread=1 sequence=31
archived log file name=+DATA/arch/orcl/1_32_964992135.dbf thread=1 sequence=32
archived log file name=+DATA/arch/orcl/1_33_964992135.dbf thread=1 sequence=33
archived log file name=+DATA/arch/orcl/1_34_964992135.dbf thread=1 sequence=34
archived log file name=+DATA/arch/orcl/1_35_964992135.dbf thread=1 sequence=35
media recovery complete, elapsed time: 00:00:08
Finished recover at 2018-01-11 03:26:34

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_xDyx_nniA":
   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> Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
   EXPDP> Processing object type TABLE_EXPORT/TABLE/COMMENT
   EXPDP> . . exported "SH"."SALES":"SALES_Q3_1998"                1.634 MB   50515 rows
   EXPDP> . . exported "SH"."SALES":"SALES_Q4_1998"                1.581 MB   48874 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_xDyx_nniA" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_xDyx_nniA is:
   EXPDP>   /ora_xtts/dump/t_emp_recvr.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_xDyx_nniA" successfully completed at Thu Jan 11 03:27:33 2018 elapsed 0 00:00:39
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_xDyx_xeDs" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_xDyx_xeDs":
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "JY"."SALES_Q3_1998"                        1.634 MB   50515 rows
   IMPDP> . . imported "JY"."SALES_Q4_1998"                        1.581 MB   48874 rows
   IMPDP> Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   IMPDP> Job "SYS"."TSPITR_IMP_xDyx_xeDs" completed with 9 error(s) at Thu Jan 11 03:28:18 2018 elapsed 0 00:00:36
import completed with errors; Oracle Data Pump dump file t_emp_recvr.dmp is retained

Removing automatic instance
Automatic instance removed
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_f5dt3146_.tmp deleted
auxiliary instance file /ora_xtts/recover/XDYX_PITR_ORCL/onlinelog/o1_mf_3_f5dt7brh_.log deleted
auxiliary instance file /ora_xtts/recover/XDYX_PITR_ORCL/onlinelog/o1_mf_2_f5dt7bqr_.log deleted
auxiliary instance file /ora_xtts/recover/XDYX_PITR_ORCL/onlinelog/o1_mf_1_f5dt7bq5_.log deleted
auxiliary instance file /ora_xtts/recover/XDYX_PITR_ORCL/datafile/o1_mf_users_f5dt57w8_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5dszvsm_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5dszvt5_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_system_f5dszvs1_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/controlfile/o1_mf_f5dszl5f_.ctl deleted
Finished recover at 2018-01-11 03:28:22

5.验证是否分区SH.SALES:SALES_Q3_1998被恢复成表JY.SALES_Q3_1998,分区SH.SALES:SALES_Q4_1998被恢复成表JY.SALES_Q4_1998,从查询记录可以看到已经成功恢复

SQL> select count(*) from JY.SALES_Q3_1998;

  COUNT(*)
----------
     50515

SQL> select count(*) from JY.SALES_Q4_1998;

  COUNT(*)
----------
     48874

Oracle 12C使用RMAN将Non-CDB中多个用户方案中的多个表或表分区恢复到新用户方案中

Oracle 12C使用RMAN将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之前记录当前时间,在执行恢复时它们被用来指定恢复时间点

SQL> select count(*) from cs.t1;

  COUNT(*)
----------
         8

SQL> select count(*) from hr.t1;

  COUNT(*)
----------
         8

1 row selected.

SQL> select sysdate from dual;

SYSDATE
-------------------
2018-01-10 22:56:16

1 row selected.

SQL> truncate table cs.t1;

Table truncated.

SQL> truncate table hr.t1;

Table truncated.

SQL> select count(*) from cs.t1;

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

SQL> select count(*) from hr.t1;

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

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.t1恢复成jy.t1_1,cs.t1恢复成jy.t1_2。使用remap tablespace子句将hr与cs用户方案中的表t1从表空间users恢复到表空间usertbs中

RMAN> run
2> {
3> recover table hr.t1,cs.t1
4> until time '2018-01-10 22:55:39'
5> auxiliary destination '/ora_xtts/recover'
6> datapump destination '/ora_xtts/dump'
7> dump file 't_emp_recvr.dmp'
8> remap table 'HR'.'T1':'JY'.'T1_1','CS'.'T1':'JY'.'T1_2'
9> remap tablespace 'USERS':'USERTBS';
10> }

Starting recover at 2018-01-10 23:26:43
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='fvtm'

initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=fvtm_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 22:55:39";
# 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 23:27:59
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:05
output file name=/ora_xtts/recover/ORCL/controlfile/o1_mf_f5dd84jp_.ctl
Finished restore at 2018-01-10 23:28:05

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 22:55:39";
# 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 23:28:15
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 23:29:02

datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=965086142 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_system_f5dd8k64_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=965086142 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5dd8k8j_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=965086142 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5dd8k7d_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-10 22:55:39";
# 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 23:29:03
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 for thread 1 with sequence 26 is already on disk as file +DATA/arch/orcl/1_26_964992135.dbf
archived log for thread 1 with sequence 27 is already on disk as file +DATA/arch/orcl/1_27_964992135.dbf
archived log for thread 1 with sequence 28 is already on disk as file +DATA/arch/orcl/1_28_964992135.dbf
archived log for thread 1 with sequence 29 is already on disk as file +DATA/arch/orcl/1_29_964992135.dbf
archived log for thread 1 with sequence 30 is already on disk as file +DATA/arch/orcl/1_30_964992135.dbf
archived log for thread 1 with sequence 31 is already on disk as file +DATA/arch/orcl/1_31_964992135.dbf
archived log for thread 1 with sequence 32 is already on disk as file +DATA/arch/orcl/1_32_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
archived log file name=+DATA/arch/orcl/1_26_964992135.dbf thread=1 sequence=26
archived log file name=+DATA/arch/orcl/1_27_964992135.dbf thread=1 sequence=27
archived log file name=+DATA/arch/orcl/1_28_964992135.dbf thread=1 sequence=28
archived log file name=+DATA/arch/orcl/1_29_964992135.dbf thread=1 sequence=29
archived log file name=+DATA/arch/orcl/1_30_964992135.dbf thread=1 sequence=30
archived log file name=+DATA/arch/orcl/1_31_964992135.dbf thread=1 sequence=31
archived log file name=+DATA/arch/orcl/1_32_964992135.dbf thread=1 sequence=32
media recovery complete, elapsed time: 00:00:34
Finished recover at 2018-01-10 23:29:40

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_f5dd84jp_.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_f5dd84jp_.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 22:55:39";
# 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 23:30:43
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/FVTM_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:01:05
Finished restore at 2018-01-10 23:31:50

datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=965086310 file name=/ora_xtts/recover/FVTM_PITR_ORCL/datafile/o1_mf_users_f5ddf560_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "2018-01-10 22:55:39";
# 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 23:31:50
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 for thread 1 with sequence 26 is already on disk as file +DATA/arch/orcl/1_26_964992135.dbf
archived log for thread 1 with sequence 27 is already on disk as file +DATA/arch/orcl/1_27_964992135.dbf
archived log for thread 1 with sequence 28 is already on disk as file +DATA/arch/orcl/1_28_964992135.dbf
archived log for thread 1 with sequence 29 is already on disk as file +DATA/arch/orcl/1_29_964992135.dbf
archived log for thread 1 with sequence 30 is already on disk as file +DATA/arch/orcl/1_30_964992135.dbf
archived log for thread 1 with sequence 31 is already on disk as file +DATA/arch/orcl/1_31_964992135.dbf
archived log for thread 1 with sequence 32 is already on disk as file +DATA/arch/orcl/1_32_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
archived log file name=+DATA/arch/orcl/1_26_964992135.dbf thread=1 sequence=26
archived log file name=+DATA/arch/orcl/1_27_964992135.dbf thread=1 sequence=27
archived log file name=+DATA/arch/orcl/1_28_964992135.dbf thread=1 sequence=28
archived log file name=+DATA/arch/orcl/1_29_964992135.dbf thread=1 sequence=29
archived log file name=+DATA/arch/orcl/1_30_964992135.dbf thread=1 sequence=30
archived log file name=+DATA/arch/orcl/1_31_964992135.dbf thread=1 sequence=31
archived log file name=+DATA/arch/orcl/1_32_964992135.dbf thread=1 sequence=32
media recovery complete, elapsed time: 00:00:05
Finished recover at 2018-01-10 23:31:58

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_fvtm_ikCg":
   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 "CS"."T1"                                   39.66 KB       8 rows
   EXPDP> . . exported "HR"."T1"                                   39.66 KB       8 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_fvtm_ikCg" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_fvtm_ikCg is:
   EXPDP>   /ora_xtts/dump/t_emp_recvr.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_fvtm_ikCg" successfully completed at Wed Jan 10 23:32:53 2018 elapsed 0 00:00:34
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_fvtm_Dybh" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_fvtm_Dybh":
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "JY"."T1_2"                                 39.66 KB       8 rows
   IMPDP> . . imported "JY"."T1_1"                                 39.66 KB       8 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_fvtm_Dybh" successfully completed at Wed Jan 10 23:33:32 2018 elapsed 0 00:00:30
Import completed


Removing automatic instance
Automatic instance removed
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_f5ddc523_.tmp deleted
auxiliary instance file /ora_xtts/recover/FVTM_PITR_ORCL/onlinelog/o1_mf_3_f5ddhgrn_.log deleted
auxiliary instance file /ora_xtts/recover/FVTM_PITR_ORCL/onlinelog/o1_mf_2_f5ddhgqw_.log deleted
auxiliary instance file /ora_xtts/recover/FVTM_PITR_ORCL/onlinelog/o1_mf_1_f5ddhgq8_.log deleted
auxiliary instance file /ora_xtts/recover/FVTM_PITR_ORCL/datafile/o1_mf_users_f5ddf560_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5dd8k7d_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5dd8k8j_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_system_f5dd8k64_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/controlfile/o1_mf_f5dd84jp_.ctl deleted
auxiliary instance file t_emp_recvr.dmp deleted
Finished recover at 2018-01-10 23:33:36

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

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

  COUNT(*)
----------
         8

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

  COUNT(*)
----------
         8

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

Oracle 12C使用UNTIL SEQUENCE子句对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之前记录当前log sequence,在执行恢复时它们被用来指定恢复时间点

SQL> select count(*) from t_emp;

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

1 row selected.

记录当前时间点的logseq号为29

SQL> select sequence#, status from v$log;

 SEQUENCE# STATUS
---------- --------
        28 INACTIVE
        29 CURRENT
        27 INACTIVE

3 rows selected.

进行日志切换,记录truncate操作之前的logseq号为30,并执行truncate操作

SQL> alter system switch logfile;

System altered.
SQL> select sequence#, status from v$log;

 SEQUENCE# STATUS
---------- ----------------
        28 INACTIVE
        29 ACTIVE
        30 CURRENT

SQL> truncate table t_emp;

Table truncated.

进行日志切换,记录truncate操作之后的logseq号为31

SQL> alter system switch logfile;

System altered.


SQL> select sequence#, status from v$log;

 SEQUENCE# STATUS
---------- ----------------
        31 CURRENT
        29 ACTIVE
        30 ACTIVE

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 sequence 30
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:32:35
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='zdjl'

initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=zdjl_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  logseq 30 thread 1;
# 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:33:40
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:05
output file name=/ora_xtts/recover/ORCL/controlfile/o1_mf_f5d929nw_.ctl
Finished restore at 2018-01-10 22:33:46

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  logseq 30 thread 1;
# 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:33:55
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:34:41

datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=965082881 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_system_f5d92n67_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=965082881 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5d92n7d_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=965082881 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5d92n6t_.dbf

contents of Memory Script:
{
# set requested point in time
set until  logseq 30 thread 1;
# 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:34:43
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 for thread 1 with sequence 26 is already on disk as file +DATA/arch/orcl/1_26_964992135.dbf
archived log for thread 1 with sequence 27 is already on disk as file +DATA/arch/orcl/1_27_964992135.dbf
archived log for thread 1 with sequence 28 is already on disk as file +DATA/arch/orcl/1_28_964992135.dbf
archived log for thread 1 with sequence 29 is already on disk as file +DATA/arch/orcl/1_29_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
archived log file name=+DATA/arch/orcl/1_26_964992135.dbf thread=1 sequence=26
archived log file name=+DATA/arch/orcl/1_27_964992135.dbf thread=1 sequence=27
archived log file name=+DATA/arch/orcl/1_28_964992135.dbf thread=1 sequence=28
archived log file name=+DATA/arch/orcl/1_29_964992135.dbf thread=1 sequence=29
media recovery complete, elapsed time: 00:00:24
Finished recover at 2018-01-10 22:35: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_f5d929nw_.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_f5d929nw_.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  logseq 30 thread 1;
# 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:36: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/ZDJL_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:37:09

datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=965083029 file name=/ora_xtts/recover/ZDJL_PITR_ORCL/datafile/o1_mf_users_f5d96ycb_.dbf

contents of Memory Script:
{
# set requested point in time
set until  logseq 30 thread 1;
# 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:37: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 for thread 1 with sequence 26 is already on disk as file +DATA/arch/orcl/1_26_964992135.dbf
archived log for thread 1 with sequence 27 is already on disk as file +DATA/arch/orcl/1_27_964992135.dbf
archived log for thread 1 with sequence 28 is already on disk as file +DATA/arch/orcl/1_28_964992135.dbf
archived log for thread 1 with sequence 29 is already on disk as file +DATA/arch/orcl/1_29_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
archived log file name=+DATA/arch/orcl/1_26_964992135.dbf thread=1 sequence=26
archived log file name=+DATA/arch/orcl/1_27_964992135.dbf thread=1 sequence=27
archived log file name=+DATA/arch/orcl/1_28_964992135.dbf thread=1 sequence=28
archived log file name=+DATA/arch/orcl/1_29_964992135.dbf thread=1 sequence=29
media recovery complete, elapsed time: 00:00:06
Finished recover at 2018-01-10 22:37: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_zdjl_ctic":
   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_zdjl_ctic" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_zdjl_ctic is:
   EXPDP>   /ora_xtts/dump/t_emp_recvr.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_zdjl_ctic" successfully completed at Wed Jan 10 22:38:12 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_zdjl_nBfi" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_zdjl_nBfi":
   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_zdjl_nBfi" successfully completed at Wed Jan 10 22:38:51 2018 elapsed 0 00:00:32
Import completed


Removing automatic instance
Automatic instance removed
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_f5d94xrx_.tmp deleted
auxiliary instance file /ora_xtts/recover/ZDJL_PITR_ORCL/onlinelog/o1_mf_3_f5d98yqq_.log deleted
auxiliary instance file /ora_xtts/recover/ZDJL_PITR_ORCL/onlinelog/o1_mf_2_f5d98yq4_.log deleted
auxiliary instance file /ora_xtts/recover/ZDJL_PITR_ORCL/onlinelog/o1_mf_1_f5d98ypg_.log deleted
auxiliary instance file /ora_xtts/recover/ZDJL_PITR_ORCL/datafile/o1_mf_users_f5d96ycb_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5d92n6t_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5d92n7d_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_system_f5d92n67_.dbf deleted
auxiliary instance file /ora_xtts/recover/ORCL/controlfile/o1_mf_f5d929nw_.ctl deleted
auxiliary instance file t_emp_recvr.dmp deleted
Finished recover at 2018-01-10 22:38:56

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中使用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]
....省略....