Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2767208
  • 博文数量: 389
  • 博客积分: 4177
  • 博客等级: 上校
  • 技术积分: 4773
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-16 23:29
文章分类

全部博文(389)

分类: Oracle

2013-10-24 21:49:38

                                       ORACLE TSPITR的基本过程剖析

   在表被truncate这样的情形下,使用flashback db或是整个库不完全恢复,这样影响太大
而且flashback table/query都不适用.我们可以使用在另一台机器上做不完全恢复,然后通
过exp的tts把这个表空间的所有对像都导到TARGET库上。rman提供了tablespace point
in time recovery(TSPITR)帮助我们简化了这个工作,整个过程一条命令全可以搞定,其他的
过程都由rman自动来完成
 
   看一个简单的TSPITR的恢复例子.

RMAN> recover tablespace abc
2> until time "to_date('2013-10-24 13:07:10','YYYY-MM-DD HH24:MI:SS')"
3> auxiliary destination '/home/ORACLE/abc';

表t1在13:15分被truncate,现在需要恢复回去,如果恢复整个库,影响太大.一起来看看rman是怎么做的.

1, rman创建了一个auxiliary 实例,所有文件都存放在auxiliary destination定义的地方
Creating automatic instance, with SID='cvsk'

initialization parameters used for automatic instance:

2,启动这个auxiliary实例,db_name和TARGET库一样,db_unique_name随机生成
starting up automatic instance TEST

ORACLE instance started

3,clone TARGET的controlfile,然后mount auxiliary instance

contents of Memory Script:
{

# set the until clause
set until  time "to_date('2013-10-24 13:07:10','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 for TSPITR to a resent until time
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 24-OCT-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=44 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/flash_recovery_area/TEST/autobackup/2013_10_24/o1_mf_s_829660027_96l6vvf5_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/ORACLE/flash_recovery_area/TEST/autobackup/2013_10_24/o1_mf_s_829660027_96l6vvf5_.bkp tag=TAG20131024T130707
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/abc/cntrl_TSPITR_TEST_cvsk.f
Finished restore at 24-OCT-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:
{

4,mount auxiliary instance,对TARGET的文件进行clone,再在auxliary上进行restore

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/abc/TSPITR_TEST_CVSK/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /home/ORACLE/abc/TSPITR_TEST_CVSK/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /home/ORACLE/abc/TSPITR_TEST_CVSK/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/ORACLE/flash_recovery_area/TEST/backupset/2013_10_24/o1_mf_nnndf_TAG20131024T021232_96k0jjdr_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/ORACLE/flash_recovery_area/TEST/backupset/2013_10_24/o1_mf_nnndf_TAG20131024T021232_96k0jjdr_.bkp tag=TAG20131024T021232
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
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/flash_recovery_area/TEST/datafile/o1_mf_abc_94fm08y5_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/ORACLE/c9on76rq
channel ORA_AUX_DISK_1: piece handle=/home/ORACLE/c9on76rq tag=TAG20131024T130705
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 24-OCT-13


5,接下来使用archivelog 在auxiliary instance上进行不完全介质恢复,然后以open resetlogs打开数据库
recover clone database tablespace  "ABC", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}

Starting recover at 24-OCT-13
using channel ORA_AUX_DISK_1

starting media recovery


6,接下来rman 自动使用exp/imp的tts进行表空间传输,point_in_time_recover=y tablespaces= ABC

contents of Memory Script:
{
# export the tablespaces in the recovery set
host 'exp userid =
'********'
 point_in_time_recover=y tablespaces= ABC file=
TSPITR_a.dmp';
# shutdown clone before import
shutdown clone immediate
# import the tablespaces in the recovery set
host 'imp userid =
'********'
 point_in_time_recover=y file=TSPITR_a.dmp';
# online/offline the tablespace imported
sql "alter tablespace ABC online";
sql "alter tablespace  ABC offline";
# enable autobackups in case user does open resetlogs from RMAN after TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script

7,一旦传输完成,移除auxiliry instnace,然后删除auxiliary destition处的临时文件

Removing automatic instance
Automatic instance removed
auxiliary instance file /home/ORACLE/abc/TSPITR_TEST_CVSK/onlinelog/o1_mf_3_96l7x089_.log deleted
auxiliary instance file /home/ORACLE/abc/TSPITR_TEST_CVSK/onlinelog/o1_mf_2_96l7wyqr_.log deleted
auxiliary instance file /home/ORACLE/abc/TSPITR_TEST_CVSK/onlinelog/o1_mf_1_96l7wxod_.log deleted
auxiliary instance file /home/ORACLE/abc/TSPITR_TEST_CVSK/datafile/o1_mf_temp_96l7x2wm_.tmp deleted
auxiliary instance file /home/ORACLE/abc/TSPITR_TEST_CVSK/datafile/o1_mf_sysaux_96l7v9j5_.dbf deleted
auxiliary instance file /home/ORACLE/abc/TSPITR_TEST_CVSK/datafile/o1_mf_undotbs1_96l7v9j8_.dbf deleted
auxiliary instance file /home/ORACLE/abc/TSPITR_TEST_CVSK/datafile/o1_mf_system_96l7v9j6_.dbf deleted
auxiliary instance file /home/ORACLE/abc/cntrl_TSPITR_TEST_cvsk.f deleted
Finished recover at 24-OCT-13

8,在TARGET的库上手动把tablespace online。

阅读(9264) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~