签到成功

知道了

CNDBA社区CNDBA社区

Oracle 12c 新特性:RMAN Recover Table 详解

2017-04-17 12:14 6256 0 原创 Oracle 18c
作者: dave

1. Recover Table 和 Table Partitions概述

Oracle 从12c开始支持在RMAN 中进行表级的恢复操作,即对单表进行recover。官方文档链接如下:

RMAN的表级和表分区级恢复可以使用在如下场景:
1. 恢复小表时。也可以使用TSPITR 的方法,但该方法效率很低,因为需要移动表空间中的所有对象。
2. 恢复有逻辑损坏或者被删除的表。
3. Flashback Table 不可用,比如undo 数据已经被覆盖。
4. DDL 操作后需要恢复数据。Flashback Table 不支持表结构发生改变后的回退。 比如truncate table。

只要之前创建了RMAN 备份,就可以根据指定的的时间来进行表级和表分区级的恢复操作,而且不影响其他的数据库对象。

可以根据在以下三种级别指定时间:
(1) SCN
(2) Sequence number
(3) Time:根据 NLS_LANG 和 NLS_DATE_FORMAT 环境变量中的格式来指定时间,也可以用SYSDATE,比如 SYSDATE-30.

为了恢复表或者表分区, 需要备份undo,SYSTEM,SYSAUX和包含表或者表分区的表空间。

如果恢复的表在PDB中,那么需要备份如下内容:
1. Root的SYSTEM,SYSAUX 和undo 表空间,SEED,以及包含表的PDB。
2. 包含表或分区的表空间

当然恢复表或者表分区也有限制条件,以下情况不能使用:
1. SYS 用户的表或表分区不能进行恢复
2. SYSTEM 和SYSAUX 表空间中的表或表分区不能进行恢复。
3. Standby 数据库上的表或表分区不能进行恢复。
4. 在使用REMAP 的情况下,有NOT NULL 约束的表不能进行恢复。

RMAN从备份中自动处理恢复表或者表分区时会执行如下步骤:
1.判断哪些备份包含需要恢复的表或表分区,然后根据指定的时间来进行恢复。
2.判断目标主机上是否有足够的空间来创建auxiliary instance,该实例用于处理表或分区的恢复。 如果需要的空间不足,那么RMAN 会报错并退出恢复操作。
3.创建auxiliary database,并根据指定的时间来恢复指定的表或表分区到auxiliary database中。 辅助数据库的数据文件位置可以在命令中指定。
4.创建包含恢复表或表分区的数据泵文件(expdp dump file)。 数据泵的名称和位置也可以在命令中指定。
5. (可选操作)将上一步生产的数据泵文件导入到目标实例中。当然也可以选择不导入,如果选择不导入就必须使用impdp 手工导入。
6. (可选操作)在目标数据库中rename 恢复表或表分区。


2 PDB操作示例

2.1 准备测试环境

因为特性不支持系统用户和表,所以需要先创建独立的用户和表空间:

oracle@www.cndba.cn ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Sun Apr 16 23:24:44 2017

Copyright (c) 1982, 2016, Oracle. All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT
SQL> show pdbs

 CON_ID CON_NAME			 OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			 READ ONLY NO
	 3 DAVE 			 READ WRITE NO
SQL> alter session set container=DAVE;
Session altered.

SQL> create tablespace lotus datafile '/dave/app/oracle/oradata/cndba/dave/lotus01.dbf' size 20m;
Tablespace created.

SQL> create user lotus identified by lotus default tablespace lotus;
User created.

SQL> grant resource,connect,dba to lotus;
Grant succeeded.

--创建测试表:
SQL> conn lotus/lotus@dave
Connected.
SQL> create table cndba as select * from dba_objects;

Table created.

SQL> select count(1) from cndba;

 COUNT(1)
----------
 72636

SQL> conn / as sysdba
Connected.
SQL> alter system switch logfile;

System altered.

SQL> alter system switch logfile;

System altered.

2.2   RMAN 备份CDB

--使用如下命令备份CDB的组建:ROOT,SEED,PDBS:

RMAN> backup database plus archivelog;

http://www.cndba.cn/dave/article/1871

具体过程省略,第一小节已有说明,在PDB 中必须备份ROOT,SEED,和所有的PDBS.http://www.cndba.cn/dave/article/1871


2.3  恢复数据

现在drop cndba 表,然后执行恢复操作:

SQL> conn lotus/lotus@dave
Connected.
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,'YY
-------------------
2017-04-17 10:20:49

SQL> drop table cndba;

