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
Proudly powered by WordPress | Indrajeet by Sus Hill.