Oracle 12c如何使用RMAN备份对Non

33次阅读
没有评论

共计 32293 个字符,预计需要花费 81 分钟才能阅读完成。

丸趣 TV 小编给大家分享一下 Oracle 12c 如何使用 RMAN 备份对 Non-CDB 中的表按时间点进行恢复,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

RMAN  backup as compressed backupset database format  +data/backup/%d_%I_%U_%t  plus archivelog format  arc_%d_%T_%U 
Starting backup at 10-JAN-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=13 RECID=1 STAMP=964995986
input archived log thread=1 sequence=14 RECID=2 STAMP=965007422
input archived log thread=1 sequence=15 RECID=3 STAMP=965007493
input archived log thread=1 sequence=16 RECID=4 STAMP=965007542
input archived log thread=1 sequence=17 RECID=5 STAMP=965011311
input archived log thread=1 sequence=18 RECID=6 STAMP=965011687
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/product/12.2.0/db/dbs/arc_ORCL_20180110_21so9q78_1_1 tag=TAG20180110T024807 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 10-JAN-18
Starting backup at 10-JAN-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA/orcl/datafile/users01.dbf
input datafile file number=00001 name=+DATA/orcl/datafile/system01.dbf
input datafile file number=00002 name=+DATA/orcl/datafile/sysaux01.dbf
input datafile file number=00003 name=+DATA/orcl/datafile/undotbs01.dbf
input datafile file number=00005 name=+DATA/orcl/datafile/usertbs01.dbf
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=+DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 tag=TAG20180110T024824 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 10-JAN-18
Starting backup at 10-JAN-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=19 RECID=7 STAMP=965011751
channel ORA_DISK_1: starting piece 1 at 10-JAN-18
channel ORA_DISK_1: finished piece 1 at 10-JAN-18
piece handle=/u01/app/oracle/product/12.2.0/db/dbs/arc_ORCL_20180110_23so9q98_1_1 tag=TAG20180110T024912 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JAN-18
Starting Control File and SPFILE Autobackup at 10-JAN-18
piece handle=+DATA/backup/c-1492772871-20180110-01 comment=NONE
Finished Control File and SPFILE Autobackup at 10-JAN-18

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

SQL  select count(*) from t_emp;
 COUNT(*)
----------
 107
1 row selected.
SQL  select sysdate from dual;
SYSDATE
-------------------
2018-01-10 02:50:10
1 row selected.
SQL  select current_scn from v$database;
CURRENT_SCN
-----------
 399411
1 row selected.
SQL  delete from t_emp;
107 rows deleted.
SQL  commit;
Commit complete.
SQL  select count(*) from t_emp;
 COUNT(*)
----------
 0
1 row selected.

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

[oracle@jytest3 ~]$ rman target/
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Jan 10 02:22:13 2018
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1492772871)

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

RMAN  run
2  {
3  recover table hr.t_emp
4  until scn 399411
5  auxiliary destination  /ora_xtts/recover 
6  datapump destination  /ora_xtts/dump 
7  dump file  t_emp.dmp 
8  notableimport;
9  }
Starting recover at 10-JAN-18
using channel ORA_DISK_1
RMAN-05026: warning: presuming following set of tablespaces applies to specified point-in-time
List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1
Creating automatic instance, with SID= fcsj 
initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=fcsj_pitr_ORCL
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=1024M
processes=120
db_create_file_dest=/ora_xtts/recover
log_archive_dest_1= location=/ora_xtts/recover 
#No auxiliary parameter file used