注意这里只能是drop,truncate不能recover。 如果是truncate,那么就不能执行导入操作。http://www.cndba.cn/dave/article/1871

注意在链接RMAN 时需要连接到root,并且具有SYSDBA 或 SYSBACKUP 权限。

可以使用rman target sys 或 rman target /(The connection is established as the SYS user with SYSDBA privilege)http://www.cndba.cn/dave/article/1871

[oracle@www.cndba.cn cndba]$ mkdir -p /tmp/oracle/recover
[oracle@www.cndba.cn cndba]$ mkdir -p /tmp/recover/dumpfiles

恢复过程:还原system,undo,sysaux表空间,然后read only数据库,然后重启数据库还原表所在表空间,然后expdp导出表,根据需要决定是否导入表到原PDB数据库中,最后删除辅助数据库。 整个过程对原PDB没有影响。

恢复命令如下:

recover table lotus.cndba of pluggable database dave
 until time "to_date('2017-04-17 10:20:49','yyyy-mm-dd hh24:mi:ss')"
 auxiliary destination '/tmp/oracle/recover'
datapump destination '/tmp/recover/dumpfiles'
 dump file 'www.cndba.cn.dat';

大致过程:

Creating automatic instance, with SID='ajrg' -----这里开始创建auxiliary instancehttp://www.cndba.cn/dave/article/1871

Starting restore at 17-APR-17 -----restore database

http://www.cndba.cn/dave/article/1871
http://www.cndba.cn/dave/article/1871

Starting recover at 17-APR-17 ----recoverhttp://www.cndba.cn/dave/article/1871

# create directory for datapump import -----使用数据泵导出相关数据

Performing import of tables... -------target database导入数据

Removing automatic instance

Automatic instance removed ------删除环境

完整log:

http://www.cndba.cn/dave/article/1871

RMAN> recover table lotus.cndba of pluggable database dave
 until time "to_date('2017-04-17 10:20:49','yyyy-mm-dd hh24:mi:ss')"
 auxiliary destination '/tmp/oracle/recover'
datapump destination '/tmp/recover/dumpfiles'
 dump file 'www.cndba.cn.dat';
2> 3> 4> 5> 
Starting recover at 17-APR-17
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 DAVE:SYSTEM
Tablespace UNDOTBS1
Tablespace DAVE:UNDOTBS1

Creating automatic instance, with SID='ajrg'

initialization parameters used for automatic instance:
db_name=CNDBA
db_unique_name=ajrg_pitr_dave_CNDBA
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/dave/app/oracle
_system_trig_enabled=FALSE
sga_target=2000M
processes=200
db_create_file_dest=/tmp/oracle/recover
log_archive_dest_1='location=/tmp/oracle/recover'
enable_pluggable_database=true
_clone_one_pdb_recovery=true
#No auxiliary parameter file used


starting up automatic instance CNDBA

Oracle instance started

Total System Global Area 2097152000 bytes

Fixed Size 8794696 bytes
Variable Size 503319992 bytes
Database Buffers 1577058304 bytes
Redo Buffers 7979008 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until time "to_date('2017-04-17 10:20:49','yyyy-mm-dd hh24:mi:ss')";
# 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 17-APR-17
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=244 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 /dave/app/oracle/recovery_area/CNDBA/autobackup/2017_04_17/o1_mf_s_941537994_dh89lcs6_.bkp
channel ORA_AUX_DISK_1: piece handle=/dave/app/oracle/recovery_area/CNDBA/autobackup/2017_04_17/o1_mf_s_941537994_dh89lcs6_.bkp tag=TAG20170417T101954
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/tmp/oracle/recover/CNDBA/controlfile/o1_mf_dh8brc7q_.ctl
Finished restore at 17-APR-17

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 "to_date('2017-04-17 10:20:49','yyyy-mm-dd hh24:mi:ss')";
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile 1 to new;
set newname for clone datafile 9 to new;
set newname for clone datafile 4 to new;
set newname for clone datafile 11 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 10 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 1, 9, 4, 11, 3, 10;
 
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

