使用rman tspitr恢复被删除的数据或表

本文主要目的是学习使用rman tspitr恢复被删除数据。
环境Win2000、Oracle10201
一、在测试表中插入数据
C:Documents and SettingsAdministrator.XY>set oracle_sid=orcl
C:Documents and SettingsAdministrator.XY>sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 2月 13 15:49:52 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> conn test1/test1
已连接。
SQL> insert into t select * from dba_objects;
已创建50361行。
SQL> commit;
提交完成。
SQL> select count(*) from t;
COUNT(*)
----------
50361
SQL>
二、备份数据库
C:Documents and SettingsAdministrator.XY>rman target/
恢复管理器: Release 10.2.0.1.0 - Production on 星期二 2月 13 15:51:45 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
连接到目标数据库: ORCL (DBID=1140649303)
RMAN> backup database format 'd:%s.bak';
启动 backup 于 13-2月 -07
使用通道 ORA_DISK_1
通道 ORA_DISK_1: 启动全部数据文件备份集
通道 ORA_DISK_1: 正在指定备份集中的数据文件
输入数据文件 fno=00001 name=D:ORACLEPRODUCT10.2.0ORADATAORCLSYSTEM01.DBF
输入数据文件 fno=00003 name=D:ORACLEPRODUCT10.2.0ORADATAORCLSYSAUX01.DBF
输入数据文件 fno=00005 name=D:ORACLEPRODUCT10.2.0ORADATAORCLEXAMPLE01.DBF
输入数据文件 fno=00002 name=D:ORACLEPRODUCT10.2.0ORADATAORCLUNDOTBS01.DBF
输入数据文件 fno=00006 name=D:ORACLEPRODUCT10.2.0ORADATAORCLTEST01.DBF
输入数据文件 fno=00004 name=D:ORACLEPRODUCT10.2.0ORADATAORCLUSERS01.DBF
通道 ORA_DISK_1: 正在启动段 1 于 13-2月 -07
通道 ORA_DISK_1: 已完成段 1 于 13-2月 -07
段句柄=D:51.BAK 标记=TAG20070213T155246 注释=NONE
通道 ORA_DISK_1: 备份集已完成, 经过时间:00:01:06
通道 ORA_DISK_1: 启动全部数据文件备份集
通道 ORA_DISK_1: 正在指定备份集中的数据文件
备份集中包括当前控制文件
在备份集中包含当前的 SPFILE
通道 ORA_DISK_1: 正在启动段 1 于 13-2月 -07
通道 ORA_DISK_1: 已完成段 1 于 13-2月 -07
段句柄=D:52.BAK 标记=TAG20070213T155246 注释=NONE
通道 ORA_DISK_1: 备份集已完成, 经过时间:00:00:08
完成 backup 于 13-2月 -07
RMAN>
三、删除表
C:Documents and SettingsAdministrator.XY>sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 2月 13 15:57:40 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> conn test1/test1
已连接。
SQL> drop table t;
表已删除。
SQL>

四、创建辅助实例(auxiliary instance)
C:Documents and SettingsAdministrator.XY>oradim -NEW -SID auxdb
创建辅助实例的密码文件
创建辅助实例的参数文件
#DB_FILE_NAME_CONVERT('target database','auxiliary database')
*.db_name=orcl #(the same to the target database)
*.db_unique_name=auxdb
*.DB_FILE_NAME_CONVERT=('d:oracleproduct10.2.0oradataorcl','d:test')
*.LOG_FILE_NAME_CONVERT=('d:oracleproduct10.2.0oradataorcl','d:test')
*.control_files='D:testCONTROLT01.CTL','D:testCONTROLT02.CTL','D:testCONTROLT03.CTL'
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
*.compatible='10.2.0.1.0'
*.db_block_size=8192
*.sga_target=250000000
background_dump_dest=d:testbdump
core_dump_dest=d:testcdump
user_dump_dest=d:testudump
以nomount方式打开
五、使用rman tspitr恢复数据
C:Documents and SettingsAdministrator.XY>rman target sys/oracle@orcl auxiliary
sys/aux@aux
恢复管理器: Release 10.2.0.1.0 - Production on 星期二 2月 13 16:00:43 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
连接到目标数据库: ORCL (DBID=1140649303)
已连接到辅助数据库: ORCL (未装载)
RUN{
allocate auxiliary channel c1 type disk;
set newname for datafile 6 to 'd:testtest01.dbf';
recover tablespace 'TEST1' until time "to_date('2007-02-13 15:57:40' , 'yyyy-mm-dd hh24:mi:ss')" AUXILIARY DESTINATION 'd:testtest01.dbf';
}
如果不设置set newname for datafile 6 to 'd:testtest01.dbf'; 默认将恢复到原来所在位置。
也可以使用如下语句来将datafile 6的位置指定到另一个目录下
recover tablespace 'TEST1' until time "to_date('2007-02-13 15:57:40' , 'yyyy-mm-dd hh24:mi:ss')" AUXILIARY DESTINATION 'd:testtest01.dbf';


