oracle 11g tablespace point in time recovery(TSPITR)

文档课题:oracle 11g tablespace point in time recovery(TSPITR)
1、概念
从11g release 2引入针对被drop掉的表空间基于时间点的恢复.利用全自动的TSPITR恢复被drop的表空间.Oracle会自动创建并启动辅助实例,且仅还原那些恢复所需的控制文件,system,sysaux,undo表空间及目标表空间,这些工作都将在指定的辅助目的地’Auxiliary Destination’中完成.之后Oracle将进一步使用辅助实例recover目标表空间到指定的时间点,并将其中的数据以Data Pump传输表空间的形式导回到原数据库当中.
以下为测试该特性步骤:
a、创建测试表空间并产生少量数据
b、数据库备份
c、drop表空间
d、使用TSPITR方式将已经被drop掉的表空间恢复回来.
说明:在正式drop表空间前需留意时间点或当时的scn号.
2、操作过程
2.1、数据库信息
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/archivelog/
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2
2.2、数据准备
SQL> create tablespace dptest datafile '/u01/app/oracle/oradata01/orcl/dptest01.dbf' size 5m autoextend on;
SQL> create user leo identified by leo;
SQL> grant dba to leo;
SQL> conn leo/leo;
SQL> create table emp tablespace dptest as select * from all_objects;
SQL> insert into emp select * from emp;
.....(省略若干insert语句)
SQL> commit;
SQL> select count(*) from emp;