Variable Size 293602616 bytes Database Buffers 763363328 bytes Redo Buffers 8146944 bytes Automatic instance created contents of Memory Script: # set requested point in time set until scn 399411; # restore the controlfile restore clone controlfile;   # mount the controlfile sql clone  alter database mount clone database   # archive current online log  sql  alter system archive log current executing Memory Script executing command: SET until clause Starting restore at 10-JAN-18 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=6 device type=DISK channel ORA_AUX_DISK_1: starting datafile backup set restore channel ORA_AUX_DISK_1: restoring control file channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/c-1492772871-20180110-01 channel ORA_AUX_DISK_1: piece handle=+DATA/backup/c-1492772871-20180110-01 tag=TAG20180110T024913 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:05 output file name=/ora_xtts/recover/ORCL/controlfile/o1_mf_f5b4xmpo_.ctl Finished restore at 10-JAN-18 sql statement: alter database mount clone database sql statement: alter system archive log current contents of Memory Script: # set requested point in time set until scn 399411; # set destinations for recovery set and auxiliary set datafiles set newname for clone datafile 1 to new; set newname for clone datafile 3 to new; set newname for clone datafile 2 to new; set newname for clone tempfile 1 to new; # switch all tempfiles switch clone tempfile all; # restore the tablespaces in the recovery set and the auxiliary set restore clone datafile 1, 3, 2;   switch clone datafile all; executing Memory Script executing command: SET until clause executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME renamed tempfile 1 to /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_%u_.tmp in control file Starting restore at 10-JAN-18 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: starting datafile backup set restore channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile 00001 to /ora_xtts/recover/ORCL/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00003 to /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00002 to /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 tag=TAG20180110T024824 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45 Finished restore at 10-JAN-18 datafile 1 switched to datafile copy input datafile copy RECID=4 STAMP=965013098 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_system_f5b4xwvo_.dbf datafile 3 switched to datafile copy input datafile copy RECID=5 STAMP=965013098 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5b4xwx2_.dbf datafile 2 switched to datafile copy input datafile copy RECID=6 STAMP=965013098 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5b4xwwj_.dbf contents of Memory Script: # set requested point in time set until scn 399411; # online the datafiles restored or switched sql clone  alter database datafile 1 online sql clone  alter database datafile 3 online sql clone  alter database datafile 2 online # recover and open database read only recover clone database tablespace  SYSTEM ,  UNDOTBS1 ,  SYSAUX sql clone  alter database open read only executing Memory Script executing command: SET until clause sql statement: alter database datafile 1 online sql statement: alter database datafile 3 online sql statement: alter database datafile 2 online Starting recover at 10-JAN-18 using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 19 is already on disk as file +DATA/arch/orcl/1_19_964992135.dbf archived log for thread 1 with sequence 20 is already on disk as file +DATA/arch/orcl/1_20_964992135.dbf archived log file name=+DATA/arch/orcl/1_19_964992135.dbf thread=1 sequence=19 archived log file name=+DATA/arch/orcl/1_20_964992135.dbf thread=1 sequence=20 media recovery complete, elapsed time: 00:00:00 Finished recover at 10-JAN-18 sql statement: alter database open read only contents of Memory Script:  sql clone  create spfile from memory  shutdown clone immediate;  startup clone nomount;  sql clone  alter system set control_files =    /ora_xtts/recover/ORCL/controlfile/o1_mf_f5b4xmpo_.ctl  comment=   RMAN set  scope=spfile  shutdown clone immediate;  startup clone nomount; # mount database sql clone  alter database mount clone database executing Memory Script sql statement: create spfile from memory database closed database dismounted Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 1073741824 bytes Fixed Size 8628936 bytes Variable Size 293602616 bytes Database Buffers 763363328 bytes Redo Buffers 8146944 bytes sql statement: alter system set control_files =  /ora_xtts/recover/ORCL/controlfile/o1_mf_f5b4xmpo_.ctl  comment=  RMAN set  scope=spfile Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 1073741824 bytes Fixed Size 8628936 bytes Variable Size 293602616 bytes Database Buffers 763363328 bytes Redo Buffers 8146944 bytes sql statement: alter database mount clone database contents of Memory Script: # set requested point in time set until scn 399411; # set destinations for recovery set and auxiliary set datafiles set newname for datafile 4 to new; # restore the tablespaces in the recovery set and the auxiliary set restore clone datafile 4;   switch clone datafile all; executing Memory Script executing command: SET until clause executing command: SET NEWNAME Starting restore at 10-JAN-18 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=7 device type=DISK channel ORA_AUX_DISK_1: starting datafile backup set restore channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile 00004 to /ora_xtts/recover/FCSJ_PITR_ORCL/datafile/o1_mf_users_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_22so9q7p_1_1_965011705 tag=TAG20180110T024824 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:15 Finished restore at 10-JAN-18 datafile 4 switched to datafile copy input datafile copy RECID=8 STAMP=965013242 file name=/ora_xtts/recover/FCSJ_PITR_ORCL/datafile/o1_mf_users_f5b51h8p_.dbf contents of Memory Script: # set requested point in time set until scn 399411; # online the datafiles restored or switched sql clone  alter database datafile 4 online # recover and open resetlogs recover clone database tablespace  USERS ,  SYSTEM ,  UNDOTBS1 ,  SYSAUX  delete archivelog; alter clone database open resetlogs; executing Memory Script executing command: SET until clause sql statement: alter database datafile 4 online Starting recover at 10-JAN-18 using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 19 is already on disk as file +DATA/arch/orcl/1_19_964992135.dbf archived log for thread 1 with sequence 20 is already on disk as file +DATA/arch/orcl/1_20_964992135.dbf archived log file name=+DATA/arch/orcl/1_19_964992135.dbf thread=1 sequence=19 archived log file name=+DATA/arch/orcl/1_20_964992135.dbf thread=1 sequence=20 media recovery complete, elapsed time: 00:00:01 Finished recover at 10-JAN-18 database opened contents of Memory Script: # create directory for datapump import sql  create or replace directory TSPITR_DIROBJ_DPDIR as  /ora_xtts/dump # create directory for datapump export sql clone  create or replace directory TSPITR_DIROBJ_DPDIR as  /ora_xtts/dump executing Memory Script sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as  /ora_xtts/dump sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as  /ora_xtts/dump Performing export of tables...  EXPDP  Starting  SYS . TSPITR_EXP_fcsj_pkfh :   EXPDP  Processing object type TABLE_EXPORT/TABLE/TABLE_DATA  EXPDP  Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS  EXPDP  Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS  EXPDP  Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER  EXPDP  Processing object type TABLE_EXPORT/TABLE/TABLE  EXPDP  Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX  EXPDP  . . exported  HR . T_EMP  17.08 KB 107 rows  EXPDP  Master table  SYS . TSPITR_EXP_fcsj_pkfh  successfully loaded/unloaded  EXPDP  ******************************************************************************  EXPDP  Dump file set for SYS.TSPITR_EXP_fcsj_pkfh is:  EXPDP  /ora_xtts/dump/t_emp.dmp  EXPDP  Job  SYS . TSPITR_EXP_fcsj_pkfh  successfully completed at Wed Jan 10 03:15:08 2018 elapsed 0 00:00:32 Export completed Not performing table import after point-in-time recovery Removing automatic instance shutting down automatic instance  Oracle instance shut down Automatic instance removed auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_f5b4zhf9_.tmp deleted auxiliary instance file /ora_xtts/recover/FCSJ_PITR_ORCL/onlinelog/o1_mf_3_f5b53yp4_.log deleted auxiliary instance file /ora_xtts/recover/FCSJ_PITR_ORCL/onlinelog/o1_mf_2_f5b53yol_.log deleted auxiliary instance file /ora_xtts/recover/FCSJ_PITR_ORCL/onlinelog/o1_mf_1_f5b53ynw_.log deleted auxiliary instance file /ora_xtts/recover/FCSJ_PITR_ORCL/datafile/o1_mf_users_f5b51h8p_.dbf deleted auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5b4xwwj_.dbf deleted auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5b4xwx2_.dbf deleted auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_system_f5b4xwvo_.dbf deleted auxiliary instance file /ora_xtts/recover/ORCL/controlfile/o1_mf_f5b4xmpo_.ctl deleted Finished recover at 10-JAN-18

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