RMAN> RUN{
2> allocate auxiliary channel c1 type disk;
3> set newname for datafile 6 to 'd:testtest01.dbf';
4> recover tablespace 'TEST1' until time "to_date('2007-02-13 15:57:40' , 'yyyy
mm-dd hh24:mi:ss')";
5> }
使用目标数据库控制文件替代恢复目录
分配的通道: c1
通道 c1: sid=36 devtype=DISK
正在执行命令: SET NEWNAME
启动 recover 于 13-2月 -07
RMAN-05026: 警告: 假定以下表空间集适用于指定的时间点
表空间列表要求具有 UNDO 段
表空间 SYSTEM
表空间 UNDOTBS1
内存脚本的内容:
{
# set the until clause
set until time "to_date('2007-02-13 15:57:40' , '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;';
}
正在执行内存脚本
正在执行命令: SET until clause
启动 restore 于 13-2月 -07
通道 c1: 正在开始恢复数据文件备份集
通道 c1: 正在复原控制文件
通道 c1: 正在读取备份段 D:52.BAK
通道 c1: 已恢复备份段 1
段句柄 = D:52.BAK 标记 = TAG20070213T155246
通道 c1: 恢复完成, 用时: 00:00:03
输出文件名=D:TESTCONTROLT01.CTL
输出文件名=D:TESTCONTROLT02.CTL
输出文件名=D:TESTCONTROLT03.CTL
完成 restore 于 13-2月 -07
sql 语句: alter database mount clone database
sql 语句: alter system archive log current
sql 语句: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
内存脚本的内容:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until time "to_date('2007-02-13 15:57:40' , 'yyyy-mm-dd hh24:mi:ss')";
plsql <<declare
sqlstatement varchar2(512);
offline_not_needed exception;
pragma exception_init(offline_not_needed, -01539);
begin
sqlstatement := 'alter tablespace '|| 'TEST1' ||' offline for recover';
krmicd.writeMsg(6162, sqlstatement);
krmicd.execSql(sqlstatement);
exception
when offline_not_needed then
null;
end; >>>;
# set a destination filename for restore
set newname for datafile 1 to
"D:TESTSYSTEM01.DBF";
# set a destination filename for restore
set newname for datafile 2 to
"D:TESTUNDOTBS01.DBF";
# set a destination tempfile
set newname for tempfile 1 to
"D:TESTTEMP01.DBF";
# set a destination filename for restore
set newname for datafile 6 to
"D:TESTTEST01.DBF";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile 1, 2, 6;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile 1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile 2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile 6 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace "TEST1", "SYSTEM", "UNDOTBS1" delete archive
og;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
# datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
正在执行内存脚本
正在执行命令: SET until clause
sql 语句: alter tablespace TEST1 offline for recover
正在执行命令: SET NEWNAME
正在执行命令: SET NEWNAME
正在执行命令: SET NEWNAME
正在执行命令: SET NEWNAME

启动 restore 于 13-2月 -07
通道 c1: 正在开始恢复数据文件备份集
通道 c1: 正在指定从备份集恢复的数据文件
正将数据文件00001恢复到D:TESTSYSTEM01.DBF
正将数据文件00002恢复到D:TESTUNDOTBS01.DBF
正将数据文件00006恢复到D:TESTTEST01.DBF
通道 c1: 正在读取备份段 D:51.BAK
通道 c1: 已恢复备份段 1
段句柄 = D:51.BAK 标记 = TAG20070213T155246
通道 c1: 恢复完成, 用时: 00:00:35
完成 restore 于 13-2月 -07

sql 语句: alter database datafile 1 online
sql 语句: alter database datafile 2 online
sql 语句: alter database datafile 6 online
启动 recover 于 13-2月 -07
正在开始介质的恢复
存档日志线程 1 序列 43 已作为文件 D:ORACLEPRODUCT10.2.0ORADATAORCLARCHIVE
ARC00043_0613390304.001 存在于磁盘上
存档日志文件名 =D:ORACLEPRODUCT10.2.0ORADATAORCLARCHIVEARC00043_06133903
4.001 线程 =1 序列 =43
介质恢复完成, 用时: 00:00:01
完成 recover 于 13-2月 -07
数据库已打开
内存脚本的内容:
{
# export the tablespaces in the recovery set
host 'exp userid =" sys/aux@aux as sysdba" point_in_time_recover=y tablespaces
TEST1 file=
tspitr_a.dmp';
#rename a datafile in recovery set
sql "alter database rename file ''D:ORACLEPRODUCT10.2.0ORADATAORCLTEST01
DBF'' to
''D:TESTTEST01.DBF''";
# shutdown clone before import
shutdown clone immediate
# import
[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/548588/viewspace-981220/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/548588/viewspace-981220/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值