renamed tempfile 1 to /tmp/oracle/recover/CNDBA/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /tmp/oracle/recover/CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 17-APR-17
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 /tmp/oracle/recover/CNDBA/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /tmp/oracle/recover/CNDBA/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /tmp/oracle/recover/CNDBA/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /dave/app/oracle/recovery_area/CNDBA/backupset/2017_04_17/o1_mf_nnndf_TAG20170417T101904_dh89jsk0_.bkp
channel ORA_AUX_DISK_1: piece handle=/dave/app/oracle/recovery_area/CNDBA/backupset/2017_04_17/o1_mf_nnndf_TAG20170417T101904_dh89jsk0_.bkp tag=TAG20170417T101904
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
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 00009 to /tmp/oracle/recover/CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00011 to /tmp/oracle/recover/CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00010 to /tmp/oracle/recover/CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /dave/app/oracle/recovery_area/CNDBA/4C0212A2559073AFE05515D212634C11/backupset/2017_04_17/o1_mf_nnndf_TAG20170417T101904_dh89k8lc_.bkp
channel ORA_AUX_DISK_1: piece handle=/dave/app/oracle/recovery_area/CNDBA/4C0212A2559073AFE05515D212634C11/backupset/2017_04_17/o1_mf_nnndf_TAG20170417T101904_dh89k8lc_.bkp tag=TAG20170417T101904
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 17-APR-17

datafile 1 switched to datafile copy
input datafile copy RECID=10 STAMP=941539242 file name=/tmp/oracle/recover/CNDBA/datafile/o1_mf_system_dh8brn6g_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=11 STAMP=941539242 file name=/tmp/oracle/recover/CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_system_dh8bs39k_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=941539242 file name=/tmp/oracle/recover/CNDBA/datafile/o1_mf_undotbs1_dh8brn8q_.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=13 STAMP=941539242 file name=/tmp/oracle/recover/CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_undotbs1_dh8bs3bb_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=14 STAMP=941539242 file name=/tmp/oracle/recover/CNDBA/datafile/o1_mf_sysaux_dh8brn7p_.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=15 STAMP=941539242 file name=/tmp/oracle/recover/CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_sysaux_dh8bs37y_.dbf