RMAN  run
2  {
3  recover table hr.t_emp
4  until scn 399411
5  auxiliary destination  /ora_xtts/recover 
6  datapump destination  /ora_xtts/dump 
7  dump file  t_emp_recvr.dmp 
8  remap table  HR . T_EMP : JY . T_EMP_NEW 
9  remap tablespace  USERS : USERTBS 
10  }
Starting recover at 10-JAN-18
current log archived
using channel ORA_DISK_1
RMAN-05026: warning: presuming following set of tablespaces applies to specified point-in-time
List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1
Creating automatic instance, with SID= jzdF 
initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=jzdF_pitr_ORCL
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=1024M
processes=120
db_create_file_dest=/ora_xtts/recover
log_archive_dest_1= location=/ora_xtts/recover 
#No auxiliary parameter file used

Variable Size 293602616 bytes Database Buffers 763363328 bytes Redo Buffers 8146944 bytes Automatic instance created contents of Memory Script: # set requested point in time set until scn 399411; # restore the controlfile restore clone controlfile;   # mount the controlfile sql clone  alter database mount clone database   # archive current online log  sql  alter system archive log current executing Memory Script executing command: SET until clause Starting restore at 10-JAN-18 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=6 device type=DISK channel ORA_AUX_DISK_1: starting datafile backup set restore channel ORA_AUX_DISK_1: restoring control file channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/c-1492772871-20180110-02 channel ORA_AUX_DISK_1: piece handle=+DATA/backup/c-1492772871-20180110-02 tag=TAG20180110T200959 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04 output file name=/ora_xtts/recover/ORCL/controlfile/o1_mf_f5d2402v_.ctl Finished restore at 10-JAN-18 sql statement: alter database mount clone database sql statement: alter system archive log current contents of Memory Script: # set requested point in time set until scn 399411; # set destinations for recovery set and auxiliary set datafiles set newname for clone datafile 1 to new; set newname for clone datafile 3 to new; set newname for clone datafile 2 to new; set newname for clone tempfile 1 to new; # switch all tempfiles switch clone tempfile all; # restore the tablespaces in the recovery set and the auxiliary set restore clone datafile 1, 3, 2;   switch clone datafile all; executing Memory Script executing command: SET until clause executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME renamed tempfile 1 to /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_%u_.tmp in control file Starting restore at 10-JAN-18 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: starting datafile backup set restore channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile 00001 to /ora_xtts/recover/ORCL/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00003 to /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00002 to /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_26sobn77_1_1_965074151 channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_26sobn77_1_1_965074151 tag=TAG20180110T200911 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45 Finished restore at 10-JAN-18 datafile 1 switched to datafile copy input datafile copy RECID=4 STAMP=965075765 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_system_f5d248q8_.dbf datafile 3 switched to datafile copy input datafile copy RECID=5 STAMP=965075766 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5d248r7_.dbf datafile 2 switched to datafile copy input datafile copy RECID=6 STAMP=965075766 file name=/ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5d248qv_.dbf contents of Memory Script: # set requested point in time set until scn 399411; # online the datafiles restored or switched sql clone  alter database datafile 1 online sql clone  alter database datafile 3 online sql clone  alter database datafile 2 online # recover and open database read only recover clone database tablespace  SYSTEM ,  UNDOTBS1 ,  SYSAUX sql clone  alter database open read only executing Memory Script executing command: SET until clause sql statement: alter database datafile 1 online sql statement: alter database datafile 3 online sql statement: alter database datafile 2 online Starting recover at 10-JAN-18 using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 24 is already on disk as file +DATA/arch/orcl/1_24_964992135.dbf archived log for thread 1 with sequence 25 is already on disk as file +DATA/arch/orcl/1_25_964992135.dbf archived log file name=+DATA/arch/orcl/1_24_964992135.dbf thread=1 sequence=24 archived log file name=+DATA/arch/orcl/1_25_964992135.dbf thread=1 sequence=25 media recovery complete, elapsed time: 00:00:01 Finished recover at 10-JAN-18 sql statement: alter database open read only contents of Memory Script:  sql clone  create spfile from memory  shutdown clone immediate;  startup clone nomount;  sql clone  alter system set control_files =    /ora_xtts/recover/ORCL/controlfile/o1_mf_f5d2402v_.ctl  comment=   RMAN set  scope=spfile  shutdown clone immediate;  startup clone nomount; # mount database sql clone  alter database mount clone database executing Memory Script sql statement: create spfile from memory database closed database dismounted Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 1073741824 bytes Fixed Size 8628936 bytes Variable Size 293602616 bytes Database Buffers 763363328 bytes Redo Buffers 8146944 bytes sql statement: alter system set control_files =  /ora_xtts/recover/ORCL/controlfile/o1_mf_f5d2402v_.ctl  comment=  RMAN set  scope=spfile Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 1073741824 bytes Fixed Size 8628936 bytes Variable Size 293602616 bytes Database Buffers 763363328 bytes Redo Buffers 8146944 bytes sql statement: alter database mount clone database contents of Memory Script: # set requested point in time set until scn 399411; # set destinations for recovery set and auxiliary set datafiles set newname for datafile 4 to new; # restore the tablespaces in the recovery set and the auxiliary set restore clone datafile 4;   switch clone datafile all; executing Memory Script executing command: SET until clause executing command: SET NEWNAME Starting restore at 10-JAN-18 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=7 device type=DISK channel ORA_AUX_DISK_1: starting datafile backup set restore channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile 00004 to /ora_xtts/recover/JZDF_PITR_ORCL/datafile/o1_mf_users_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/orcl_1492772871_26sobn77_1_1_965074151 channel ORA_AUX_DISK_1: piece handle=+DATA/backup/orcl_1492772871_26sobn77_1_1_965074151 tag=TAG20180110T200911 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55 Finished restore at 10-JAN-18 datafile 4 switched to datafile copy input datafile copy RECID=8 STAMP=965075892 file name=/ora_xtts/recover/JZDF_PITR_ORCL/datafile/o1_mf_users_f5d27wvd_.dbf contents of Memory Script: # set requested point in time set until scn 399411; # online the datafiles restored or switched sql clone  alter database datafile 4 online # recover and open resetlogs recover clone database tablespace  USERS ,  SYSTEM ,  UNDOTBS1 ,  SYSAUX  delete archivelog; alter clone database open resetlogs; executing Memory Script executing command: SET until clause sql statement: alter database datafile 4 online Starting recover at 10-JAN-18 using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 24 is already on disk as file +DATA/arch/orcl/1_24_964992135.dbf archived log for thread 1 with sequence 25 is already on disk as file +DATA/arch/orcl/1_25_964992135.dbf archived log file name=+DATA/arch/orcl/1_24_964992135.dbf thread=1 sequence=24 archived log file name=+DATA/arch/orcl/1_25_964992135.dbf thread=1 sequence=25 media recovery complete, elapsed time: 00:00:00 Finished recover at 10-JAN-18 database opened contents of Memory Script: # create directory for datapump import sql  create or replace directory TSPITR_DIROBJ_DPDIR as  /ora_xtts/dump # create directory for datapump export sql clone  create or replace directory TSPITR_DIROBJ_DPDIR as  /ora_xtts/dump executing Memory Script sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as  /ora_xtts/dump sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as  /ora_xtts/dump Performing export of tables...  EXPDP  Starting  SYS . TSPITR_EXP_jzdF_fxiC :   EXPDP  Processing object type TABLE_EXPORT/TABLE/TABLE_DATA  EXPDP  Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS  EXPDP  Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER  EXPDP  Processing object type TABLE_EXPORT/TABLE/TABLE  EXPDP  . . exported  HR . T_EMP  17.08 KB 107 rows  EXPDP  Master table  SYS . TSPITR_EXP_jzdF_fxiC  successfully loaded/unloaded  EXPDP  ******************************************************************************  EXPDP  Dump file set for SYS.TSPITR_EXP_jzdF_fxiC is:  EXPDP  /ora_xtts/dump/t_emp_recvr.dmp  EXPDP  Job  SYS . TSPITR_EXP_jzdF_fxiC  successfully completed at Wed Jan 10 20:39:09 2018 elapsed 0 00:00:32 Export completed
Performing import of tables...  IMPDP  Master table  SYS . TSPITR_IMP_jzdF_BDce  successfully loaded/unloaded  IMPDP  Starting  SYS . TSPITR_IMP_jzdF_BDce :   IMPDP  Processing object type TABLE_EXPORT/TABLE/TABLE  IMPDP  Processing object type TABLE_EXPORT/TABLE/TABLE_DATA  IMPDP  . . imported  JY . T_EMP_NEW  17.08 KB 107 rows  IMPDP  Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS  IMPDP  Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER  IMPDP  Job  SYS . TSPITR_IMP_jzdF_BDce  successfully completed at Wed Jan 10 20:39:47 2018 elapsed 0 00:00:31 Import completed
Automatic instance removed auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_tempts1_f5d25tp8_.tmp deleted auxiliary instance file /ora_xtts/recover/JZDF_PITR_ORCL/onlinelog/o1_mf_3_f5d29sj0_.log deleted auxiliary instance file /ora_xtts/recover/JZDF_PITR_ORCL/onlinelog/o1_mf_2_f5d29shf_.log deleted auxiliary instance file /ora_xtts/recover/JZDF_PITR_ORCL/onlinelog/o1_mf_1_f5d29sgs_.log deleted auxiliary instance file /ora_xtts/recover/JZDF_PITR_ORCL/datafile/o1_mf_users_f5d27wvd_.dbf deleted auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_sysaux_f5d248qv_.dbf deleted auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_undotbs1_f5d248r7_.dbf deleted auxiliary instance file /ora_xtts/recover/ORCL/datafile/o1_mf_system_f5d248q8_.dbf deleted auxiliary instance file /ora_xtts/recover/ORCL/controlfile/o1_mf_f5d2402v_.ctl deleted auxiliary instance file t_emp_recvr.dmp deleted Finished recover at 10-JAN-18

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

