网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>数据库技术>>Oracle技术>>Oracle开发>查看文档  
  巧用"rman"的tspitr技术找回删除的表     
  文章作者:未知  文章来源:赛迪网技术社区  
  查看:99次  录入:管理员--2008-01-31  
 

1.首先我们需要创建一个辅助实例。

2.然后备份目标数据库。 style="text-indent:2em">

backup as compressed backupset database include 
current controlfile plus all archivedlog format=......;

sql> select * from t;

id name brith
---------- -------------------- --------------
1 a 14-12月-06

sql> set time on
12:29:30 sql> select table_name from user_tables;

table_name
------------------------------
t
tt

12:41:48 sql> create table ttt(id int) tablespace test;

表已创建。

12:42:07 sql> insert into ttt values(1);

已创建 1 行。

12:42:12 sql> commit;

提交完成。

12:42:14 sql> drop table t;

表已删除。

c:>rman target sys/system@test auxiliary 
sys/system@auxi catalog rman/rman@orcl


恢复管理器: release 10.2.0.1.0 - production 
on 星期五 12月 15 15:02:21 2006

copyright (c) 1982, 2005, oracle. all rights reserved.

连接到目标数据库: test (dbid=1906627575)
连接到恢复目录数据库
已连接到辅助数据库: test (未装载)

rman> run{
2> allocate auxiliary channel c1 type disk;
3> recover tablespace 'test' until 
time "to_date('12/15/2006 12:42:14' , 'mm/dd/
yyyy hh24:mi:ss')" auxiliary 
destination 'e:oracleproduct10.2.0oradataauxi'
;
4> release channel c1;
5> }

分配的通道: c1
通道 c1: sid=156 devtype=disk

启动 recover 于 15-12月-06

