Oracle 表空间时点恢复(TSPITR)

  1. 云栖社区>
  2. 博客>
  3. 正文

Oracle 表空间时点恢复(TSPITR)

leshami 2017-04-25 09:15:43 浏览547
展开阅读全文

表空间时点恢复,是Oracle在基于冷备,热备恢复以外的一种以表空间为粒度的,不完全恢复的形式来将表空间恢复到过去某个特定的时间点的一种恢复方式。它整合了RMAN以及DataPump这2个备份恢复工具来实现时点恢复。那它具体的过程和逻辑是怎样的?下文是其具体的描述。

一、什么是表空间时点恢复

Oracle表空间时点恢复有2个需要理解的概念。

  • 恢复粒度

  表空间级别,也就是说恢复的粒度是以表空间为单位

  • 时点恢复

  时点恢复意味着是一个不完全恢复。也就是说可以把某个或几个表空间恢复到过去的特定时间点,进行视点恢复的表空间可以与数据库中现有的其他表空间不在同一个时间线上。

二、适用场景

表空间时点恢复适用用以下场景:

  错误的批处理作业或数据操作语言DML

  恢复数据定义语言(DDL)后丢失的数据操作,改变表的结构。不能使用闪回表将表倒回结构更改点之前,例如截断表(truncate)操作。

  恢复drop时使用了purge选项的表

  恢复存在逻辑错误的表

  恢复被删除的表空间,RMAN可以在被drop的表空间上面执行TSPITR

与全库级别闪回相比,表空间时点恢复停留在表空间级别,影响较全库闪回较小。其次,数据库闪回功能需要承担维护闪回日志开启的相关性能开销。

三、实现表空间时点恢复的前提及限制

要实现表空间的时点恢复有以下前提,同时也存在一些限制,如下:

  1.存在有效可用的备份

  2.数据库处于归档模式

  3.表空间上存在约束关系(依赖)表的情形,依赖关系所在的表空间也需要一同做时点恢复(如外键参照,不在同一时点,则违反参照约束)

  4.对于索引与数据分离的表空间在时点恢复时,应先删除索引

  5.不能恢复数据库当前的缺省表空间

  6.不能恢复以下对象:

    存在依赖关系的物化视图,分区表等(如果要恢复,先解决依赖)

    undo表空间,undo段

    sys模式下的对象(如PL/SQL,views, synonyms, users…)

四、表空间时点恢复的相关术语

Target instance

  目标实例,即需要恢复的表空间的实例

Target time

  要恢复的目标时间点或者scn

Auxiliary instance

  是一个Oracle实例,用来完成各种恢复表空间工作的实例。辅助实例需要有其关联的文件。

Auxiliary destination

  用来临时存储辅助实例相关文件的辅助目录。

Recovery set

  恢复集合,需要恢复的表空间中的数据文件

Auxiliary set

  辅助实例的其他文件集合。如system,sysaux,undo,临时表空间,原数据库控制文件,归档日志文件,联机重做日志文件等
(不包括参数文件,密码文件,网络文件)

五、表空间时点恢复TSPITR 结构图

这里写图片描述

六、表空间时点恢复的几种模式

  • 全自动(缺省)

  在这个模式中,RMAN管理整个不完全恢复过程包括辅助实例。默认的模式是最省事的。除非你特别需要在TSPITR过程中可以有更多控制,诸如控制恢复集文件目录,通道设置、参数或辅助实例实例相关设置。如下示例:

rman target /
RMAN> recover tablespace users, tools
until logseq 1300 thread 1
-- until time "to_date( '2017-04-18 16:05:07', 'yyyy-mm-dd hh24:mi:ss')"
auxiliary destination '/disk1/auxdest';
  • 半自动(辅助实例使用用户自定义的设置)
run
{
   set newname for datafile '?/oracle_home/oradata/trgt/users01.dbf'
   to '/newfs/users01.dbf';
   ...other set newname commands...
   recover tablespace users, tools until sequence 1300 thread 1;
}

  如可以设置辅助集位置,恢复集文件

  初始化参数

  • 手动

  该方式需要人为管理整个TSPITR的方方面。比如需要为用户托管的辅助实例分配不同数量的通道或更改通道参数,则使用此模式。

