TSPITR:Tablespace Point-in-Time Recovery实例

一。基本要求:

1.Target time: 
The point in time or SCN that the tablespace will be recovered to
2.Recovery set: 
Datafiles that compose the tablespaces to be recovered
3.Auxiliary set: 
Datafiles required for the TSPITR of the recovery set that are not part of the recovery set. It typically includes:
SYSTEM tablespace
Rollback or undo segment tablespaces
Temporary tablespace

Auxiliary destination: 
Disk location to store files,必须是本地磁盘
如果不是将报错,如下:
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/01/2013 16:36:56
RMAN-04014: startup failed: ORA-01261: Parameter db_create_file_dest destination string cannot be translated


4.要恢复的表空间不能是default tablespace
否则报错如下:
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/01/2013 17:32:21
RMAN-03015: error occurred in stored script Memory Script
RMAN-03009: failure of sql command on default channel at 07/01/2013 17:32:18
RMAN-11003: failure during parse/execution of SQL statement: drop tablespace  USERS including contents keep datafiles
ORA-12919: Can not drop the default permanent tablespace
解决办法:更改默认表空间。
SQL> create tablespace data datafile '+DATA1/tantest/datafile/data01.dbf' size 10m;
SQL> alter database default tablespace data;


5.数据库必须要有全备
6.数据删除前,至少相应表空间要有备份 。




二 。实例测试:



SQL> select * from scott.tt1;
         ID
-----------
        111
        111
        111
        111




1.备份

RMAN> run {
allocate channel c1 type disk;
backup tag ts_test
format '+FRI/bak/ts_t%t_%s.bkp'
tablespace users;
backup current controlfile;
release channel c1;
}



using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=44 instance=tantest1 device type=DISK


Starting backup at 01-JUL-13
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA1/tantest/datafile/users.259.816103443
channel c1: starting piece 1 at 01-JUL-13
channel c1: finished piece 1 at 01-JUL-13
piece handle=+FRI/bak/ts_t819649933_94.bkp tag=TS_TEST comment=NONE
channel c1: backup set complete, elapsed time: 00:00:03
Finished backup at 01-JUL-13


Starting backup at 01-JUL-13
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
channel c1: starting piece 1 at 01-JUL-13
channel c1: finished piece 1 at 01-JUL-13
piece handle=/u01/flashback/TANTEST/backupset/2013_07_01/o1_mf_ncnnf_TAG20130701T163223_8x2hnv3m_.bkp tag=TAG20130701T163223 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:02
Finished backup at 01-JUL-13


released channel: c1


RMAN> 
记录个时间:
SQL> select sysdate from dual;


SYSDATE
-------------------
2013.07.02 17:00:02


2.删除:

delete from scott.tt1;
commit;




The TS_PITR_CHECK view lets you identify relationships between objects that span the recovery set boundaries. If this view returns rows when queried, then investigate and correct the problem. Proceed with TSPITR only when TS_PITR_CHECK view returns no rows for the tablespaces not in the recovery set. Record all actions performed during this step so that you can re-create any suspended or removed relationships after completing TSPITR.
用TS_PITR_CHECK视图检查表空间是否可做传送
SELECT * FROM SYS.TS_PITR_CHECK
WHERE (TS1_NAME IN ('USERS')
   AND TS2_NAME NOT IN ('USERS'))
OR (TS1_NAME NOT IN ('USERS')
AND TS2_NAME IN ('USERS'));




To see which objects will be lost in TSPITR, query the TS_PITR_OBJECTS_TO_BE_DROPPED view on the primary database. 
查询哪些对象会丢失。
SELECT OWNER, NAME, TABLESPACE_NAME,
TO_CHAR(CREATION_TIME, 'YYYY-MM-DD:HH24:MI:SS')
FROM TS_PITR_OBJECTS_TO_BE_DROPPED
WHERE TABLESPACE_NAME IN ('USERS')
AND CREATION_TIME > 
    TO_DATE('2013-07-03:17:00:00','YY-MM-DD:HH24:MI:SS')
ORDER BY TABLESPACE_NAME, CREATION_TIME;

3.进行恢复:


RMAN> run {   
recover tablespace users until time "to_date('2013-7-2 17:00','yyyy-mm-dd hh24:mi')"
auxiliary destination '/u01/bak';
}

整个恢复的过程自动完成。恢复过程是按时间点先恢复到auxiliary库上,然后再从axiliary将要恢复的表空间通过“传输表空间”的方法传送回来。

下面的恢复的过程:

RMAN> run {   
recover tablespace users until time "to_date('2013-7-2 16:00','yyyy-mm-dd hh24:m2> i')"
auxiliary destination '/u01/bak';
}3> 4> 

Starting recover at 02-JUL-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=139 instance=tantest1 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
Tablespace UNDOTBS2

Creating automatic instance, with SID='euui'

initialization parameters used for automatic instance:
db_name=TANTEST
db_unique_name=euui_tspitr_TANTEST
compatible=11.2.0.0.0
db_block_size=8192
db_files=200
sga_target=280M
processes=50
db_create_file_dest=/u01/bak
log_archive_dest_1='location=/u01/bak'
#No auxiliary parameter file used


starting up automatic instance TANTEST

Oracle instance started

Total System Global Area     292278272 bytes

