限制条件
不支持sys用户和system表空间的表
RMAN-05063: Cannot recover specified tables RMAN-05056: Table SYS.TB belongs to SYS RMAN-05056: Table SYS.TA belongs to SYS
恢复过程
RMAN> create table scutech.ta as select object_id from dba_objects; Statement processed RMAN> select current_scn from v$database; CURRENT_SCN ----------- 3647348 RMAN> recover table scutech.ta of pluggable database orcl until scn 3647348 AUXILIARY DESTINATION '/u01/recover' REMAP TABLE scutech.ta:tb; Starting recover at 21-SEP-20 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 ORCL:SYSTEM Tablespace UNDOTBS2 Tablespace ORCL:UNDOTBS2 Creating automatic instance, with SID='bmDF' initialization parameters used for automatic instance: db_name=ORCLCDB db_unique_name=bmDF_pitr_orcl_ORCLCDB compatible=19.0.0 db_block_size=8192 db_files=200 diagnostic_dest=/u01/app/oracle _system_trig_enabled=FALSE sga_target=800M processes=200 db_create_file_dest=/u01/recover log_archive_dest_1='location=/u01/recover' enable_pluggable_database=true _clone_one_pdb_recovery=true max_string_size=EXTENDED #No auxiliary parameter file used starting up automatic instance ORCLCDB Oracle instance started Total System Global Area 838858664 bytes Fixed Size 9140136 bytes Variable Size 243269632 bytes Database Buffers 578813952 bytes Redo Buffers 7634944 bytes Automatic instance created contents of Memory Script: { # set requested point in time set until scn 3647348; # 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 21-SEP-20 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=169 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 /u01/app/oracle/fast_recovery_area/ORCLCDB/autobackup/2020_09_21/o1_mf_s_1051676625_hpjrrlnv_.bkp channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCLCDB/autobackup/2020_09_21/o1_mf_s_1051676625_hpjrrlnv_.bkp tag=TAG20200921T042345 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01 output file name=/u01/recover/ORCLCDB/controlfile/o1_mf_hpjsj4g3_.ctl Finished restore at 21-SEP-20 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 3647348; # 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 14 to new; set newname for clone datafile 15 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, 14, 15, 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 /u01/recover/ORCLCDB/datafile/o1_mf_temp_%u_.tmp in control file renamed tempfile 3 to /u01/recover/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_temp_%u_.tmp in control file Starting restore at 21-SEP-20 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 00009 to /u01/recover/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00015 to /u01/recover/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_undotbs2_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/recover/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/backupset/2020_09_21/o1_mf_nnndf_TAG20200921T042229_hpjrp65m_.bkp channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/backupset/2020_09_21/o1_mf_nnndf_TAG20200921T042229_hpjrp65m_.bkp tag=TAG20200921T042229 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25 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 /u01/recover/ORCLCDB/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00014 to /u01/recover/ORCLCDB/datafile/o1_mf_undotbs2_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/recover/ORCLCDB/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ORCLCDB/backupset/2020_09_21/o1_mf_nnndf_TAG20200921T042229_hpjrq9df_.bkp channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCLCDB/backupset/2020_09_21/o1_mf_nnndf_TAG20200921T042229_hpjrq9df_.bkp tag=TAG20200921T042229 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25 Finished restore at 21-SEP-20 datafile 1 switched to datafile copy input datafile copy RECID=10 STAMP=1051677437 file name=/u01/recover/ORCLCDB/datafile/o1_mf_system_hpjsk4kh_.dbf datafile 9 switched to datafile copy input datafile copy RECID=11 STAMP=1051677437 file name=/u01/recover/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_system_hpjsjcf8_.dbf datafile 14 switched to datafile copy input datafile copy RECID=12 STAMP=1051677437 file name=/u01/recover/ORCLCDB/datafile/o1_mf_undotbs2_hpjsk4m6_.dbf datafile 15 switched to datafile copy input datafile copy RECID=13 STAMP=1051677437 file name=/u01/recover/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_undotbs2_hpjsjcfc_.dbf datafile 3 switched to datafile copy input datafile copy RECID=14 STAMP=1051677437 file name=/u01/recover/ORCLCDB/datafile/o1_mf_sysaux_hpjsk4m0_.dbf datafile 10 switched to datafile copy input datafile copy RECID=15 STAMP=1051677437 file name=/u01/recover/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_sysaux_hpjsjcdb_.dbf contents of Memory Script: { # set requested point in time set until scn 3647348; # online the datafiles restored or switched sql clone "alter database datafile 1 online"; sql clone 'ORCL' "alter database datafile 9 online"; sql clone "alter database datafile 14 online"; sql clone 'ORCL' "alter database datafile 15 online"; sql clone "alter database datafile 3 online"; sql clone 'ORCL' "alter database datafile 10 online"; # recover and open database read only recover clone database tablespace "SYSTEM", "ORCL":"SYSTEM", "UNDOTBS2", "ORCL":"UNDOTBS2", "SYSAUX", "ORCL":"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 14 online sql statement: alter database datafile 15 online sql statement: alter database datafile 3 online sql statement: alter database datafile 10 online Starting recover at 21-SEP-20 using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 29 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCLCDB/archivelog/2020_09_21/o1_mf_1_29_hpjs1brk_.arc archived log for thread 1 with sequence 30 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCLCDB/archivelog/2020_09_21/o1_mf_1_30_hpjshf2z_.arc archived log file name=/u01/app/oracle/fast_recovery_area/ORCLCDB/archivelog/2020_09_21/o1_mf_1_29_hpjs1brk_.arc thread=1 sequence=29 archived log file name=/u01/app/oracle/fast_recovery_area/ORCLCDB/archivelog/2020_09_21/o1_mf_1_30_hpjshf2z_.arc thread=1 sequence=30 media recovery complete, elapsed time: 00:00:02 Finished recover at 21-SEP-20 sql statement: alter database open read only contents of Memory Script: { sql clone 'alter pluggable database ORCL open read only'; } executing Memory Script sql statement: alter pluggable database ORCL 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 = ''/u01/recover/ORCLCDB/controlfile/o1_mf_hpjsj4g3_.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 838858664 bytes Fixed Size 9140136 bytes Variable Size 243269632 bytes Database Buffers 578813952 bytes Redo Buffers 7634944 bytes sql statement: alter system set control_files = ''/u01/recover/ORCLCDB/controlfile/o1_mf_hpjsj4g3_.ctl'' comment= ''RMAN set'' scope=spfile Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 838858664 bytes Fixed Size 9140136 bytes Variable Size 243269632 bytes Database Buffers 578813952 bytes Redo Buffers 7634944 bytes sql statement: alter database mount clone database contents of Memory Script: { # set requested point in time set until scn 3647348; # set destinations for recovery set and auxiliary set datafiles set newname for datafile 12 to new; # restore the tablespaces in the recovery set and the auxiliary set restore clone datafile 12; switch clone datafile all; } executing Memory Script executing command: SET until clause executing command: SET NEWNAME Starting restore at 21-SEP-20 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=203 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 00012 to /u01/recover/BMDF_PITR_ORCL_ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_users_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/backupset/2020_09_21/o1_mf_nnndf_TAG20200921T042229_hpjrp65m_.bkp channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/backupset/2020_09_21/o1_mf_nnndf_TAG20200921T042229_hpjrp65m_.bkp tag=TAG20200921T042229 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15 Finished restore at 21-SEP-20 datafile 12 switched to datafile copy input datafile copy RECID=17 STAMP=1051677532 file name=/u01/recover/BMDF_PITR_ORCL_ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_users_hpjsndxv_.dbf contents of Memory Script: { # set requested point in time set until scn 3647348; # online the datafiles restored or switched sql clone 'ORCL' "alter database datafile 12 online"; # recover and open resetlogs recover clone database tablespace "ORCL":"USERS", "SYSTEM", "ORCL":"SYSTEM", "UNDOTBS2", "ORCL":"UNDOTBS2", "SYSAUX", "ORCL":"SYSAUX" delete archivelog; alter clone database open resetlogs; } executing Memory Script executing command: SET until clause sql statement: alter database datafile 12 online Starting recover at 21-SEP-20 using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 29 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCLCDB/archivelog/2020_09_21/o1_mf_1_29_hpjs1brk_.arc archived log for thread 1 with sequence 30 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCLCDB/archivelog/2020_09_21/o1_mf_1_30_hpjshf2z_.arc archived log file name=/u01/app/oracle/fast_recovery_area/ORCLCDB/archivelog/2020_09_21/o1_mf_1_29_hpjs1brk_.arc thread=1 sequence=29 archived log file name=/u01/app/oracle/fast_recovery_area/ORCLCDB/archivelog/2020_09_21/o1_mf_1_30_hpjshf2z_.arc thread=1 sequence=30 media recovery complete, elapsed time: 00:00:00 Finished recover at 21-SEP-20 database opened contents of Memory Script: { sql clone 'alter pluggable database ORCL open'; } executing Memory Script sql statement: alter pluggable database ORCL open contents of Memory Script: { # create directory for datapump import sql 'ORCL' "create or replace directory TSPITR_DIROBJ_DPDIR as '' /u01/recover''"; # create directory for datapump export sql clone 'ORCL' "create or replace directory TSPITR_DIROBJ_DPDIR as '' /u01/recover''"; } executing Memory Script sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/recover'' sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/recover'' Performing export of tables... EXPDP> Starting "SYS"."TSPITR_EXP_bmDF_eslD": 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 "SCUTECH"."TA" 688.7 KB 79002 rows EXPDP> Master table "SYS"."TSPITR_EXP_bmDF_eslD" successfully loaded/unloaded EXPDP> ****************************************************************************** EXPDP> Dump file set for SYS.TSPITR_EXP_bmDF_eslD is: EXPDP> /u01/recover/tspitr_bmDF_21348.dmp EXPDP> Job "SYS"."TSPITR_EXP_bmDF_eslD" successfully completed at Mon Sep 21 04:40:26 2020 elapsed 0 00:00:55 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_bmDF_BBAp" successfully loaded/unloaded IMPDP> Starting "SYS"."TSPITR_IMP_bmDF_BBAp": IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA IMPDP> . . imported "SCUTECH"."TB" 688.7 KB 79002 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_bmDF_BBAp" successfully completed at Mon Sep 21 04:41:48 2020 elapsed 0 00:01:00 Import completed Removing automatic instance Automatic instance removed auxiliary instance file /u01/recover/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_temp_hpjsl4dy_.tmp deleted auxiliary instance file /u01/recover/ORCLCDB/datafile/o1_mf_temp_hpjsl2m9_.tmp deleted auxiliary instance file /u01/recover/BMDF_PITR_ORCL_ORCLCDB/onlinelog/o1_mf_3_hpjsnz14_.log deleted auxiliary instance file /u01/recover/BMDF_PITR_ORCL_ORCLCDB/onlinelog/o1_mf_2_hpjsnz07_.log deleted auxiliary instance file /u01/recover/BMDF_PITR_ORCL_ORCLCDB/onlinelog/o1_mf_1_hpjsnyym_.log deleted auxiliary instance file /u01/recover/BMDF_PITR_ORCL_ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_users_hpjsndxv_.dbf deleted auxiliary instance file /u01/recover/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_sysaux_hpjsjcdb_.dbf deleted auxiliary instance file /u01/recover/ORCLCDB/datafile/o1_mf_sysaux_hpjsk4m0_.dbf deleted auxiliary instance file /u01/recover/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_undotbs2_hpjsjcfc_.dbf deleted auxiliary instance file /u01/recover/ORCLCDB/datafile/o1_mf_undotbs2_hpjsk4m6_.dbf deleted auxiliary instance file /u01/recover/ORCLCDB/8A34DEF16CD55C76E0530100007F040C/datafile/o1_mf_system_hpjsjcf8_.dbf deleted auxiliary instance file /u01/recover/ORCLCDB/datafile/o1_mf_system_hpjsk4kh_.dbf deleted auxiliary instance file /u01/recover/ORCLCDB/controlfile/o1_mf_hpjsj4g3_.ctl deleted auxiliary instance file tspitr_bmDF_21348.dmp deleted Finished recover at 21-SEP-20
我们看到一个recover table命令执行了很多过程,大致分成
创建一下临时实例
恢复一个临时实例,只包括SYSTEM,UNDO,SYSAUX和表所在的表空间。
expdp导出表
impdp导入表
删除临时实例
这条命令的功能真强,执行了这么多步骤!
创建临时实例
我们看到在恢复的过程中启动了一个辅助的实例
[oracle@localhost ~]$ ps -ef|grep pmon oracle 17228 1 0 03:41 ? 00:00:00 ora_pmon_orclcdb oracle 21232 1 0 04:36 ? 00:00:00 ora_pmon_bmDF oracle 21320 16131 0 04:36 pts/2 00:00:00 grep --color=auto pmon [oracle@localhost ~]$ ll /u01/recover/ total 0 drwxr-x---. 6 oracle oinstall 98 Sep 21 04:36 ORCLCDB [oracle@localhost ~]$ ll /u01/recover/ORCLCDB/ total 0 drwxr-x---. 3 oracle oinstall 22 Sep 21 04:36 8A34DEF16CD55C76E0530100007F040C drwxr-x---. 2 oracle oinstall 33 Sep 21 04:36 controlfile drwxr-x---. 2 oracle oinstall 6 Sep 21 04:36 datafile drwxr-x---. 2 oracle oinstall 6 Sep 21 04:36 onlinelog
检查执行结果
oracle@localhost ~]$ sqlplus sys/oracle as sysdba SQL*Plus: Release 19.0.0.0.0 - Production on Mon Sep 21 04:40:13 2020 Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle. All rights reserved. Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0 SQL> select count(*) from scutech.ta; COUNT(*) ---------- 79002 SQL> select count(*) from scutech.tb; COUNT(*) ---------- 79002