RMAN全自动TSPITR

环境:

Windows xp

Oracle 10.2.0.1

 

准备工作:

1创建auxiliary instance的口令文件

先创建aux实例:

C:\>oradim -NEW -SID aux

实例已创建。

 

创建口令文件:

C:\>orapwd file=D:\oracle\product\10.2.0\db_1\database\PWDaux.ora password=sys

2.  配置auxiliary instance的监听和tnsnames.ora

listener.ora中增加:

    (SID_DESC =

      (GLOBAL_DBNAME = orcl)

      (ORACLE_HOME = D:\oracle\product\10.2.0\db_1)

      (SID_NAME = aux)

)

tnsnames.ora中增加:

aux =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SID = aux)

    )

  )

使用tnsping验证:

C:\>tnsping aux

TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 22-4 -2009 09:47:35

Copyright (c) 1997, 2005, Oracle.  All rights reserved.

已使用的参数文件:

D:\oracle\product\10.2.0\db_1\network\admin\sqlnet.ora

已使用 TNSNAMES 适配器来解析别名

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SID = aux))) OK (10 毫秒)

 

3.  创建auxiliary instance的参数文件

创建参数文件d:\initaux.ora,内容如下:

compatible='10.2.0.1.0'

db_name='orcl'

db_unique_name='aux'

db_block_size=8192

SHARED_POOL_SIZE=50M

CONTROL_FILES='D:\oracle\product\10.2.0\oradata\auxi\control01.ctl'

DB_FILE_NAME_CONVERT='D:\oracle\product\10.2.0\oradata\orcl','D:\oracle\product\10.2.0\oradata\auxi'

LOG_FILE_NAME_CONVERT='D:\oracle\product\10.2.0\oradata\orcl','D:\oracle\product\10.2.0\oradata\auxi'还必须创建D:\oracle\product\10.2.0\oradata\auxi目录

特别注意db_namedb_unique_name参数,设置不当可能会遇到ORA-01102ORA-01103报错。

 

4. 启动auxiliary instancenomount状态

C:\>set oracle_sid=aux

C:\>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 4 22 09:35:00 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

已连接到空闲例程。

 

SQL> startup nomount pfile=d:\initaux.ora

ORACLE 例程已经启动。

 

5. target database open or mount

确认target database状态为open mount

 

6. 保证备份文件和归档文件可用

备份target database

C:\>rman target /

RMAN> backup as compressed backupset database current controlfile plus archivelog;

RMAN> exit

 

备份完成后,模拟失误操作:(确定恢复时间)

14:47:15 SQL> conn test/test

已连接。

14:47:19 SQL> drop table t1;

表已删除。

已用时间:  00: 00: 00.28

14:47:34 SQL> truncate table t2;

表被截断。

 

执行全自动TSPITR

首先确定对象被删除之前的准确时间

C:\>rman target / auxiliary sys/sys@aux

 

恢复管理器: Release 10.2.0.1.0 - Production on 星期一 4 27 14:51:13 2009

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

连接到目标数据库: ORCL (DBID=1211958316)

已连接到辅助数据库: ORCL (未装载)

 

RMAN> run{

2> allocate auxiliary channel c1 type disk;

3> recover tablespace 'TEST' until time "to_date('2009-04-27:14:46:00','yyyy-mm-

dd:hh24:mi:ss')" auxiliary destination 'D:\oracle\product\10.2.0\oradata\auxi';

4> }

 

使用目标数据库控制文件替代恢复目录

分配的通道: c1

通道 c1: sid=36 devtype=DISK

 

启动 recover 27-4 -09

RMAN-05026: 警告: 假定以下表空间集适用于指定的时间点

 

表空间列表要求具有 UNDO

表空间 SYSTEM

表空间 UNDOTBS1

 

内存脚本的内容:

{

# set the until clause

set until  time "to_date('2009-04-27:14:46:00','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 27-4 -09

 

通道 c1: 正在开始恢复数据文件备份集

通道 c1: 正在复原控制文件

通道 c1: 正在读取备份段 D:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\BACKUP

SET\2009_04_27\O1_MF_NCNNF_TAG20090427T144344_4ZBO2WMK_.BKP

通道 c1: 已恢复备份段 1

段句柄 = D:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\BACKUPSET\2009_04_27\

O1_MF_NCNNF_TAG20090427T144344_4ZBO2WMK_.BKP 标记 = TAG20090427T144344

通道 c1: 恢复完成, 用时: 00:00:01

输出文件名=D:\ORACLE\PRODUCT\10.2.0\ORADATA\AUXI\CONTROL01.CTL

完成 restore 27-4 -09

 

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('2009-04-27:14:46:00','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 '||  '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

 "D:\ORACLE\PRODUCT\10.2.0\ORADATA\AUXI\SYSTEM01.DBF";

# set a destination filename for restore

set newname for datafile  2 to

 "D:\ORACLE\PRODUCT\10.2.0\ORADATA\AUXI\UNDOTBS01.DBF";

# set a destination tempfile

set newname for tempfile  1 to

 "D:\ORACLE\PRODUCT\10.2.0\ORADATA\AUXI\TEMP01.DBF";

# set a destination filename for restore

set newname for datafile  6 to

 "D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST.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  "TEST", "SYSTEM", "UNDOTBS1" delete archivelog;

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

 

 

启动 restore 27-4 -09

 

通道 c1: 正在开始恢复数据文件备份集

通道 c1: 正在指定从备份集恢复的数据文件

正将数据文件00001恢复到D:\ORACLE\PRODUCT\10.2.0\ORADATA\AUXI\SYSTEM01.DBF

正将数据文件00002恢复到D:\ORACLE\PRODUCT\10.2.0\ORADATA\AUXI\UNDOTBS01.DBF

正将数据文件00006恢复到D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEST.DBF

通道 c1: 正在读取备份段 D:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\BACKUP

SET\2009_04_27\O1_MF_NNNDF_TAG20090427T144344_4ZBO117B_.BKP

通道 c1: 已恢复备份段 1

段句柄 = D:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\BACKUPSET\2009_04_27\

O1_MF_NNNDF_TAG20090427T144344_4ZBO117B_.BKP 标记 = TAG20090427T144344

通道 c1: 恢复完成, 用时: 00:00:46

完成 restore 27-4 -09

 

数据文件 6 已转换成数据文件副本

输入数据文件副本 recid=7 stamp=685291943 文件名=D:\ORACLE\PRODUCT\10.2.0\ORADATA

\ORCL\TEST.DBF

 

sql 语句: alter database datafile  1 online

 

sql 语句: alter database datafile  2 online

 

sql 语句: alter database datafile  6 online

 

启动 recover 27-4 -09

 

正在开始介质的恢复

 

存档日志线程 1 序列 38 已作为文件 D:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\O

RCL\ARCHIVELOG\2009_04_27\O1_MF_1_38_4ZBO2Y3X_.ARC 存在于磁盘上

存档日志线程 1 序列 39 已作为文件 D:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\O

RCL\ARCHIVELOG\2009_04_27\O1_MF_1_39_4ZBO90X9_.ARC 存在于磁盘上

存档日志文件名 =D:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\200

9_04_27\O1_MF_1_38_4ZBO2Y3X_.ARC 线程 =1 序列 =38

存档日志文件名 =D:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\200

9_04_27\O1_MF_1_39_4ZBO90X9_.ARC 线程 =1 序列 =39

介质恢复完成, 用时: 00:00:02

完成 recover 27-4 -09

 

数据库已打开

 

内存脚本的内容:

{

# export the tablespaces in the recovery set

host 'exp userid =\"sys/sys@aux as sysdba\" point_in_time_recover=y tablespaces=

 

 TEST file=

tspitr_a.dmp';

# shutdown clone before import

shutdown clone immediate

# import the tablespaces in the recovery set

host 'imp userid =\"/@ 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;';

}

正在执行内存脚本

 

 

Export: Release 10.2.0.1.0 - Production on 星期一 4 27 14:52:50 2009

 

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 字符集

: 将不导出表数据 ()

 

即将导出表空间时间点恢复对象...

对于表空间 TEST...

. 正在导出簇定义

. 正在导出表定义

. . 正在导出表                              T1

. . 正在导出表                              T2

. 正在导出引用完整性约束条件

. 正在导出触发器

. 终止时间点恢复

成功终止导出, 没有出现警告。

主机命令完成

 

数据库已关闭

数据库已卸载

Oracle 实例已关闭

 

 

Import: Release 10.2.0.1.0 - Production on 星期一 4 27 14:53:18 2009

 

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 字符集中的导入

. 正在将 SYS 的对象导入到 SYS

. 正在将 TEST 的对象导入到 TEST

. . 正在导入表                            "T1"

. . 正在导入表                            "T2"

. 正在将 SYS 的对象导入到 SYS

成功终止导入, 没有出现警告。

主机命令完成

 

sql 语句: alter tablespace  TEST online

 

sql 语句: alter tablespace  TEST offline

 

sql 语句: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

已删除辅助实例文件 D:\ORACLE\PRODUCT\10.2.0\ORADATA\AUXI\CONTROL01.CTL

已删除辅助实例文件 D:\ORACLE\PRODUCT\10.2.0\ORADATA\AUXI\SYSTEM01.DBF

已删除辅助实例文件 D:\ORACLE\PRODUCT\10.2.0\ORADATA\AUXI\UNDOTBS01.DBF

已删除辅助实例文件 D:\ORACLE\PRODUCT\10.2.0\ORADATA\AUXI\TEMP01.DBF

完成 recover 27-4 -09

 

至此全自动TSPITR完成,验证恢复结果:

14:50:54 SQL> select tablespace_name,status from dba_tablespaces;

 

TABLESPACE_NAME                STATUS

------------------------------ ---------

SYSTEM                         ONLINE

UNDOTBS1                       ONLINE

SYSAUX                         ONLINE

TEMP                           ONLINE

USERS                          ONLINE

EXAMPLE                        ONLINE

TEST                           OFFLINE

 

已选择7行。

 

已用时间:  00: 00: 00.03

14:53:37 SQL> alter tablespace test online;

 

分别select两个表,观察恢复结果!

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

转载于:http://blog.itpub.net/17997/viewspace-591927/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值