COUNT(*)
----------
673624
[oracle@liujun ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Sep 9 13:39:40 2022

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

connected to target database: ORCL (DBID=1642676218)
RMAN> backup database;

Starting backup at 09-SEP-22
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=00001 name=/u01/app/oracle/oradata01/orcl/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata01/orcl/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata01/orcl/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata01/orcl/dptest01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata01/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 09-SEP-22
channel ORA_DISK_1: finished piece 1 at 09-SEP-22
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2022_09_09/o1_mf_nnndf_TAG20220909T134046_kkongylk_.bkp tag=TAG20220909T134046 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
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 09-SEP-22
channel ORA_DISK_1: finished piece 1 at 09-SEP-22
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2022_09_09/o1_mf_ncsnf_TAG20220909T134046_kkonhroq_.bkp tag=TAG20220909T134046 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 09-SEP-22
SQL> select current_scn from v$database;

CURRENT_SCN
-----------
969838

SQL> drop tablespace dptest including contents and datafiles;
2.3、开始恢复
2.3.1、基于SCN
RMAN> recover tablespace dptest until scn 969838 auxiliary destination '/home/oracle/backup';

Starting recover at 09-SEP-22
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='uhso'

initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=uhso_tspitr_ORCL
compatible=11.2.0.4.0
db_block_size=8192
db_files=200
sga_target=1G
processes=80
db_create_file_dest=/home/oracle/backup
log_archive_dest_1='location=/home/oracle/backup'
#No auxiliary parameter file used


starting up automatic instance ORCL

Oracle instance started

Total System Global Area 1068937216 bytes

Fixed Size 2260088 bytes
Variable Size 285213576 bytes
Database Buffers 775946240 bytes
Redo Buffers 5517312 bytes
Automatic instance created


List of tablespaces that have been dropped from the target database:
Tablespace dptest

contents of Memory Script:
{
# set requested point in time
set until scn 969838;
# 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';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script

executing command: SET until clause

Starting restore at 09-SEP-22
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=109 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/ORCL/backupset/2022_09_09/o1_mf_ncsnf_TAG20220909T134046_kkonhroq_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2022_09_09/o1_mf_ncsnf_TAG20220909T134046_kkonhroq_.bkp tag=TAG20220909T134046
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/backup/ORCL/controlfile/o1_mf_kkont5h2_.ctl
Finished restore at 09-SEP-22

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

contents of Memory Script:
{
# set requested point in time
set until scn 969838;
# 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;
set newname for datafile 5 to
"/u01/app/oracle/oradata01/orcl/dptest01.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 3, 2, 5;
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

renamed tempfile 1 to /home/oracle/backup/ORCL/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 09-SEP-22
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/backup/ORCL/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /home/oracle/backup/ORCL/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /home/oracle/backup/ORCL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata01/orcl/dptest01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ORCL/backupset/2022_09_09/o1_mf_nnndf_TAG20220909T134046_kkongylk_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2022_09_09/o1_mf_nnndf_TAG20220909T134046_kkongylk_.bkp tag=TAG20220909T134046
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 09-SEP-22

datafile 1 switched to datafile copy
input datafile copy RECID=12 STAMP=1114955218 file name=/home/oracle/backup/ORCL/datafile/o1_mf_system_kkontbw8_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=13 STAMP=1114955218 file name=/home/oracle/backup/ORCL/datafile/o1_mf_undotbs1_kkontbwb_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=14 STAMP=1114955218 file name=/home/oracle/backup/ORCL/datafile/o1_mf_sysaux_kkontbw9_.dbf

contents of Memory Script:
{
# set requested point in time
set until scn 969838;
# 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";
sql clone "alter database datafile 5 online";
# recover and open resetlogs
recover clone database tablespace "DPTEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
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

sql statement: alter database datafile 5 online

Starting recover at 09-SEP-22
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/archivelog/1_3_1114901548.dbf
archived log file name=/u01/app/oracle/archivelog/1_3_1114901548.dbf thread=1 sequence=3
media recovery complete, elapsed time: 00:00:01
Finished recover at 09-SEP-22

database opened

contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace DPTEST read only';
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/home/oracle/backup''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/home/oracle/backup''";
}
executing Memory Script

sql statement: alter tablespace DPTEST read only

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle/backup''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle/backup''

Performing export of metadata...
EXPDP> Starting "SYS"."TSPITR_EXP_uhso":
EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
EXPDP> Master table "SYS"."TSPITR_EXP_uhso" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_uhso is:
EXPDP> /home/oracle/backup/tspitr_uhso_51068.dmp
EXPDP> ******************************************************************************
EXPDP> Datafiles required for transportable tablespace DPTEST:
EXPDP> /u01/app/oracle/oradata01/orcl/dptest01.dbf
EXPDP> Job "SYS"."TSPITR_EXP_uhso" successfully completed at Fri Sep 9 13:47:55 2022 elapsed 0 00:00:19
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
}
executing Memory Script

database closed
database dismounted
Oracle instance shut down

Performing import of metadata...
IMPDP> Master table "SYS"."TSPITR_IMP_uhso" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_uhso":
IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
IMPDP> Job "SYS"."TSPITR_IMP_uhso" successfully completed at Fri Sep 9 13:48:07 2022 elapsed 0 00:00:01
Import completed


contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'alter tablespace DPTEST read write';
sql 'alter tablespace DPTEST offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script

sql statement: alter tablespace DPTEST read write

sql statement: alter tablespace DPTEST offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

Removing automatic instance
Automatic instance removed
auxiliary instance file /home/oracle/backup/ORCL/datafile/o1_mf_temp_kkontrrt_.tmp deleted
auxiliary instance file /home/oracle/backup/ORCL/onlinelog/o1_mf_3_kkontpgz_.log deleted
auxiliary instance file /home/oracle/backup/ORCL/onlinelog/o1_mf_2_kkontpd4_.log deleted
auxiliary instance file /home/oracle/backup/ORCL/onlinelog/o1_mf_1_kkontp1k_.log deleted
auxiliary instance file /home/oracle/backup/ORCL/datafile/o1_mf_sysaux_kkontbw9_.dbf deleted
auxiliary instance file /home/oracle/backup/ORCL/datafile/o1_mf_undotbs1_kkontbwb_.dbf deleted
auxiliary instance file /home/oracle/backup/ORCL/datafile/o1_mf_system_kkontbw8_.dbf deleted
auxiliary instance file /home/oracle/backup/ORCL/controlfile/o1_mf_kkont5h2_.ctl deleted
Finished recover at 09-SEP-22
验证数据
SQL> conn leo/leo
SQL> select tablespace_name,STATUS from user_tablespaces;

TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
DPTEST OFFLINE

6 rows selected.
SQL> alter tablespace dptest online;

Tablespace altered.

SQL> select count(*) from emp;

COUNT(*)
----------
673624
2.3.2、基于时间
a、log文件确认表空间被删时间
Sat Sep 10 23:41:57 2022
drop tablespace dptest including contents and datafiles
Deleted file /u01/app/oracle/oradata01/orcl/dptest01.dbf
Completed: drop tablespace dptest including contents and datafiles
b、
[oracle@liujun ~]$ export NLS_DATE_FORMAT=’yyyy-mm-dd hh24:mi:ss’
[oracle@liujun ~]$ export NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252
RMAN> recover tablespace dptest until time "to_date('2022-09-10 23:41:57','yyyy-mm-dd hh24:mi:ss')" auxiliary destination '/home/oracle/backup';
Starting recover at 10-SEP-22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=130 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='gFsb'

initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=gFsb_tspitr_ORCL
compatible=11.2.0.4.0
db_block_size=8192
db_files=200
sga_target=1G
processes=80
db_create_file_dest=/home/oracle/backup
log_archive_dest_1='location=/home/oracle/backup'
#No auxiliary parameter file used


starting up automatic instance ORCL

Oracle instance started

Total System Global Area 1068937216 bytes

Fixed Size 2260088 bytes
Variable Size 285213576 bytes
Database Buffers 775946240 bytes
Redo Buffers 5517312 bytes
Automatic instance created


List of tablespaces that have been dropped from the target database:
Tablespace dptest

contents of Memory Script:
{
# set requested point in time
set until time "to_date('2022-09-10 23:41:57','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';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script

executing command: SET until clause

Starting restore at 10-SEP-22
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=109 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 /home/oracle/rmanbak/4ctl_ORCL_1417dec3_1_36
channel ORA_AUX_DISK_1: piece handle=/home/oracle/rmanbak/4ctl_ORCL_1417dec3_1_36 tag=TAG20220910T233635
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/backup/ORCL/controlfile/o1_mf_kksdm6q5_.ctl
Finished restore at 10-SEP-22

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

contents of Memory Script:
{
# set requested point in time
set until time "to_date('2022-09-10 23:41:57','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 3 to new;
set newname for clone datafile 2 to new;
set newname for clone tempfile 1 to new;
set newname for datafile 5 to
"/u01/app/oracle/oradata01/orcl/dptest01.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 3, 2, 5;
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

renamed tempfile 1 to /home/oracle/backup/ORCL/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 10-SEP-22
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 00003 to /home/oracle/backup/ORCL/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/rmanbak/2dbf_ORCL_0v17deb8_1_31
channel ORA_AUX_DISK_1: piece handle=/home/oracle/rmanbak/2dbf_ORCL_0v17deb8_1_31 tag=DBFULLBACKUP
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
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 /u01/app/oracle/oradata01/orcl/dptest01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/rmanbak/2dbf_ORCL_0u17deb8_1_30
channel ORA_AUX_DISK_1: piece handle=/home/oracle/rmanbak/2dbf_ORCL_0u17deb8_1_30 tag=DBFULLBACKUP
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
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/backup/ORCL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/rmanbak/2dbf_ORCL_0t17deb8_1_29
channel ORA_AUX_DISK_1: piece handle=/home/oracle/rmanbak/2dbf_ORCL_0t17deb8_1_29 tag=DBFULLBACKUP
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 /home/oracle/backup/ORCL/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/rmanbak/2dbf_ORCL_0s17deb8_1_28
channel ORA_AUX_DISK_1: piece handle=/home/oracle/rmanbak/2dbf_ORCL_0s17deb8_1_28 tag=DBFULLBACKUP
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 10-SEP-22

datafile 1 switched to datafile copy
input datafile copy RECID=12 STAMP=1115077932 file name=/home/oracle/backup/ORCL/datafile/o1_mf_system_kksdn9cq_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=13 STAMP=1115077932 file name=/home/oracle/backup/ORCL/datafile/o1_mf_undotbs1_kksdmd4q_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=14 STAMP=1115077932 file name=/home/oracle/backup/ORCL/datafile/o1_mf_sysaux_kksdmj73_.dbf

contents of Memory Script:
{
# set requested point in time
set until time "to_date('2022-09-10 23:41:57','yyyy-mm-dd hh24:mi:ss')";
# 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";
sql clone "alter database datafile 5 online";
# recover and open resetlogs
recover clone database tablespace "DPTEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
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

sql statement: alter database datafile 5 online

Starting recover at 10-SEP-22
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 6 is already on disk as file /u01/app/oracle/archivelog/1_6_1115055578.dbf
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=5
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/rmanbak/3arc_ORCL_1317dec2_1_35
channel ORA_AUX_DISK_1: piece handle=/home/oracle/rmanbak/3arc_ORCL_1317dec2_1_35 tag=TAG20220910T233634
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/home/oracle/backup/1_5_1115055578.dbf thread=1 sequence=5
channel clone_default: deleting archived log(s)
archived log file name=/home/oracle/backup/1_5_1115055578.dbf RECID=20 STAMP=1115077933
archived log file name=/u01/app/oracle/archivelog/1_6_1115055578.dbf thread=1 sequence=6
media recovery complete, elapsed time: 00:00:00
Finished recover at 10-SEP-22

database opened

contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace DPTEST read only';
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/home/oracle/backup''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/home/oracle/backup''";
}
executing Memory Script

sql statement: alter tablespace DPTEST read only

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle/backup''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle/backup''

Performing export of metadata...
EXPDP> Starting "SYS"."TSPITR_EXP_gFsb":
EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
EXPDP> Master table "SYS"."TSPITR_EXP_gFsb" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_gFsb is:
EXPDP> /home/oracle/backup/tspitr_gFsb_82017.dmp
EXPDP> ******************************************************************************
EXPDP> Datafiles required for transportable tablespace DPTEST:
EXPDP> /u01/app/oracle/oradata01/orcl/dptest01.dbf
EXPDP> Job "SYS"."TSPITR_EXP_gFsb" successfully completed at Sat Sep 10 23:52:37 2022 elapsed 0 00:00:20
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
}
executing Memory Script

database closed
database dismounted
Oracle instance shut down

Performing import of metadata...
IMPDP> Master table "SYS"."TSPITR_IMP_gFsb" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_gFsb":
IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
IMPDP> Job "SYS"."TSPITR_IMP_gFsb" successfully completed at Sat Sep 10 23:52:46 2022 elapsed 0 00:00:01
Import completed


contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'alter tablespace DPTEST read write';
sql 'alter tablespace DPTEST offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script

sql statement: alter tablespace DPTEST read write

sql statement: alter tablespace DPTEST offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

Removing automatic instance
Automatic instance removed
auxiliary instance file /home/oracle/backup/ORCL/datafile/o1_mf_temp_kksdogsh_.tmp deleted
auxiliary instance file /home/oracle/backup/ORCL/onlinelog/o1_mf_3_kksdognw_.log deleted
auxiliary instance file /home/oracle/backup/ORCL/onlinelog/o1_mf_2_kksdogln_.log deleted
auxiliary instance file /home/oracle/backup/ORCL/onlinelog/o1_mf_1_kksdogff_.log deleted
auxiliary instance file /home/oracle/backup/ORCL/datafile/o1_mf_sysaux_kksdmj73_.dbf deleted
auxiliary instance file /home/oracle/backup/ORCL/datafile/o1_mf_undotbs1_kksdmd4q_.dbf deleted
auxiliary instance file /home/oracle/backup/ORCL/datafile/o1_mf_system_kksdn9cq_.dbf deleted
auxiliary instance file /home/oracle/backup/ORCL/controlfile/o1_mf_kksdm6q5_.ctl deleted
Finished recover at 10-SEP-22
验证数据.
SQL> conn leo/leo
SQL> select tablespace_name,STATUS from user_tablespaces;

TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
DPTEST OFFLINE

6 rows selected.
SQL> alter tablespace dptest online;

Tablespace altered.

SQL> select count(*) from emp;

COUNT(*)
----------
673624
说明:恢复前incarnation的确认需根据恢复时间来判断.
4、注意事项
a、11g或10g的TSPITR都需要遵循表空间自包含(self-contained)原则,以上测试的表空间与其它表空间均不存在依赖关系.
表空间上不能有sys用户的对象,否则将出现类似下列错误:
shutting down automatic instance
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/28/2010 05:35:34
RMAN-06136: ORACLE error from auxiliary database:
ORA-01097: cannot shutdown while in a transaction - commit or rollback first
RMAN-06962: Error received during export of metadata
RMAN-06960:
EXPDP> ORA-39123: Data Pump transportable tablespace job aborted
ORA-39187: The transportable set is not self-contained, violation list is
ORA-39917: SYS owned object COSTS in tablespace MOS not allowed in pluggable setde
b、恢复期间可能遇到”the filename for datafile %d is missing in the control file”的问题,一般是在drop表空间前没有对控制文件进行备份,导致RMAN选择还原出来的控制文件中没有该目标表空间相关数据文件的记录,恢复将被终止.
c、当TSPITR中恢复一旦终止,Oracle将删除所有辅助实例使用的临时文件.
参考网址:
http://wjhsh.net/macleanoracle-p-2967567.html