内存脚本的内容:
{
# set the until clause
set until time "to_date
('12/15/2006 12:42:14' , 'mm/dd/yyyy 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;';
# resync catalog after controlfile restore
resync catalog;
}
正在执行内存脚本

正在执行命令: set until clause

启动 restore 于 15-12月-06

通道 c1: 正在开始恢复数据文件备份集
通道 c1: 正在复原控制文件
通道 c1: 正在读取备份段 e:rmanatest_09i50smu_1_1.bak
通道 c1: 已恢复备份段 1
段句柄 = e:rmanatest_09i50smu_1_1.bak 标记 = tag20061215t124006
通道 c1: 恢复完成, 用时: 00:00:03
输出文件名=e:oracleproduct10.2.0oradataauxicontrol01.ctl
输出文件名=e:oracleproduct10.2.0oradataauxicontrol02.ctl
完成 restore 于 15-12月-06

sql 语句: alter database mount clone database

sql 语句: alter system archive log current

sql 语句: begin dbms_backup_restore.autobackupflag(false); end;

正在启动全部恢复目录的 resync
完成全部 resync

内存脚本的内容:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until time "to_date
('12/15/2006 12:42:14' ,'mm/dd/yyyy 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 '|| 
'test' ||' 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
"e:oracleproduct10.2.0oradataauxisystem01.dbf";
# set a destination filename for restore
set newname for datafile 2 to
"e:oracleproduct10.2.0oradataauxiundotbs01.dbf";
# set a destination tempfile
set newname for tempfile 1 to
"e:oracleproduct10.2.0oradataauxitemp01.dbf";
# set a destination tempfile
set newname for tempfile 2 to
"e:oracleproduct10.2.0oradataauxitmp.dbf";
# set a destination filename for restore
set newname for datafile 4 to
"e:oracleproduct10.2.0oradatatesttest.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery 
set plus the auxilliary tablespaces
restore clone datafile 1, 2, 4;
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 4 online";
# make the controlfile point at the restored 
datafiles, then recover them
recover clone database tablespace "test", 
"system", "undotbs1" delete archivelo
g;
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 test offline for recover

正在执行命令: set newname

正在执行命令: set newname

正在执行命令: set newname

正在执行命令: set newname

正在执行命令: set newname


启动 restore 于 15-12月-06

通道 c1: 正在开始恢复数据文件备份集
通道 c1: 正在指定从备份集恢复的数据文件
正将数据文件00001恢复到e:oracleproduct10.2.0oradataauxisystem01.dbf
正将数据文件00002恢复到e:oracleproduct10.2.0oradataauxiundotbs01.dbf
正将数据文件00004恢复到e:oracleproduct10.2.0oradatatesttest.dbf
通道 c1: 正在读取备份段 e:rmanatest_08i50sl7_1_1.bak
通道 c1: 已恢复备份段 1
段句柄 = e:rmanatest_08i50sl7_1_1.bak 标记 = tag20061215t124006
通道 c1: 恢复完成, 用时: 00:01:09
完成 restore 于 15-12月-06

数据文件 4 已转换成数据文件副本
输入数据文件副本 recid=9 stamp=609260651 文件名=e:oracleproduct10.2.0oradata
testtest.dbf

sql 语句: alter database datafile 1 online

sql 语句: alter database datafile 2 online

sql 语句: alter database datafile 4 online

启动 recover 于 15-12月-06

正在开始介质的恢复

存档日志线程 1 序列 116 已作为文件 e:oracleproduct10.2.0flash_recovery_area
testarchivelog2006_12_15o1_mf_1_116_2r49v29r_.arc 存在于磁盘上
存档日志线程 1 序列 117 已作为文件 e:oracleproduct10.2.0flash_recovery_area
testarchivelog2006_12_15o1_mf_1_117_2r4l4s2x_.arc 存在于磁盘上
存档日志文件名 =e:oracleproduct10.2.0flash_recovery_areatestarchivelog200
6_12_15o1_mf_1_116_2r49v29r_.arc 线程 =1 序列 =116
存档日志文件名 =e:oracleproduct10.2.0flash_recovery_areatestarchivelog200
6_12_15o1_mf_1_117_2r4l4s2x_.arc 线程 =1 序列 =117
介质恢复完成, 用时: 00:00:02
完成 recover 于 15-12月-06

数据库已打开

内存脚本的内容:
{
# export the tablespaces in the recovery set
host 'exp userid ="sys/system@auxi as sysdba" 
point_in_time_recover=y tablespa
ces=
test file=
tspitr_a.dmp';
# shutdown clone before import
shutdown clone immediate
# import the tablespaces in the recovery set
host 'imp userid ="sys/system@test as sysdba" point_in_time_recover=y file=
tspitr_a.dmp';
# online/offline the tablespace imported
sql "alter tablespace test online";
sql "alter tablespace test offline";
# enable autobackups in case user does 
open resetlogs from rman after tspitr
sql 'begin dbms_backup_restore.autobackupflag(true); end;';
# resync catalog after tspitr finished
resync catalog;
}
正在执行内存脚本


export: release 10.2.0.1.0 - production 
on 星期五 12月 15 15:04:34 2006

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
已导出 zhs16gbk 字符集和 al16utf16 nchar 字符集
服务器使用 zhs16cgb231280 字符集 (可能的字符集转换)
注: 将不导出表数据 (行)

即将导出表空间时间点恢复对象...
对于表空间 test...
. 正在导出簇定义
. 正在导出表定义
. . 正在导出表 tt
exp-00091: 正在导出有问题的统计信息。
exp-00008: 遇到 oracle 错误 6552
ora-06552: pl/sql: compilation unit analysis terminated
ora-06553: pls-553: 无法识别字符集名称
. . 正在导出表 t
exp-00091: 正在导出有问题的统计信息。
exp-00008: 遇到 oracle 错误 6552
ora-06552: pl/sql: compilation unit analysis terminated
ora-06553: pls-553: 无法识别字符集名称
. . 正在导出表 ttt
. 正在导出引用完整性约束条件
. 正在导出触发器
. 终止时间点恢复
导出成功终止, 但出现警告。
主机命令完成

数据库已关闭
数据库已卸载
oracle 实例已关闭


import: release 10.2.0.1.0 - production 
on 星期五 12月 15 15:05:01 2006

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

经由常规路径由 export:v10.02.01 创建的导出文件
即将导入表空间时间点恢复对象...
已经完成 zhs16gbk 字符集和 al16utf16 nchar 字符集中的导入
导入服务器使用 zhs16cgb231280 字符集 (可能的字符集转换)
. 正在将 sys 的对象导入到 sys
. 正在将 xys 的对象导入到 xys
. . 正在导入表 "tt"
. . 正在导入表 "t"
. . 正在导入表 "ttt"
. 正在将 sys 的对象导入到 sys
成功终止导入, 没有出现警告。
主机命令完成

sql 语句: alter tablespace test online

sql 语句: alter tablespace test offline

sql 语句: begin dbms_backup_restore.autobackupflag(true); end;

正在启动全部恢复目录的 resync
完成全部 resync
已删除辅助实例文件 e:oracleproduct10.2.0oradataauxicontrol01.ctl
已删除辅助实例文件 e:oracleproduct10.2.0oradataauxicontrol02.ctl
已删除辅助实例文件 e:oracleproduct10.2.0oradataauxisystem01.dbf
已删除辅助实例文件 e:oracleproduct10.2.0oradataauxiundotbs01.dbf
已删除辅助实例文件 e:oracleproduct10.2.0oradataauxitemp01.dbf
已删除辅助实例文件 e:oracleproduct10.2.0oradataauxitmp.dbf
完成 recover 于 15-12月-06
--====================================
14:48:22 sql> select tablespace_name , status from dba_tablespaces;

tablespace_name status
------------------------------ ------------------
system online
undotbs1 online
sysaux online
temp online
test offline
tmp online
test1 online

已选择7行。

15:06:14 sql> alter tablespace test online;

表空间已更改。

15:06:28 sql> show user
user 为 "xys"
15:06:32 sql> select * from t;

id name brith
---------- -------------- --------
1 a 2006/12/14 08:44:24

现在,我们就可以发现,被删除的表t被找回来了。

 
 
上一篇: oracle数据库中的共享服务器和专用服务器    下一篇: 如何使用备份的控制文件来恢复数据库?
  相关文档
为什么同机安装10g和11g后会出现连接问题 04-17
用一个实例讲解如何正确使用数据库游标 04-09
轻松了解 memory_target与自动内存管理 11-15
数据库不在open状态下的冷备份恢复步骤 02-29
如何在oracle中释放flash_recovery_area (1) 05-05
在unix裸设备与文件系统间移动oracle (1) 04-04
Oracle中细粒度访问控制的工作方式 04-12
带你快速了解wait等待事件及其处理方法 04-17
影响oracle数据库系统性能的初始化参数 11-19
理解和使用Oracle分析工具-LogMiner 06-10
用events 跟踪解决不能创建物化试图一例 06-17
Oracle的两个重要文件:TNSNAMES.ORA 05-13
教你轻松掌握如何把数据导入不同的表空间 11-15
细化解析Oracle中限制返回结果集的大小 09-01
教你快速掌握oracle 9i数据库的移动过程 11-15
在suse中让其他用户也能运行oracle命令 03-06
如何查看"control file"中保存的内容 02-27
对系统默认的约束名和索引名进行重命名 03-03
实例讲解ora-12514和ora-12514解决方法 04-15
轻松解决:Oracle8i回滚段表空间的坏块 08-05
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
厦门(总部):13616026886 福州:0591-87655121
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息