|
12C 全自动基于时间点恢复表(TPITR)
----------------------------------------------------------------------------------------------
环境:
RDBMS:ORACLE 12.1.0.2
OS:Linux7.8
----------------------------------------------------------------------------------------------
测试如下:
--创建RMAN备份
RMAN> backup database plus archivelog;
Starting backup at 31-JUL-20
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=5 RECID=5 STAMP=1047203433
input archived log thread=1 sequence=6 RECID=6 STAMP=1047203452
input archived log thread=1 sequence=7 RECID=7 STAMP=1047204475
input archived log thread=1 sequence=8 RECID=8 STAMP=1047204494
input archived log thread=1 sequence=9 RECID=9 STAMP=1047204529
input archived log thread=1 sequence=10 RECID=10 STAMP=1047204811
input archived log thread=1 sequence=11 RECID=11 STAMP=1047207299
channel ORA_DISK_1: starting piece 1 at 31-JUL-20
channel ORA_DISK_1: finished piece 1 at 31-JUL-20
piece handle=/u01/app/oracle/fast_recovery_area/SZTECH/backupset/2020_07_31/o1_mf_annnn_TAG20200731T105459_hl7203r5_.bkp tag=TAG20200731T105459 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 31-JUL-20
Starting backup at 31-JUL-20
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/example01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/undotbs1.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/tbs_idx01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/users01.dbf
channel ORA_DISK_1: starting piece 1 at 31-JUL-20
channel ORA_DISK_1: finished piece 1 at 31-JUL-20
piece handle=/u01/app/oracle/fast_recovery_area/SZTECH/backupset/2020_07_31/o1_mf_nnndf_TAG20200731T105500_hl7204x5_.bkp tag=TAG20200731T105500 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 31-JUL-20
channel ORA_DISK_1: finished piece 1 at 31-JUL-20
piece handle=/u01/app/oracle/fast_recovery_area/SZTECH/backupset/2020_07_31/o1_mf_ncsnf_TAG20200731T105500_hl720f01_.bkp tag=TAG20200731T105500 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 31-JUL-20
Starting backup at 31-JUL-20
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=12 RECID=12 STAMP=1047207310
channel ORA_DISK_1: starting piece 1 at 31-JUL-20
channel ORA_DISK_1: finished piece 1 at 31-JUL-20
piece handle=/u01/app/oracle/fast_recovery_area/SZTECH/backupset/2020_07_31/o1_mf_annnn_TAG20200731T105510_hl720g37_.bkp tag=TAG20200731T105510 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 31-JUL-20
--查询当前SCN
SQL> select timestamp_to_scn(sysdate) from dual;
TIMESTAMP_TO_SCN(SYSDATE)
-------------------------
3329365
--截断表
SQL> truncate table hr.emp;
Table truncated.
--RMAN基于SCN恢复表
RMAN> recover table hr.emp until scn 3329365
2> auxiliary destination '/home/oracle';
Starting recover at 31-JUL-20
current log archived
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/31/2020 10:57:30
RMAN-05063: Cannot recover specified tables
RMAN-05112: table "HR"."EMP" already exists
--报错是因为TARGET实例中存在EMP,虽然只有表结构也不行。
--删除表EMP
SQL> drop table hr.emp;
Table dropped.
--再次执行恢复
RMAN> recover table hr.emp until scn 3329365
2> auxiliary destination '/home/oracle';
Starting recover at 31-JUL-20
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='ftvd'
initialization parameters used for automatic instance:
db_name=SZTECH
db_unique_name=ftvd_pitr_SZTECH
compatible=12.1.0.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=768M
processes=200
db_create_file_dest=/home/oracle
log_archive_dest_1='location=/home/oracle'
#No auxiliary parameter file used
starting up automatic instance SZTECH
Oracle instance started
Total System Global Area 805306368 bytes
Fixed Size 2929552 bytes
Variable Size 222301296 bytes
Database Buffers 574619648 bytes
Redo Buffers 5455872 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until scn 3329365;
# 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 31-JUL-20
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=12 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/SZTECH/backupset/2020_07_31/o1_mf_ncsnf_TAG20200731T105500_hl720f01_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/SZTECH/backupset/2020_07_31/o1_mf_ncsnf_TAG20200731T105500_hl720f01_.bkp tag=TAG20200731T105500
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/oracle/SZTECH/controlfile/o1_mf_hl725x70_.ctl
Finished restore at 31-JUL-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 3329365;
# 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 /home/oracle/SZTECH/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 31-JUL-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 00001 to /home/oracle/SZTECH/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /home/oracle/SZTECH/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /home/oracle/SZTECH/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/SZTECH/backupset/2020_07_31/o1_mf_nnndf_TAG20200731T105500_hl7204x5_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/SZTECH/backupset/2020_07_31/o1_mf_nnndf_TAG20200731T105500_hl7204x5_.bkp tag=TAG20200731T105500
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 31-JUL-20
datafile 1 switched to datafile copy
input datafile copy RECID=8 STAMP=1047207498 file name=/home/oracle/SZTECH/datafile/o1_mf_system_hl7263wr_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=9 STAMP=1047207498 file name=/home/oracle/SZTECH/datafile/o1_mf_undotbs1_hl7263wx_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=10 STAMP=1047207498 file name=/home/oracle/SZTECH/datafile/o1_mf_sysaux_hl7263ws_.dbf
contents of Memory Script:
{
# set requested point in time
set until scn 3329365;
# 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 31-JUL-20
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 12 is already on disk as file /u01/app/oracle/fast_recovery_area/SZTECH/archivelog/2020_07_31/o1_mf_1_12_hl720g0x_.arc
archived log for thread 1 with sequence 13 is already on disk as file /u01/app/oracle/fast_recovery_area/SZTECH/archivelog/2020_07_31/o1_mf_1_13_hl724t8r_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/SZTECH/archivelog/2020_07_31/o1_mf_1_12_hl720g0x_.arc thread=1 sequence=12
archived log file name=/u01/app/oracle/fast_recovery_area/SZTECH/archivelog/2020_07_31/o1_mf_1_13_hl724t8r_.arc thread=1 sequence=13
media recovery complete, elapsed time: 00:00:00
Finished recover at 31-JUL-20
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 =
''/home/oracle/SZTECH/controlfile/o1_mf_hl725x70_.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 805306368 bytes
Fixed Size 2929552 bytes
Variable Size 226495600 bytes
Database Buffers 570425344 bytes
Redo Buffers 5455872 bytes
sql statement: alter system set control_files = ''/home/oracle/SZTECH/controlfile/o1_mf_hl725x70_.ctl'' comment= ''RMAN set'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 805306368 bytes
Fixed Size 2929552 bytes
Variable Size 226495600 bytes
Database Buffers 570425344 bytes
Redo Buffers 5455872 bytes
sql statement: alter database mount clone database
contents of Memory Script:
{
# set requested point in time
set until scn 3329365;
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile 2 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 2;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
Starting restore at 31-JUL-20
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=12 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 00002 to /home/oracle/FTVD_PITR_SZTECH/datafile/o1_mf_tbs_idx_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/SZTECH/backupset/2020_07_31/o1_mf_nnndf_TAG20200731T105500_hl7204x5_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/SZTECH/backupset/2020_07_31/o1_mf_nnndf_TAG20200731T105500_hl7204x5_.bkp tag=TAG20200731T105500
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 31-JUL-20
datafile 2 switched to datafile copy
input datafile copy RECID=12 STAMP=1047207543 file name=/home/oracle/FTVD_PITR_SZTECH/datafile/o1_mf_tbs_idx_hl727p05_.dbf
contents of Memory Script:
{
# set requested point in time
set until scn 3329365;
# online the datafiles restored or switched
sql clone "alter database datafile 2 online";
# recover and open resetlogs
recover clone database tablespace "TBS_IDX", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 2 online
Starting recover at 31-JUL-20
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 12 is already on disk as file /u01/app/oracle/fast_recovery_area/SZTECH/archivelog/2020_07_31/o1_mf_1_12_hl720g0x_.arc
archived log for thread 1 with sequence 13 is already on disk as file /u01/app/oracle/fast_recovery_area/SZTECH/archivelog/2020_07_31/o1_mf_1_13_hl724t8r_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/SZTECH/archivelog/2020_07_31/o1_mf_1_12_hl720g0x_.arc thread=1 sequence=12
archived log file name=/u01/app/oracle/fast_recovery_area/SZTECH/archivelog/2020_07_31/o1_mf_1_13_hl724t8r_.arc thread=1 sequence=13
media recovery complete, elapsed time: 00:00:00
Finished recover at 31-JUL-20
database opened
contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/home/oracle''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/home/oracle''";
}
executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle''
Performing export of tables...
EXPDP> Starting "SYS"."TSPITR_EXP_ftvd_ugeh":
EXPDP> Estimate in progress using BLOCKS method...
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
EXPDP> Total estimation using BLOCKS method: 64 KB
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
EXPDP> ORA-39127: unexpected error from call to export_string :=SYS.DBMS_TRANSFORM_EXIMP.INSTANCE_INFO_EXP('AQ$_ORDERS_QUEUETABLE_S','IX',1,1,'12.01.00.02.00',newblock)
ORA-00376: file 5 cannot be read at this time
ORA-01110: data file 5: '/u01/app/oracle/oradata/sztech/SZTECH/datafile/example01.dbf'
ORA-06512: at "SYS.DBMS_TRANSFORM_EXIMP", line 197
ORA-06512: at line 1
ORA-06512: at "SYS.DBMS_METADATA", line 10261
ORA-39127: unexpected error from call to export_string :=SYS.DBMS_TRANSFORM_EXIMP.INSTANCE_INFO_EXP('AQ$_STREAMS_QUEUE_TABLE_S','IX',1,1,'12.01.00.02.00',newblock)
ORA-00376: file 5 cannot be read at this time
ORA-01110: data file 5: '/u01/app/oracle/oradata/sztech/SZTECH/datafile/example01.dbf'
ORA-06512: at "SYS.DBMS_TRANSFORM_EXIMP", line 197
ORA-06512: at line 1
ORA-06512: at "SYS.DBMS_METADATA", line 10261
EXPDP> . . exported "HR"."EMP" 17.08 KB 107 rows
EXPDP> Master table "SYS"."TSPITR_EXP_ftvd_ugeh" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_ftvd_ugeh is:
EXPDP> /home/oracle/tspitr_ftvd_57525.dmp
EXPDP> Job "SYS"."TSPITR_EXP_ftvd_ugeh" completed with 2 error(s) at Fri Jul 31 10:59:19 2020 elapsed 0 00:00:10
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_ftvd_fqdd" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_ftvd_fqdd":
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
IMPDP> . . imported "HR"."EMP" 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_ftvd_fqdd" successfully completed at Fri Jul 31 10:59:33 2020 elapsed 0 00:00:11
Import completed
Removing automatic instance
Automatic instance removed
auxiliary instance file /home/oracle/SZTECH/datafile/o1_mf_temp_hl726cov_.tmp deleted
auxiliary instance file /home/oracle/FTVD_PITR_SZTECH/onlinelog/o1_mf_3_hl727qp1_.log deleted
auxiliary instance file /home/oracle/FTVD_PITR_SZTECH/onlinelog/o1_mf_2_hl727qmf_.log deleted
auxiliary instance file /home/oracle/FTVD_PITR_SZTECH/onlinelog/o1_mf_1_hl727qjq_.log deleted
auxiliary instance file /home/oracle/FTVD_PITR_SZTECH/datafile/o1_mf_tbs_idx_hl727p05_.dbf deleted
auxiliary instance file /home/oracle/SZTECH/datafile/o1_mf_sysaux_hl7263ws_.dbf deleted
auxiliary instance file /home/oracle/SZTECH/datafile/o1_mf_undotbs1_hl7263wx_.dbf deleted
auxiliary instance file /home/oracle/SZTECH/datafile/o1_mf_system_hl7263wr_.dbf deleted
auxiliary instance file /home/oracle/SZTECH/controlfile/o1_mf_hl725x70_.ctl deleted
auxiliary instance file tspitr_ftvd_57525.dmp deleted
Finished recover at 31-JUL-20
--恢复完成后,验证表和数据,恢复成功
SQL> select count(*) from hr.emp;
COUNT(*)
----------
107
说明 :
基于期间点对一张或多张表或表分区进行恢复的使用场景:
- Small number of tables (no TSPITR) --需要恢复的数据相关较少时,使用表空间恢复速度太慢
- Not in a self-contained tablespace (no TSPITR) --不存在于自包含的表空间中
- Purged tables (no Flashback drop) --无法通过闪回删除表技术来恢复
- Beyond the available undo (no Flashback Table) --UNDO丢失,无法通过闪回表来恢复
- After a structural DDL change (no Flashback Table) --表结构变化,无法通过闪回表来恢复
基于期间点对一张或多张表或表分区进行恢复的条件和限制:
To recover tables and table partitions from RMAN backups, the target database must be:
- In read/write mode --目标库在读写状态,最后需要执行 impdp数据导入
- In ARCHIVELOG mode --目标库开归档
- COMPATIBLE set to 12.0 or higher to recover table(s) or table partition(s) --12C及以上版本才支持
Limitations of recovery: No tables and table partitions from:
- The SYS schema
- The SYSTEM and SYSAUX tablespaces
- Standby databases
--THE END
|
|