run
{
# specify newname for recovery set data files
  set newname for tablespace clients
                        to '?/oradata/prod/rec/%b';

# specify newnames for some auxiliary set
# data files that have a valid image copy to avoid restores:
  set newname for datafile '?/oradata/prod/system01.dbf'
                        to '/backups/prod/system01_monday_noon.dbf';
  set newname for datafile '?/oradata/prod/system02.dbf'
                        to '/backups/prod/system02_monday_noon.dbf';
  set newname for datafile '?/oradata/prod/sysaux01.dbf'
                        to '/backups/prod/sysaux01_monday_noon.dbf';
  set newname for datafile '?/oradata/prod/undo01.dbf'
                        to '/backups/prod/undo01_monday_noon.dbf';

# specify the types of channels to use
  allocate auxiliary channel c1 device type disk;
  allocate auxiliary channel t1 device type sbt;

# recover the clients tablespace to 24 hours ago:
  recover tablespace clients until time 'sysdate-1';
}

七、表空间时点恢复TSPITR原理及步骤

  1.自包含检查,也就是检查是否存在依赖性。执行DBMS_TTS.TRANSPORT_SET_CHECK后,查看视图TRANSPORT_SET_VIOLATIONS,如果有记录被返回,则需要先解决依赖。

  2.检查是否连接到一个用户管理的辅助实例,否则RMAN将创建一个辅助实例,启动并连接到辅助实例。

  3.在目标数据库中将要被恢复的表空间置于脱机状态。

  4.对辅助实例使用恢复目标时间之前的控制文件备份来还原控制文件。

  5.从恢复集和辅助集中将数据文件还原到辅助实例。还原的数据文件可以存储在你指定的目录中或者是文件的原始目录中(对于恢复集文件)或者在辅助目录中(对于辅助集文件,如果你使用了有auxliary destination参数的recover tablespace命令)。

  6.在辅助实例中将数据文件还原和恢复到指定的目标时间点。

  7.使用resetlogs选项将辅助实例打开

  8.将辅助实例上恢复集表空间置为只读模式

  9.使用DataPump从辅助实例导出恢复集表空间产生一个传输表空间dump文件

  10.关闭辅助实例

  11.从目标实例删除恢复集表空间(即需要进行时点还原的表空间)

  12.DataPump程序将使用传输表空间方式将dump文件导入到目标数据库

  13.将导入到目标数据库的表空间置为读/写并立即离线

  14.删除所有辅助集数据文件

八、演示表空间时点恢复

-- 演示环境
SQL> select * from v$version where rownum<2;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

SQL> select 'Leshami' Author,'http://blog.csdn.net/leshami' Blog,
  2  '645746311' QQ from dual;

AUTHOR  BLOG                         QQ
------- ---------------------------- ---------
Leshami http://blog.csdn.net/leshami 645746311

--查看数据库归档模式
SQL> select log_mode from v$database;

LOG_MODE
------------
ARCHIVELOG

--创建2个用于测试TSPITR的表空间
SQL> create tablespace tbs_tspitr1 datafile '/app/oracle/ora11g/oradata/ora11g/tbs_tspitr1.dbf' size 20m;

SQL> create tablespace tbs_tspitr2 datafile '/app/oracle/ora11g/oradata/ora11g/tbs_tspitr2.dbf' size 20m;

--创建测试用户并授权
SQL> create user usr_tbspitr identified by usr_tbspitr;

SQL> grant dba to usr_tbspitr;

SQL> conn usr_tbspitr/usr_tbspitr

--创建用于测试的表,将数据存放到tbs_tspitr1表空间
SQL> create table tb_emp tablespace tbs_tspitr1 as select * from scott.emp;

--将索引存放到表空间tbs_tspitr2上
SQL> create unique index pk_tb_emp on tb_emp(empno) tablespace tbs_tspitr2;

SQL> alter table tb_emp add primary key(empno) using index pk_tb_emp;

SQL> select count(*) from tb_emp;

  COUNT(*)
----------
        14

--准备辅助实例环境及备份数据库       
$ mkdir /tmp/tempbak
$ rman target /
RMAN> configure controlfile autobackup on;
RMAN> backup database format '/tmp/tempbak/db_%d_full_%U' plus archivelog;

SQL> set time on;

--此时turncate表tb_emp
14:17:05 SQL> truncate table tb_emp;

SQL> set time off;

--在表空间tbs_tspitr2上创建另外的一张表tb_dept
SQL> create table tb_dept tablespace tbs_tspitr2 as select * from scott.dept;

SQL> select count(*) from tb_dept;

  COUNT(*)
----------
         4

--添加索引
SQL> create unique index pk_tb_dept on tb_dept(deptno) tablespace tbs_tspitr2;

--添加主键约束
SQL> alter table tb_dept add primary key(deptno) using index pk_tb_dept;