contents of Memory Script:
{
# set requested point in time
set until time "to_date('2017-04-17 10:20:49','yyyy-mm-dd hh24:mi:ss')";
# online the datafiles restored or switched
sql clone "alter database datafile 1 online";
sql clone 'DAVE' "alter database datafile 
 9 online";
sql clone "alter database datafile 4 online";
sql clone 'DAVE' "alter database datafile 
 11 online";
sql clone "alter database datafile 3 online";
sql clone 'DAVE' "alter database datafile 
 10 online";
# recover and open database read only
recover clone database tablespace "SYSTEM", "DAVE":"SYSTEM", "UNDOTBS1", "DAVE":"UNDOTBS1", "SYSAUX", "DAVE":"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 9 online

sql statement: alter database datafile 4 online

sql statement: alter database datafile 11 online

sql statement: alter database datafile 3 online

sql statement: alter database datafile 10 online

Starting recover at 17-APR-17
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 15 is already on disk as file /dave/app/oracle/recovery_area/CNDBA/archivelog/2017_04_17/o1_mf_1_15_dh89l7vk_.arc
archived log for thread 1 with sequence 16 is already on disk as file /dave/app/oracle/recovery_area/CNDBA/archivelog/2017_04_17/o1_mf_1_16_dh89or10_.arc
archived log file name=/dave/app/oracle/recovery_area/CNDBA/archivelog/2017_04_17/o1_mf_1_15_dh89l7vk_.arc thread=1 sequence=15
archived log file name=/dave/app/oracle/recovery_area/CNDBA/archivelog/2017_04_17/o1_mf_1_16_dh89or10_.arc thread=1 sequence=16
media recovery complete, elapsed time: 00:00:04
Finished recover at 17-APR-17

sql statement: alter database open read only

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

sql statement: alter pluggable database DAVE 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 = 
 ''/tmp/oracle/recover/CNDBA/controlfile/o1_mf_dh8brc7q_.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 2097152000 bytes

Fixed Size 8794696 bytes
Variable Size 503319992 bytes
Database Buffers 1577058304 bytes
Redo Buffers 7979008 bytes

sql statement: alter system set control_files = ''/tmp/oracle/recover/CNDBA/controlfile/o1_mf_dh8brc7q_.ctl'' comment= ''RMAN set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 2097152000 bytes

Fixed Size 8794696 bytes
Variable Size 503319992 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 "to_date('2017-04-17 10:20:49','yyyy-mm-dd hh24:mi:ss')";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile 13 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 13;
 
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

Starting restore at 17-APR-17
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=244 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 00013 to /tmp/oracle/recover/AJRG_PITR_DAVE_CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_lotus_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /dave/app/oracle/recovery_area/CNDBA/4C0212A2559073AFE05515D212634C11/backupset/2017_04_17/o1_mf_nnndf_TAG20170417T101904_dh89k8lc_.bkp
channel ORA_AUX_DISK_1: piece handle=/dave/app/oracle/recovery_area/CNDBA/4C0212A2559073AFE05515D212634C11/backupset/2017_04_17/o1_mf_nnndf_TAG20170417T101904_dh89k8lc_.bkp tag=TAG20170417T101904
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 17-APR-17

datafile 13 switched to datafile copy
input datafile copy RECID=17 STAMP=941539307 file name=/tmp/oracle/recover/AJRG_PITR_DAVE_CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_lotus_dh8bvbof_.dbf

contents of Memory Script:
{
# set requested point in time
set until time "to_date('2017-04-17 10:20:49','yyyy-mm-dd hh24:mi:ss')";
# online the datafiles restored or switched
sql clone 'DAVE' "alter database datafile 
 13 online";
# recover and open resetlogs
recover clone database tablespace "DAVE":"LOTUS", "SYSTEM", "DAVE":"SYSTEM", "UNDOTBS1", "DAVE":"UNDOTBS1", "SYSAUX", "DAVE":"SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile 13 online

Starting recover at 17-APR-17
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 15 is already on disk as file /dave/app/oracle/recovery_area/CNDBA/archivelog/2017_04_17/o1_mf_1_15_dh89l7vk_.arc
archived log for thread 1 with sequence 16 is already on disk as file /dave/app/oracle/recovery_area/CNDBA/archivelog/2017_04_17/o1_mf_1_16_dh89or10_.arc
archived log file name=/dave/app/oracle/recovery_area/CNDBA/archivelog/2017_04_17/o1_mf_1_15_dh89l7vk_.arc thread=1 sequence=15
archived log file name=/dave/app/oracle/recovery_area/CNDBA/archivelog/2017_04_17/o1_mf_1_16_dh89or10_.arc thread=1 sequence=16
media recovery complete, elapsed time: 00:00:00
Finished recover at 17-APR-17

database opened

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

sql statement: alter pluggable database DAVE open

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

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/tmp/recover/dumpfiles''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/tmp/recover/dumpfiles''

Performing export of tables...
 EXPDP> Starting "SYS"."TSPITR_EXP_ajrg_izmu": 
 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 "LOTUS"."CNDBA" 9.613 MB 72623 rows
 EXPDP> Master table "SYS"."TSPITR_EXP_ajrg_izmu" successfully loaded/unloaded
 EXPDP> ******************************************************************************
 EXPDP> Dump file set for SYS.TSPITR_EXP_ajrg_izmu is:
 EXPDP> /tmp/recover/dumpfiles/www.cndba.cn.dat
 EXPDP> Job "SYS"."TSPITR_EXP_ajrg_izmu" successfully completed at Mon Apr 17 10:42:28 2017 elapsed 0 00:00:15
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_ajrg_onBg" successfully loaded/unloaded
 IMPDP> Starting "SYS"."TSPITR_IMP_ajrg_onBg": 
 IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
 IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
 IMPDP> . . imported "LOTUS"."CNDBA" 9.613 MB 72623 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_ajrg_onBg" successfully completed at Mon Apr 17 10:42:46 2017 elapsed 0 00:00:13
Import completed


Removing automatic instance
Automatic instance removed
auxiliary instance file /tmp/oracle/recover/CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_temp_dh8bsmnd_.tmp deleted
auxiliary instance file /tmp/oracle/recover/CNDBA/datafile/o1_mf_temp_dh8bslnq_.tmp deleted
auxiliary instance file /tmp/oracle/recover/AJRG_PITR_DAVE_CNDBA/onlinelog/o1_mf_3_dh8bvhz2_.log deleted
auxiliary instance file /tmp/oracle/recover/AJRG_PITR_DAVE_CNDBA/onlinelog/o1_mf_2_dh8bvhyt_.log deleted
auxiliary instance file /tmp/oracle/recover/AJRG_PITR_DAVE_CNDBA/onlinelog/o1_mf_1_dh8bvhyk_.log deleted
auxiliary instance file /tmp/oracle/recover/AJRG_PITR_DAVE_CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_lotus_dh8bvbof_.dbf deleted
auxiliary instance file /tmp/oracle/recover/CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_sysaux_dh8bs37y_.dbf deleted
auxiliary instance file /tmp/oracle/recover/CNDBA/datafile/o1_mf_sysaux_dh8brn7p_.dbf deleted
auxiliary instance file /tmp/oracle/recover/CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_undotbs1_dh8bs3bb_.dbf deleted
auxiliary instance file /tmp/oracle/recover/CNDBA/datafile/o1_mf_undotbs1_dh8brn8q_.dbf deleted
auxiliary instance file /tmp/oracle/recover/CNDBA/4C0212A2559073AFE05515D212634C11/datafile/o1_mf_system_dh8bs39k_.dbf deleted
auxiliary instance file /tmp/oracle/recover/CNDBA/datafile/o1_mf_system_dh8brn6g_.dbf deleted
auxiliary instance file /tmp/oracle/recover/CNDBA/controlfile/o1_mf_dh8brc7q_.ctl deleted
auxiliary instance file www.cndba.cn.dat deleted
Finished recover at 17-APR-17

RMAN>

3 注意事项

3.1 说明1:PDB操作恢复的数据还在原PDB中生成

上面的示例是在PDB中演示的。 操作对象是单表,实际上对分区表中的单个分区也可以进行类似操作。

SQL> show con_name

CON_NAME
------------------------------
DAVE
SQL> select count(1) from cndba;

 COUNT(1)
----------
 72623

恢复的表还在原PDB中,中间产生的辅助数据库会在操作结束后删除。

3.2  说明2: RMAN-05112: table "LOTUS"."CNDBA" already exists

在PDB测试中 , 最开始的操作的时候,是对cndba表进行truncate 操作的。 但是执行recover时报错。 提示表已经存在,尝试remap,并未成功。 后来drop 掉表后成功recovoer。

当然也使用导出,添加notableimport参数不执行导入操作,然后在手工处理。


RMAN> recover table lotus.cndba of pluggable database dave
 until time "to_date('2017-04-17 10:20:49','yyyy-mm-dd hh24:mi:ss')"
 auxiliary destination '/tmp/oracle/recover'
datapump destination '/tmp/recover/dumpfiles'
remap table 'lotus'.' cndba':'cndba_2> 3> 4> 5> new';
 dump file 'www.cndba.cn.dat';

Starting recover at 17-APR-17
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/17/2017 10:33:20
RMAN-05063: Cannot recover specified tables
RMAN-05112: table "LOTUS"."CNDBA" already exists

3.3  说明3:ORA-01516: nonexistent log file 问题

第一次模拟的时候,recover 时报了数据文件不存在的问题。 实际上这个数据文件是我自己创建的。 后来换了个环境,重新备份后正常。 推测之前其他的rman 备份导致的异常。http://www.cndba.cn/dave/article/1871


auxiliary instance file /tmp/oracle/recover/CNDBA/controlfile/o1_mf_dh79n58l_.ctl deleted
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/17/2017 01:16:25
RMAN-03015: error occurred in stored script Memory Script
RMAN-20505: create datafile during recovery
RMAN-11003: failure during parse/execution of SQL statement: alter database datafile 17 offline
ORA-01516: nonexistent log file, data file, or temporary file "17" in the current container
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/u01/app/oracle/recovery_area/CNDBA/archivelog/2017_04_17/o1_mf_1_19_dh79h697_.arc'
ORA-00283: recovery session canceled due to errors
ORA-01244: unnamed datafile(s) added to control file by media recovery
ORA-01110: data file 17: '/u01/app/oracle/oradata/cndba/dave/lotus01.dbf'

3.4  说明4:non-CDB与PDB的区别

官网文档里还有另外一种写法,就是不带PDB 名称的。在CDB架构中测试的时候,会一直报RMAN-05057的错误:

recover table "c##lotus2".cndba 
 until time "to_date('2017-04-17 11:03:49','yyyy-mm-dd hh24:mi:ss')"
 auxiliary destination '/tmp/oracle/recover'
datapump destination '/tmp/recover/dumpfiles'
 dump file 'www.cndba.cn.dat';

但尝试恢复一直报表不存在的错误:
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/17/2017 11:35:55
RMAN-05063: Cannot recover specified tables
RMAN-05057: Table c##lotus2.CNDBA not found

仔细看了下官网,里面有提到non-cdb 情况,所以这种不带pdb名称的,应该是指这种non-cdb架构的环境。 就是普通的12c 数据库,非non-cdb 架构。 这里没有环境,不再去验证。

至少有一点可以确认,就是在CDB架构中,对PDB中的表进行操作recover table是没有问题的。


版权声明:本文为博主原创文章,未经博主允许不得转载。

Oracle 12c 新特性:RMAN Recover Table 详解

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2237
    原创
  • 2
    翻译
  • 535
    转载
  • 185
    评论
  • 访问:6530137次
  • 积分:4229
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