[oracle@jytest3 dump]$ impdp hr/hr@orcl dumpfile=dump_dir:t_emp.dmp
Import: Release 12.2.0.1.0 - Production on Wed Jan 10 03:23:34 2018
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Master table  HR . SYS_IMPORT_FULL_01  successfully loaded/unloaded
Starting  HR . SYS_IMPORT_FULL_01 : hr/********@orcl dumpfile=dump_dir:t_emp.dmp 
Processing object type TABLE_EXPORT/TABLE/TABLE
ORA-39151: Table  HR . T_EMP  exists. All dependent metadata and data will be skipped due to table_exists_action of skip
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
Job  HR . SYS_IMPORT_FULL_01  completed with 1 error(s) at Wed Jan 10 03:23:51 2018 elapsed 0 00:00:10

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

[oracle@jytest3 dump]$ impdp hr/hr@orcl dumpfile=dump_dir:t_emp.dmp table_exists_action=truncate
Import: Release 12.2.0.1.0 - Production on Wed Jan 10 03:29:10 2018
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Master table  HR . SYS_IMPORT_FULL_01  successfully loaded/unloaded
Starting  HR . SYS_IMPORT_FULL_01 : hr/********@orcl dumpfile=dump_dir:t_emp.dmp table_exists_action=truncate 
Processing object type TABLE_EXPORT/TABLE/TABLE
Table  HR . T_EMP  exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported  HR . T_EMP  17.08 KB 107 rows
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
Job  HR . SYS_IMPORT_FULL_01  successfully completed at Wed Jan 10 03:29:30 2018 elapsed 0 00:00:18

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

SQL  select count(*) from t_emp;
 COUNT(*)
----------
 107

以上是“Oracle 12c 如何使用 RMAN 备份对 Non-CDB 中的表按时间点进行恢复”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-24发表,共计32293字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)