Fixed Size                     2227744 bytes
Variable Size                104858080 bytes
Database Buffers             180355072 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('2013-7-2 16:00','yyyy-mm-dd hh24:mi')";
# 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 02-JUL-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=62 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 +FRI/bak/full_36odo9rk_1_1.bkp
channel ORA_AUX_DISK_1: piece handle=+FRI/bak/full_36odo9rk_1_1.bkp tag=TAG20130702T155811
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:08
output file name=/u01/bak/TANTEST/controlfile/o1_mf_8x52w4rp_.ctl
Finished restore at 02-JUL-13

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('2013-7-2 16:00','yyyy-mm-dd hh24:mi')";
plsql <<<-- tspitr_2
declare
  sqlstatement       varchar2(512);
  offline_not_needed exception;
  pragma exception_init(offline_not_needed, -01539);
begin
  sqlstatement := 'alter tablespace '||  'USERS' ||' 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  5 to new;
set newname for clone datafile  2 to new;
set newname for clone tempfile  1 to new;
set newname for datafile  4 to 
 "+DATA1/tantest/datafile/users.259.816103443";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 3, 5, 2, 4;
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

sql statement: alter tablespace USERS 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 /u01/bak/TANTEST/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 02-JUL-13
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 /u01/bak/TANTEST/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/bak/TANTEST/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/bak/TANTEST/datafile/o1_mf_undotbs2_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/bak/TANTEST/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to +DATA1/tantest/datafile/users.259.816103443
channel ORA_AUX_DISK_1: reading from backup piece +FRI/bak/full_35odo9ok_1_1.bkp
channel ORA_AUX_DISK_1: piece handle=+FRI/bak/full_35odo9ok_1_1.bkp tag=TAG20130702T155811
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:02:15
Finished restore at 02-JUL-13

datafile 1 switched to datafile copy
input datafile copy RECID=6 STAMP=819735344 file name=/u01/bak/TANTEST/datafile/o1_mf_system_8x52wzs7_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=819735344 file name=/u01/bak/TANTEST/datafile/o1_mf_undotbs1_8x52wzsg_.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=8 STAMP=819735345 file name=/u01/bak/TANTEST/datafile/o1_mf_undotbs2_8x52wzsp_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=9 STAMP=819735345 file name=/u01/bak/TANTEST/datafile/o1_mf_sysaux_8x52wzpk_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2013-7-2 16:00','yyyy-mm-dd hh24:mi')";
# 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  5 online";
sql clone "alter database datafile  2 online";
sql clone "alter database datafile  4 online";
# recover and open resetlogs
recover clone database tablespace  "USERS", "SYSTEM", "UNDOTBS1", "UNDOTBS2", "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  5 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  4 online

Starting recover at 02-JUL-13
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 179 is already on disk as file +FRI/tantest/arch1/1_179_816103580.dbf
archived log for thread 2 with sequence 125 is already on disk as file +FRI/tantest/arch2/2_125_816103580.dbf
archived log file name=+FRI/tantest/arch1/1_179_816103580.dbf thread=1 sequence=179
archived log file name=+FRI/tantest/arch2/2_125_816103580.dbf thread=2 sequence=0
media recovery complete, elapsed time: 00:00:02
Finished recover at 02-JUL-13

database opened

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

sql statement: alter tablespace  USERS read only

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/bak''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/bak''

Performing export of metadata...
   EXPDP> Starting "SYS"."TSPITR_EXP_euui":  
   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/CONSTRAINT/REF_CONSTRAINT
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   EXPDP> Master table "SYS"."TSPITR_EXP_euui" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_euui is:
   EXPDP>   /u01/bak/tspitr_euui_97863.dmp
   EXPDP> ******************************************************************************
   EXPDP> Datafiles required for transportable tablespace USERS:
   EXPDP>   +DATA1/tantest/datafile/users.259.816103443
   EXPDP> Job "SYS"."TSPITR_EXP_euui" successfully completed at 16:21:00
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
# drop target tablespaces before importing them back
sql 'drop tablespace  USERS including contents keep datafiles';
}
executing Memory Script

database closed
database dismounted
Oracle instance shut down

sql statement: drop tablespace  USERS including contents keep datafiles

Performing import of metadata...
   IMPDP> Master table "SYS"."TSPITR_IMP_euui" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_euui":  
   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/CONSTRAINT/REF_CONSTRAINT
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   IMPDP> Job "SYS"."TSPITR_IMP_euui" successfully completed at 16:23:34
Import completed


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

sql statement: alter tablespace  USERS read write

sql statement: alter tablespace  USERS offline

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

Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/bak/TANTEST/datafile/o1_mf_temp_8x532pxs_.tmp deleted
auxiliary instance file /u01/bak/TANTEST/onlinelog/o1_mf_4_8x5329gx_.log deleted
auxiliary instance file /u01/bak/TANTEST/onlinelog/o1_mf_3_8x5328cq_.log deleted
auxiliary instance file /u01/bak/TANTEST/onlinelog/o1_mf_2_8x5326jz_.log deleted
auxiliary instance file /u01/bak/TANTEST/onlinelog/o1_mf_1_8x5324r2_.log deleted
auxiliary instance file /u01/bak/TANTEST/datafile/o1_mf_sysaux_8x52wzpk_.dbf deleted
auxiliary instance file /u01/bak/TANTEST/datafile/o1_mf_undotbs2_8x52wzsp_.dbf deleted
auxiliary instance file /u01/bak/TANTEST/datafile/o1_mf_undotbs1_8x52wzsg_.dbf deleted
auxiliary instance file /u01/bak/TANTEST/datafile/o1_mf_system_8x52wzs7_.dbf deleted
auxiliary instance file /u01/bak/TANTEST/controlfile/o1_mf_8x52w4rp_.ctl deleted
Finished recover at 02-JUL-13

RMAN> 


你可能感兴趣的:(TSPITR:Tablespace Point-in-Time Recovery实例)