--为表tb_emp添加外键
SQL> alter table tb_emp add constraint fk_tb_dept foreign key(deptno)
 2 >  references tb_dept(deptno);

$ mkdir -pv /tmp/aux

RMAN> recover tablespace tbs_tspitr1
            until time "to_date( '2017-04-19 14:17:05', 'yyyy-mm-dd hh24:mi:ss')"
            auxiliary destination '/tmp/aux';

--提示违反约束,如下
Running TRANSPORT_SET_CHECK on recovery set tablespaces
The following errors need to be fixed before peforming this command
     Violation: ORA-39906: Constraint FK_TB_DEPT between table USR_TBSPITR.TB_DEPT
         in tablespace TBS_TSPITR2 and table USR_TBSPITR.TB_EMP in tablespace TBS_TSPITR1.
     Violation: ORA-39908: Index USR_TBSPITR.PK_TB_EMP in tablespace TBS_TSPITR2 enforces
         primary constraints  of table USR_TBSPITR.TB_EMP in tablespace TBS_TSPITR1.

--下面使用DBMS_TTS检查自包含        
SQL> conn / as sysdba

SQL> BEGIN
  2     DBMS_TTS.TRANSPORT_SET_CHECK('TBS_TSPITR1', TRUE,TRUE);
  3  END;
  4  /

PL/SQL procedure successfully completed.

--下面的错误提示跟在RMAN执行时一致
SQL> SELECT * FROM  TRANSPORT_SET_VIOLATIONS;

VIOLATIONS
--------------------------------------------------------------------------------
ORA-39906: Constraint FK_TB_DEPT between table USR_TBSPITR.TB_DEPT in tablespace
TBS_TSPITR2 and table USR_TBSPITR.TB_EMP in tablespace TBS_TSPITR1.

ORA-39908: Index USR_TBSPITR.PK_TB_EMP in tablespace TBS_TSPITR2 enforces primary
 constraints  of table USR_TBSPITR.TB_EMP in tablespace TBS_TSPITR1.

--下面将TBS_TSPITR2表空间也增加到自包含检查中
SQL> BEGIN                                                                      
  2     DBMS_TTS.TRANSPORT_SET_CHECK('TBS_TSPITR1,TBS_TSPITR2', TRUE,TRUE);
  3  END;                                                                       
  4  /                                                                          

PL/SQL procedure successfully completed.

--下面的查询结果为空,也就是上面的2个表空同时做时点恢复具备成功的可能
SQL> SELECT * FROM  TRANSPORT_SET_VIOLATIONS;

no rows selected

--将表空间tbs_tspitr2也加入到时点恢复中,再次执行rman
RMAN> recover tablespace tbs_tspitr1,tbs_tspitr2
2> until time "to_date( '2017-04-19 14:17:05', 'yyyy-mm-dd hh24:mi:ss')"
3> auxiliary destination '/tmp/aux';

Starting recover at 19-APR-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=162 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='bjmm'  --自动创建一个辅助实例

--以下是辅助实例的初始化参数
initialization parameters used for automatic instance:
db_name=ORA11G
db_unique_name=bjmm_tspitr_ORA11G
compatible=11.2.0.0.0
db_block_size=8192
db_files=200
sga_target=280M
processes=50
db_create_file_dest=/tmp/aux
log_archive_dest_1='location=/tmp/aux'
#No auxiliary parameter file used

--启动辅助实例
starting up automatic instance ORA11G  

Oracle instance started

Total System Global Area     292278272 bytes

Fixed Size                     2227744 bytes
Variable Size                100663776 bytes
Database Buffers             184549376 bytes
Redo Buffers                   4837376 bytes
Automatic instance created
Running TRANSPORT_SET_CHECK on recovery set tablespaces
TRANSPORT_SET_CHECK completed successfully

