12c RMAN新特性之Recover Table
Recovering Tables and Table Partitions
摘要
12c 的 rman 有了很大的增強,其中一個亮點就是可以進行表(或分割槽)級別的恢復,相比 TSPITR,recover table 更加快捷、靈活。
在 Oracle 12c 之前,如果誤刪一張表,常規的方法是 Flashback 閃回或 TSPITR。而開啟 flashback 會消耗磁碟空間,且如果被 purge 或者經過 DDL,將無法 flashback。如果需要恢復的表空間過大,TSPITR 會耗時非常久。12c 中提供了Table Recovery 的新特性,可以針對單表(或單個表分割槽)基於時間點進行恢復,該特性用以直接從 RMAN 備份中恢復表的方法,該特性有以下特點:
-
不影響資料庫中的其他資料庫物件
-
減少時間和磁碟空間的消耗,和早期的 TSPIRT 工作流程類似
-
從另一個磁碟路徑恢復表空間
-
匯出想要的表資料
-
匯入到原資料庫(可選)
recover table 可以將一個或多個表或表分割槽恢復到指定的時間點,而不會影響其餘的資料庫物件。可以使用以前建立的 RMAN 備份將表和表分割槽恢復到指定的時間點。
該表被恢復到一個輔助例項中,並且可以選擇:
-
使用 REMAP 選項將恢復的表匯入新表或分割槽
-
僅在恢復的表中建立 expdp dump 檔案,以便在其他時間進行匯入
先決條件
目標資料庫必須處於 ARCHIVELOG 模式。
您必須擁有表或表分割槽的 RMAN 備份,因為它們存在於要恢復這些物件的時間點。
要恢復單個表分割槽,目標資料庫的 COMPATIBLE 初始化引數必須設定為 11.1.0 或更高。
請確保 AUXILIARY DESTINATION 有足夠的空間來恢復 system、sysaux、undo 以及恢復表所需的表空間。
請注意,表恢復後,輔助目標中的這些檔案將自動刪除
必須使用 AUXILIARY DESTINATION 子句和後面其中一個子句來指定恢復的時間點:UNTIL TIME、UNTIL SCN 或 UNTIL SEQUENCE。
使用限制
-
屬於SYS模式的表和表分割槽無法恢復。
-
SYSTEM和SYSAUX表空間中的表和表分割槽無法恢復。
-
standby資料庫上的表和表分割槽無法恢復。
-
命名為NOT NULL約束的表不能用REMAP選項恢復。
使用場景
RMAN 的表級和表分割槽級恢復在以下場景中非常適用:
(1) 需要將非常少量的表恢復至特定的時間點。在這種情況下,TSPITR 不是最有效的解決方案 ,因為它會將表空間中的所有物件恢復到指定的時間點。
(2) 需要恢復已被邏輯損壞或已被 drop 和 purge 的表。
(3) flashback 不可用,比如需要的 undo 資料被覆蓋。
(4) DDL 操作修改表結構後丟失的資料。flashback table 不能跨越 DDL(例如 truncate )來回滾表。
在這Recover table 過程演示
建立測試表
SQL> create table t_recover_test as select * from dba_objects;
Table created.
SQL> select count(*) from t_recover_test;
COUNT(*) ---------- 72652 |
備份
[oracle@localhost ~]$ rman target / Recovery Manager: Release 12.2.0.1.0 - Production on Thu Jun 28 21:06:17 2018 Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved. connected to target database: PCC (DBID=3164878903) RMAN> backup database format '/home/oracle/bak/db_%U';
Starting backup at 28-JUN-18 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=61 device type=DISK channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00001 name=/home/oracle/oradata/pcc/system01.dbf input datafile file number=00003 name=/home/oracle/oradata/pcc/sysaux01.dbf input datafile file number=00004 name=/home/oracle/oradata/pcc/undotbs01.dbf input datafile file number=00005 name=/home/oracle/oradata/pcc/tbs_zyq01.dbf input datafile file number=00007 name=/home/oracle/oradata/pcc/users01.dbf channel ORA_DISK_1: starting piece 1 at 28-JUN-18 channel ORA_DISK_1: finished piece 1 at 28-JUN-18 piece handle=/home/oracle/bak/db_01t6k254_1_1 tag=TAG20180628T215236 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 Finished backup at 28-JUN-18
Starting Control File and SPFILE Autobackup at 28-JUN-18 piece handle=/u01/app/oracle/product/12.2.0.1/dbs/c-3164878903-20180628-00 comment=NONE Finished Control File and SPFILE Autobackup at 28-JUN-18 |
恢復表
[oracle@localhost ~]$ rman target / Recovery Manager: Release 12.2.0.1.0 - Production on Fri Jun 29 00:52:29 2018 Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved. connected to target database: PCC (DBID=3164878903) RMAN> RECOVER TABLE zyq.t_recover_test until time "to_date('2018-06-28 23:56:06','yyyy-mm-dd hh24:mi:ss')" AUXILIARY DESTINATION '/data01' REMAP TABLE zyq.t_recover_test:t_recover_test_map;
Starting recover at 29-JUN-18 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=66 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=' hCed '
initialization parameters used for automatic instance: db_name=PCC db_unique_name=hCed_pitr_PCC compatible=12.2.0 db_block_size=8192 db_files=200 diagnostic_dest=/u01/app/oracle _system_trig_enabled=FALSE sga_target=732M processes=200 db_create_file_dest=/data01 log_archive_dest_1='location=/data01' #No auxiliary parameter file used
starting up automatic instance PCC
Oracle instance started
Total System Global Area 767557632 bytes
Fixed Size 8625416 bytes Variable Size 213910264 bytes Database Buffers 541065216 bytes Redo Buffers 3956736 bytes Automatic instance created
contents of Memory Script: { # set requested point in time set until time "to_date('2018-06-28 23:56:06','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 29-JUN-18 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=35 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/product/12.2.0.1/dbs/c-3164878903-20180628-01 channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/product/12.2.0.1/dbs/c-3164878903-20180628-01 tag=TAG20180628T234914 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02 output file name=/data01/PCC/controlfile/o1_mf_fmcsc00p_.ctl Finished restore at 29-JUN-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 time "to_date('2018-06-28 23:56:06','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 4 to new; set newname for clone datafile 3 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, 4, 3;
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 /data01/PCC/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 29-JUN-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 /data01/PCC/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00004 to /data01/PCC/datafile/o1_mf_undotbs1_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00003 to /data01/PCC/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/bak/db_01t6k254_1_1 channel ORA_AUX_DISK_1: piece handle=/home/oracle/bak/db_01t6k254_1_1 tag=TAG20180628T215236 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15 Finished restore at 29-JUN-18
datafile 1 switched to datafile copy input datafile copy RECID=4 STAMP=980038406 file name=/data01/PCC/datafile/o1_mf_system_fmcsc755_.dbf datafile 4 switched to datafile copy input datafile copy RECID=5 STAMP=980038406 file name=/data01/PCC/datafile/o1_mf_undotbs1_fmcsc75h_.dbf datafile 3 switched to datafile copy input datafile copy RECID=6 STAMP=980038406 file name=/data01/PCC/datafile/o1_mf_sysaux_fmcsc75c_.dbf
contents of Memory Script: { # set requested point in time set until time "to_date('2018-06-28 23:56:06','yyyy-mm-dd hh24:mi:ss')"; # online the datafiles restored or switched sql clone "alter database datafile 1 online"; sql clone "alter database datafile 4 online"; sql clone "alter database datafile 3 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 4 online
sql statement: alter database datafile 3 online
Starting recover at 29-JUN-18 using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/product/12.2.0.1/dbs/arch1_3_979872889.dbf archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oracle/product/12.2.0.1/dbs/arch1_4_979872889.dbf archived log file name=/u01/app/oracle/product/12.2.0.1/dbs/arch1_3_979872889.dbf thread=1 sequence=3 archived log file name=/u01/app/oracle/product/12.2.0.1/dbs/arch1_4_979872889.dbf thread=1 sequence=4 media recovery complete, elapsed time: 00:00:11 Finished recover at 29-JUN-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 = ''/data01/PCC/controlfile/o1_mf_fmcsc00p_.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 767557632 bytes
Fixed Size 8625416 bytes Variable Size 213910264 bytes Database Buffers 541065216 bytes Redo Buffers 3956736 bytes
sql statement: alter system set control_files = ''/data01/PCC/controlfile/o1_mf_fmcsc00p_.ctl'' comment= ''RMAN set'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started) Oracle instance started
Total System Global Area 767557632 bytes
Fixed Size 8625416 bytes Variable Size 213910264 bytes Database Buffers 541065216 bytes Redo Buffers 3956736 bytes
sql statement: alter database mount clone database
contents of Memory Script: { # set requested point in time set until time "to_date('2018-06-28 23:56:06','yyyy-mm-dd hh24:mi:ss')"; # set destinations for recovery set and auxiliary set datafiles set newname for datafile 5 to new; # restore the tablespaces in the recovery set and the auxiliary set restore clone datafile 5;
switch clone datafile all; } executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
Starting restore at 29-JUN-18 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=34 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 00005 to /data01/HCED_PITR_PCC/datafile/o1_mf_tbs_zyq_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/bak/db_01t6k254_1_1 channel ORA_AUX_DISK_1: piece handle=/home/oracle/bak/db_01t6k254_1_1 tag=TAG20180628T215236 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03 Finished restore at 29-JUN-18
datafile 5 switched to datafile copy input datafile copy RECID=8 STAMP=980038478 file name=/data01/HCED_PITR_PCC/datafile/o1_mf_tbs_zyq_fmcsfttn_.dbf
contents of Memory Script: { # set requested point in time set until time "to_date('2018-06-28 23:56:06','yyyy-mm-dd hh24:mi:ss')"; # online the datafiles restored or switched sql clone "alter database datafile 5 online"; # recover and open resetlogs recover clone database tablespace "TBS_ZYQ", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog; alter clone database open resetlogs; } executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 5 online
Starting recover at 29-JUN-18 using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/product/12.2.0.1/dbs/arch1_3_979872889.dbf archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oracle/product/12.2.0.1/dbs/arch1_4_979872889.dbf archived log file name=/u01/app/oracle/product/12.2.0.1/dbs/arch1_3_979872889.dbf thread=1 sequence=3 archived log file name=/u01/app/oracle/product/12.2.0.1/dbs/arch1_4_979872889.dbf thread=1 sequence=4 media recovery complete, elapsed time: 00:00:01 Finished recover at 29-JUN-18
database opened
contents of Memory Script: { # create directory for datapump import sql "create or replace directory TSPITR_DIROBJ_DPDIR as '' /data01''"; # create directory for datapump export sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as '' /data01''"; } executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/data01''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/data01''
Performing export of tables... EXPDP> Starting "SYS"."TSPITR_EXP_hCed_Dhxe": 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 "ZYQ"."T_RECOVER_TEST" 9.324 MB 72652 rows EXPDP> Master table "SYS"."TSPITR_EXP_hCed_Dhxe" successfully loaded/unloaded EXPDP> ****************************************************************************** EXPDP> Dump file set for SYS.TSPITR_EXP_hCed_Dhxe is: EXPDP> /data01/tspitr_hCed_71393.dmp EXPDP> Job "SYS"."TSPITR_EXP_hCed_Dhxe" successfully completed at Fri Jun 29 00:55:41 2018 elapsed 0 00:00:35 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_hCed_Arhm" successfully loaded/unloaded IMPDP> Starting "SYS"."TSPITR_IMP_hCed_Arhm": IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA IMPDP> . . imported "ZYQ"."T_RECOVER_TEST_MAP" 9.324 MB 72652 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_hCed_Arhm" successfully completed at Fri Jun 29 00:56:43 2018 elapsed 0 00:00:45 Import completed
Removing automatic instance Automatic instance removed auxiliary instance file /data01/PCC/datafile/o1_mf_temp_fmcsd5ny_.tmp deleted auxiliary instance file /data01/HCED_PITR_PCC/onlinelog/o1_mf_3_fmcsg3y6_.log deleted auxiliary instance file /data01/HCED_PITR_PCC/onlinelog/o1_mf_2_fmcsg07o_.log deleted auxiliary instance file /data01/HCED_PITR_PCC/onlinelog/o1_mf_1_fmcsfzr1_.log deleted auxiliary instance file /data01/HCED_PITR_PCC/datafile/o1_mf_tbs_zyq_fmcsfttn_.dbf deleted auxiliary instance file /data01/PCC/datafile/o1_mf_sysaux_fmcsc75c_.dbf deleted auxiliary instance file /data01/PCC/datafile/o1_mf_undotbs1_fmcsc75h_.dbf deleted auxiliary instance file /data01/PCC/datafile/o1_mf_system_fmcsc755_.dbf deleted auxiliary instance file /data01/PCC/controlfile/o1_mf_fmcsc00p_.ctl deleted auxiliary instance file tspitr_hCed_71393.dmp deleted Finished recover at 29-JUN-18
RMAN> |
驗證
SQL> select count(*) from T_RECOVER_TEST_MAP;
COUNT(*) ---------- 72652 |
總結
(1) 根據為恢復指定的時間點確定哪個備份包含需要恢復的表或表分割槽。
(2) 確定目標主機上是否有足夠的空間來建立將在表或分割槽恢復過程中使用的輔助例項。如果所需空間不可用,則 RMAN 會顯示錯誤並退出恢復操作。
(3) 在目標主機上建立一個輔助資料庫,並將指定的表或表分割槽恢復到此輔助資料庫中,直到指定的時間點。您可以指定恢復的資料檔案儲存在輔助資料庫中的目標主機上的位置。
(4) 建立包含恢復的表或表分割槽的資料泵匯出轉儲檔案。您可以指定用於儲存恢復的表或表分割槽的後設資料的資料泵匯出轉儲檔案的名稱和位置。
(5) (可選)將 Data Pump 匯出轉儲檔案匯入到目標例項中。您可以選擇不將包含恢復的表或表分割槽的匯出轉儲檔案匯入目標資料庫。如果不將匯出轉儲檔案作為恢復過程的一部分匯入,則必須稍後使用“資料泵匯入”實用程式手動匯入它。
注:如果在匯入操作期間發生錯誤,RMAN 不會在表恢復結束時刪除匯出轉儲檔案。這使您能夠手動匯入轉儲檔案。
(6) (可選)重新命名目標資料庫中已恢復的表或表分割槽。您還可以將恢復的物件匯入到與最初存在的表空間或模式不同的表空間或模式中。12.2 開始,schema 可不同
注:當您使用 REMAP 選項時,不會匯入任何指定的約束和索引。這是為了避免與現有表格的名稱衝突。
如果不希望表被匯入,只需要恢復出 dmp 檔案,可以使用 notableimport 選項,命令如下:
RECOVER TABLE SCOTT.EMP, SCOTT.DEPT UNTIL TIME 'SYSDATE-1' AUXILIARY DESTINATION '/tmp/oracle/recover' DATAPUMP DESTINATION '/tmp/recover/dumpfiles' DUMP FILE 'emp_dept_exp_dump.dat' NOTABLEIMPORT; |
如果需要將表恢復至另外的 schema,命令如下:
RECOVER TABLE HR.DEPARTMENTS, SH.CHANNELS UNTIL TIME 'SYSDATE – 1' AUXILIARY DESTINATION '/tmp/auxdest' REMAP TABLE hr.departments:example.new_departments, sh.channels:example.new_channels; |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31397003/viewspace-2639895/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【12c】12c RMAN新特性之recover table(表級別恢復)
- 【12c】12c RMAN新特性之通過網路遠端恢復資料庫(RESTORE/Recover from Service)資料庫REST
- Oracle Database 12C 新功能 rman RECOVER TABLE (文件 ID 2047644.1)OracleDatabase
- Oracle 12c新特性之——TABLE ACCESS BY INDEX ROWID BATCHEDOracleIndexBAT
- Oracle 12c Recover Table New FeatureOracle
- Oracle 12C新特性-RMAN恢復表Oracle
- Oracle 12c: Recover tables using RMANOracle
- Oracle 12C 新特性之move (非分割槽表)table onlineOracle
- oracle 12c新特性:Rman表恢復之直接匯入系統Oracle
- Oracle 12c新特性之Sequence的Session特性OracleSession
- Oracle 12c 新特性之 temp undoOracle
- Oracle 12C 新特性之級聯truncateOracle
- Oracle 12C 新特性之 恢復表Oracle
- 實戰10g新特性之RMAN TSPITR特性
- rman recover databaseDatabase
- oracle 12c 新特性之不可見欄位Oracle
- oracle 12C 新特性之臨時undo控制Oracle
- Oracle 12c新特性Oracle
- 【新炬網路名師大講堂】12c新特性:使用RMAN連線CDB
- Oracle11g新特性點評之RMANOracle
- 12c 新特性之 Limiting the Size of the Program Global AreaMIT
- Oracle 12c 新特性(四)Oracle
- Oracle 12c 新特性(三)Oracle
- Oracle 12c 新特性(二)Oracle
- Oracle 12c 新特性(一)Oracle
- 【12c】12c RMAN新特性之UNTIL AVAILABLE REDO--自動恢復到REDO終點的步驟簡化AI
- [20190718]12c rman新特性 表恢復.txt
- oracle 12c 新特性三:rman命令視窗可以執行sql語句OracleSQL
- 12c 新特性之大表自動快取 Automatic Big Table Caching快取
- Oracle 12c新特性--ASMFD(ASM Filter Driver)特性OracleASMFilter
- Oracle 12C新特性-History命令Oracle
- Oracle 12c 兩個新特性Oracle
- Oracle 12C新特性In-MemoryOracle
- Oracle GoldenGate 12c 新特性OracleGo
- oracle 11g 新特性 data recover AdvisorOracle
- Oracle 12c 新特性之臨時Undo--temp_undo_enabledOracle
- lockdown profile 12c之後的許可權控制新特性
- Oracle 12c新特性之:APPROX_COUNT_DISTINCT 函式OracleAPP函式