打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
使用rman tspitr恢复被删除的数据或表
一、在测试表中插入数据
C:\Documents and Settings\Administrator.XY>set oracle_sid=orcl
C:\Documents and Settings\Administrator.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 Settings\Administrator.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:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF
输入数据文件 fno=00003 name=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF
输入数据文件 fno=00005 name=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\EXAMPLE01.DBF
输入数据文件 fno=00002 name=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF
输入数据文件 fno=00006 name=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST01.DBF
输入数据文件 fno=00004 name=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.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 Settings\Administrator.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 Settings\Administrator.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:\oracle\product\10.2.0\oradata\orcl','d:\test')
*.LOG_FILE_NAME_CONVERT=('d:\oracle\product\10.2.0\oradata\orcl','d:\test')
*.control_files='D:\test\CONTROLT01.CTL','D:\test\CONTROLT02.CTL','D:\test\CONTROLT03.CTL'
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
*.compatible='10.2.0.1.0'
*.db_block_size=8192
*.sga_target=250000000
background_dump_dest=d:\test\bdump
core_dump_dest=d:\test\cdump
user_dump_dest=d:\test\udump
以nomount方式打开
五、使用rman tspitr恢复数据
C:\Documents and Settings\Administrator.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:\test\test01.dbf';
recover tablespace 'TEST1' until time "to_date('2007-02-13 15:57:40' , 'yyyy-mm-dd hh24:mi:ss')" AUXILIARY DESTINATION 'd:\test\test01.dbf';
}
如果不设置set newname for datafile 6 to 'd:\test\test01.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:\test\test01.dbf';


RMAN> RUN{
2> allocate auxiliary channel c1 type disk;
3> set newname for datafile 6 to 'd:\test\test01.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:\TEST\CONTROLT01.CTL
输出文件名=D:\TEST\CONTROLT02.CTL
输出文件名=D:\TEST\CONTROLT03.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 <<<-- tspitr_2
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:\TEST\SYSTEM01.DBF";
# set a destination filename for restore
set newname for datafile  2 to
 "D:\TEST\UNDOTBS01.DBF";
# set a destination tempfile
set newname for tempfile  1 to
 "D:\TEST\TEMP01.DBF";
# set a destination filename for restore
set newname for datafile  6 to
 "D:\TEST\TEST01.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:\TEST\SYSTEM01.DBF
正将数据文件00002恢复到D:\TEST\UNDOTBS01.DBF
正将数据文件00006恢复到D:\TEST\TEST01.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:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\ARCHIVE
ARC00043_0613390304.001 存在于磁盘上
存档日志文件名 =D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\ARCHIVE\ARC00043_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:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST01
DBF'' to
 ''D:\TEST\TEST01.DBF''";
# shutdown clone before import
shutdown clone immediate
# import
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
使用RMAN复制数据库
12c 表恢复
用rman将Oracle迁移到异机 - 待做实验 - 众人拾贝
关于rman中set newname的探讨
aidu : 使用RMAN在线创建DataGuard备用库(数据文件不同路径结构)
oracle Rman-使用小记
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服