--执行脚本,还原控制文件,
contents of Memory Script:
{
# set requested point in time
set until  time "to_date( '2017-04-19 14:17:05', '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 19-APR-17
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=42 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 /app/oracle/ora11g/fast_recovery_area
      /ORA11G/autobackup/2017_04_19/o1_mf_s_941724971_dhg05dw1_.bkp
channel ORA_AUX_DISK_1: piece handle=/app/oracle/ora11g/fast_recovery_area/ORA11G/autobackup
      /2017_04_19/o1_mf_s_941724971_dhg05dw1_.bkp tag=TAG20170419T141611
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/aux/ORA11G/controlfile/o1_mf_dhg48bwc_.ctl
Finished restore at 19-APR-17

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( '2017-04-19 14:17:05', 'yyyy-mm-dd hh24:mi:ss')";
plsql <<<-- tspitr_2
declare
  sqlstatement       varchar2(512);
  offline_not_needed exception;
  pragma exception_init(offline_not_needed, -01539);
begin
  sqlstatement := 'alter tablespace '||  'TBS_TSPITR1' ||' offline immediate';
  krmicd.writeMsg(6162, sqlstatement);
  krmicd.execSql(sqlstatement);
exception
  when offline_not_needed then
    null;
end; >>>;
plsql <<<-- tspitr_2
declare
  sqlstatement       varchar2(512);
  offline_not_needed exception;
  pragma exception_init(offline_not_needed, -01539);
begin
  sqlstatement := 'alter tablespace '||  'TBS_TSPITR2' ||' offline immediate';
  krmicd.writeMsg(6162, sqlstatement);
  krmicd.execSql(sqlstatement);
exception
  when offline_not_needed then
    null;
end; >>>;
# 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  6 to
"/app/oracle/ora11g/oradata/ora11g/tbs_tspitr1.dbf";
set newname for datafile  7 to
"/app/oracle/ora11g/oradata/ora11g/tbs_tspitr2.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, 6, 7;
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

sql statement: alter tablespace TBS_TSPITR1 offline immediate

sql statement: alter tablespace TBS_TSPITR2 offline immediate

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/aux/ORA11G/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 19-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/aux/ORA11G/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /tmp/aux/ORA11G/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /tmp/aux/ORA11G/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /app/oracle/ora11g/oradata/ora11g/tbs_tspitr1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00007 to /app/oracle/ora11g/oradata/ora11g/tbs_tspitr2.dbf
channel ORA_AUX_DISK_1: reading from backup piece /tmp/tempbak/db_ORA11G_full_02s2358q_1_1
channel ORA_AUX_DISK_1: piece handle=/tmp/tempbak/db_ORA11G_full_02s2358q_1_1 tag=TAG20170419T141554
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 19-APR-17

datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=941729186 file name=/tmp/aux/ORA11G/datafile/o1_mf_system_dhg48m17_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=941729186 file name=/tmp/aux/ORA11G/datafile/o1_mf_undotbs1_dhg48m2y_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=7 STAMP=941729186 file name=/tmp/aux/ORA11G/datafile/o1_mf_sysaux_dhg48m25_.dbf

--将辅助实例相关数据文件联机,做介质恢复,最后以resetlogs方式打开数据库
contents of Memory Script:
{
# set requested point in time
set until  time "to_date( '2017-04-19 14:17:05', '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  6 online";
sql clone "alter database datafile  7 online";
# recover and open resetlogs
recover clone database tablespace  "TBS_TSPITR1", "TBS_TSPITR2", "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  6 online

sql statement: alter database datafile  7 online

Starting recover at 19-APR-17
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 8 is already on disk as file
  /app/oracle/ora11g/fast_recovery_area/ORA11G/archivelog/2017_04_19/o1_mf_1_8_dhg05b87_.arc
archived log for thread 1 with sequence 9 is already on disk as file
  /app/oracle/ora11g/fast_recovery_area/ORA11G/archivelog/2017_04_19/o1_mf_1_9_dhg48kow_.arc
archived log file name=/app/oracle/ora11g/fast_recovery_area/ORA11G
  /archivelog/2017_04_19/o1_mf_1_8_dhg05b87_.arc thread=1 sequence=8
archived log file name=/app/oracle/ora11g/fast_recovery_area/ORA11G
  /archivelog/2017_04_19/o1_mf_1_9_dhg48kow_.arc thread=1 sequence=9
media recovery complete, elapsed time: 00:00:01
Finished recover at 19-APR-17

database opened

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

sql statement: alter tablespace  TBS_TSPITR1 read only

sql statement: alter tablespace  TBS_TSPITR2 read only

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

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

--基于上面创建的目录实现表空间传输导出到dump文件
Performing export of metadata...
   EXPDP> Starting "SYS"."TSPITR_EXP_bjmm": 
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX/INDEX
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/CONSTRAINT
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   EXPDP> Master table "SYS"."TSPITR_EXP_bjmm" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_bjmm is:
   EXPDP>   /tmp/aux/tspitr_bjmm_39061.dmp
   EXPDP> ******************************************************************************
   EXPDP> Datafiles required for transportable tablespace TBS_TSPITR1:
   EXPDP>   /app/oracle/ora11g/oradata/ora11g/tbs_tspitr1.dbf
   EXPDP> Datafiles required for transportable tablespace TBS_TSPITR2:
   EXPDP>   /app/oracle/ora11g/oradata/ora11g/tbs_tspitr2.dbf
   EXPDP> Job "SYS"."TSPITR_EXP_bjmm" successfully completed at 15:26:53
Export completed

--删除目标数据库源表空间
contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
# drop target tablespaces before importing them back
sql 'drop tablespace  TBS_TSPITR1 including contents keep datafiles';
sql 'drop tablespace  TBS_TSPITR2 including contents keep datafiles';
}
executing Memory Script

database closed
database dismounted
Oracle instance shut down

sql statement: drop tablespace  TBS_TSPITR1 including contents keep datafiles

sql statement: drop tablespace  TBS_TSPITR2 including contents keep datafiles

--导入表空间
Performing import of metadata...
   IMPDP> Master table "SYS"."TSPITR_IMP_bjmm" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_bjmm": 
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX/INDEX
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/CONSTRAINT
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   IMPDP> Job "SYS"."TSPITR_IMP_bjmm" successfully completed at 15:27:15
Import completed

--将表空间联机然后迅速脱机
contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'alter tablespace  TBS_TSPITR1 read write';
sql 'alter tablespace  TBS_TSPITR1 offline';
sql 'alter tablespace  TBS_TSPITR2 read write';
sql 'alter tablespace  TBS_TSPITR2 offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script

sql statement: alter tablespace  TBS_TSPITR1 read write

sql statement: alter tablespace  TBS_TSPITR1 offline

sql statement: alter tablespace  TBS_TSPITR2 read write

sql statement: alter tablespace  TBS_TSPITR2 offline

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

--移除辅助实例产生的相关文件,完成时点恢复
Removing automatic instance
Automatic instance removed
auxiliary instance file /tmp/aux/ORA11G/datafile/o1_mf_temp_dhg499bd_.tmp deleted
auxiliary instance file /tmp/aux/ORA11G/onlinelog/o1_mf_3_dhg497cw_.log deleted
auxiliary instance file /tmp/aux/ORA11G/onlinelog/o1_mf_2_dhg496fz_.log deleted
auxiliary instance file /tmp/aux/ORA11G/onlinelog/o1_mf_1_dhg495d4_.log deleted
auxiliary instance file /tmp/aux/ORA11G/datafile/o1_mf_sysaux_dhg48m25_.dbf deleted
auxiliary instance file /tmp/aux/ORA11G/datafile/o1_mf_undotbs1_dhg48m2y_.dbf deleted
auxiliary instance file /tmp/aux/ORA11G/datafile/o1_mf_system_dhg48m17_.dbf deleted
auxiliary instance file /tmp/aux/ORA11G/controlfile/o1_mf_dhg48bwc_.ctl deleted
Finished recover at 19-APR-17

--备份一下时点恢复后的表空调
RMAN> backup tablespace tbs_tspitr1,tbs_tspitr2 format '/tmp/tempbak/tbs_%d_%U';

-- RMAN时点恢复期间,可以查看到辅助实例的bjmm pmon进程
$ ps -ef|grep pmon
oracle   16911     1  0 15:25 ?        00:00:00 ora_pmon_bjmm
oracle   22747     1  0 09:03 ?        00:00:03 ora_pmon_ora11g

--辅助实例目录下产生了相关文件
$ ls -hltr /tmp/aux
total 8.0K
drwxr-x---. 5 oracle oinstall 4.0K Apr 19 15:26 ORA11G
-rw-r-----. 1 oracle oinstall 4.0K Apr 19 15:26 tspitr_bjmm_39061.dmp

--查看还原后的表空间
SQL> select tablespace_name,status from dba_tablespaces where tablespace_name like '%TSPI%';

TABLESPACE_NAME                STATUS
------------------------------ ---------
TBS_TSPITR1                    OFFLINE
TBS_TSPITR2                    OFFLINE

--将其联机
SQL> alter tablespace TBS_TSPITR1 online;

SQL> alter tablespace TBS_TSPITR2 online;

SQL> conn usr_tbspitr/usr_tbspitr

--验证结果,truncate的表tb_emp被找回
SQL> select count(*) from tb_emp;

  COUNT(*)
----------
        14

--通过下面的查询可以得知,表空间TBS_TSPITR2上的对象丢失
SQL> select count(*) from tb_dept;
select count(*) from tb_dept
                     *
ERROR at line 1:
ORA-00942: table or view does not exist

DBA牛鹏社(SQL/NOSQL/LINUX)


这里写图片描述

网友评论

登录后评论
0/500
评论
leshami
+ 关注