利用rman做数据文件丢失的恢复实验

利用rman做数据文件丢失的恢复实验
1.首先备份全库  实验环境 windows xp+oracle 9.2.0.1
C:\Documents and Settings\paulyi>rman target /

恢复管理器: 版本9.2.0.1.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

连接到目标数据库: TEST (DBID=1964268543)

RMAN> backup full database;

启动 backup 于 23-9月 -08
正在使用目标数据库控制文件替代恢复目录
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=13 devtype=DISK
通道 ORA_DISK_1: 正在启动 full 数据文件备份集
通道 ORA_DISK_1: 正在指定备份集中的数据文件
输入数据文件 fno=00001 name=D:\ORACLE\ORADATA\TEST\SYSTEM01.DBF
输入数据文件 fno=00002 name=D:\ORACLE\ORADATA\TEST\UNDOTBS01.DBF
输入数据文件 fno=00005 name=D:\ORACLE\ORADATA\TEST\EXAMPLE01.DBF
输入数据文件 fno=00010 name=D:\ORACLE\ORADATA\TEST\XDB01.DBF
输入数据文件 fno=00006 name=D:\ORACLE\ORADATA\TEST\INDX01.DBF
输入数据文件 fno=00009 name=D:\ORACLE\ORADATA\TEST\USERS01.DBF
输入数据文件 fno=00003 name=D:\ORACLE\ORADATA\TEST\CWMLITE01.DBF
输入数据文件 fno=00004 name=D:\ORACLE\ORADATA\TEST\DRSYS01.DBF
输入数据文件 fno=00007 name=D:\ORACLE\ORADATA\TEST\ODM01.DBF
输入数据文件 fno=00008 name=D:\ORACLE\ORADATA\TEST\TOOLS01.DBF
通道 ORA_DISK_1: 正在启动段 1 于 23-9月 -08
通道 ORA_DISK_1: 已完成段 1 于 23-9月 -08
段 handle=D:\BACKUP\BACKUP_0IJRABD7_1_1 comment=NONE
通道 ORA_DISK_1: 备份集已完成, 经过时间:00:01:06
完成 backup 于 23-9月 -08

启动 Control File and SPFILE Autobackup 于 23-9月 -08
段 handle=D:\BACKUP\C-1964268543-20080923-07 comment=NONE
完成 Control File and SPFILE Autobackup 于 23-9月 -08

RMAN>exit


SQL> select tablespace_name from user_tables where table_name='TEST';

TABLESPACE_NAME
------------------------------
TOOLS
SQL>select count(*) from test;
    count(*)
     236096
    
SQL> insert into test select * from test;    --产生数据

已创建236096行。

SQL> /

已创建472192行。

SQL> /

已创建944384行。

SQL> alter system switch logfile;

系统已更改。

SQL> select count(*) from test;

  COUNT(*)
----------
   1888768 


这个时候从操作系统删除数据文件tools01.dbf

下面利用rman在数据库mount的状态来恢复

SQL> shutdown immediate;
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> exit
从Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production中断开

C:\Documents and Settings\paulyi>d:

D:\>cd oracle\oradata\test

D:\oracle\oradata\test>dir
 驱动器 D 中的卷是 software
 卷的序列号是 3C2B-605D

 D:\oracle\oradata\test 的目录

2008-09-23  10:50   

          .
2008-09-23  10:50              ..
2008-09-23  11:32         2,023,424 CONTROL01.CTL
2008-09-23  11:32         2,023,424 CONTROL02.CTL
2008-09-23  11:32         2,023,424 CONTROL03.CTL
2008-09-23  10:49        20,979,712 CWMLITE01.DBF
2008-09-23  10:49        20,979,712 DRSYS01.DBF
2008-09-23  10:50       156,639,232 EXAMPLE01.DBF
2008-09-23  10:49        26,222,592 INDX01.DBF
2008-09-23  10:49        20,979,712 ODM01.DBF
2008-09-23  11:29       104,858,112 REDO01.LOG
2008-09-23  11:30       104,858,112 REDO02.LOG
2008-09-23  11:32       104,858,112 REDO03.LOG
2008-09-23  11:32       419,438,592 SYSTEM01.DBF
2008-09-23  11:32        31,465,472 TOOLS01.DBF
2008-09-23  11:32       209,723,392 UNDOTBS01.DBF
2008-09-23  10:49        26,222,592 USERS01.DBF
2008-09-23  10:49        39,985,152 XDB01.DBF
              16 个文件  1,293,280,768 字节
               2 个目录  7,935,217,664 可用字节

D:\oracle\oradata\test>del TOOLS01.DBF

D:\oracle\oradata\test>dir
 驱动器 D 中的卷是 software
 卷的序列号是 3C2B-605D

 D:\oracle\oradata\test 的目录

2008-09-23  11:33   

          .
2008-09-23  11:33              ..
2008-09-23  11:32         2,023,424 CONTROL01.CTL
2008-09-23  11:32         2,023,424 CONTROL02.CTL
2008-09-23  11:32         2,023,424 CONTROL03.CTL
2008-09-23  10:49        20,979,712 CWMLITE01.DBF
2008-09-23  10:49        20,979,712 DRSYS01.DBF
2008-09-23  10:50       156,639,232 EXAMPLE01.DBF
2008-09-23  10:49        26,222,592 INDX01.DBF
2008-09-23  10:49        20,979,712 ODM01.DBF
2008-09-23  11:29       104,858,112 REDO01.LOG
2008-09-23  11:30       104,858,112 REDO02.LOG
2008-09-23  11:32       104,858,112 REDO03.LOG
2008-09-23  11:32       419,438,592 SYSTEM01.DBF
2008-09-23  11:32       209,723,392 UNDOTBS01.DBF
2008-09-23  10:49        26,222,592 USERS01.DBF
2008-09-23  10:49        39,985,152 XDB01.DBF
              15 个文件  1,261,815,296 字节
               2 个目录  7,966,683,136 可用字节

D:\oracle\oradata\test>sqlplus "/as sysdba"

SQL*Plus: Release 9.2.0.1.0 - Production on 星期二 9月 23 11:33:40 2008

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

已连接到空闲例程。

SQL> startup;
ORACLE 例程已经启动。

Total System Global Area  496049552 bytes
Fixed Size                   454032 bytes
Variable Size             201326592 bytes
Database Buffers          293601280 bytes
Redo Buffers                 667648 bytes
数据库装载完毕。
ORA-01157: 无法标识/锁定数据文件 8 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 8: 'D:\ORACLE\ORADATA\TEST\TOOLS01.DBF'    --数据库启动报错,找不到数据文件


SQL>

SQL> exit
从Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production中断开

D:\oracle\oradata\test>rman target /

恢复管理器: 版本9.2.0.1.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

连接到目标数据库: TEST (DBID=1964268543)

RMAN> restore datafile 8;

启动 restore 于 23-9月 -08

正在使用目标数据库控制文件替代恢复目录
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=13 devtype=DISK
通道 ORA_DISK_1: 正在开始恢复数据文件备份集
通道 ORA_DISK_1: 正在指定从备份集恢复的数据文件
正将数据文件00008恢复到D:\ORACLE\ORADATA\TEST\TOOLS01.DBF
通道 ORA_DISK_1: 已恢复备份段 1
段 handle=D:\BACKUP\BACKUP_0IJRABD7_1_1 tag=TAG20080923T112526 params=NULL
通道 ORA_DISK_1: 恢复完成
完成 restore 于 23-9月 -08

RMAN> recover datafile 8;

启动 recover 于 23-9月 -08
使用通道 ORA_DISK_1

正在开始介质的恢复
完成介质的恢复

完成 recover 于 23-9月 -08

RMAN> alter database open;

数据库已打开

RMAN> exit


恢复管理器完成。

D:\oracle\oradata\test>sqlplus "/as sysdba"

SQL*Plus: Release 9.2.0.1.0 - Production on 星期二 9月 23 11:37:22 2008

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


连接到:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production

SQL> select count(*) from test;

  COUNT(*)
----------
   1888768

SQL>

--数据没丢失 恢复成功

利用rman在open状态下的恢复

D:\oracle\oradata\test>sqlplus "/as sysdba"

SQL*Plus: Release 9.2.0.1.0 - Production on 星期二 9月 23 11:40:16 2008

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


连接到:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production

SQL> shutdown immediate;
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> exit
从Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production中断开

D:\oracle\oradata\test>del TOOLS01.DBF

D:\oracle\oradata\test>sqlplus "/as sysdba"

SQL*Plus: Release 9.2.0.1.0 - Production on 星期二 9月 23 11:40:43 2008

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

已连接到空闲例程。

SQL> startup;
ORACLE 例程已经启动。

Total System Global Area  496049552 bytes
Fixed Size                   454032 bytes
Variable Size             201326592 bytes
Database Buffers          293601280 bytes
Redo Buffers                 667648 bytes
数据库装载完毕。
ORA-01157: 无法标识/锁定数据文件 8 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 8: 'D:\ORACLE\ORADATA\TEST\TOOLS01.DBF'


SQL> alter database datafile 'D:\ORACLE\ORADATA\TEST\TOOLS01.DBF' offline;

数据库已更改。

SQL> alter database open;

数据库已更改。

SQL> exit
从Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production中断开

D:\oracle\oradata\test>rman target /

恢复管理器: 版本9.2.0.1.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

连接到目标数据库: TEST (DBID=1964268543)

RMAN> restore datafile 8;

启动 restore 于 23-9月 -08

正在使用目标数据库控制文件替代恢复目录
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=15 devtype=DISK
通道 ORA_DISK_1: 正在开始恢复数据文件备份集
通道 ORA_DISK_1: 正在指定从备份集恢复的数据文件
正将数据文件00008恢复到D:\ORACLE\ORADATA\TEST\TOOLS01.DBF
通道 ORA_DISK_1: 已恢复备份段 1
段 handle=D:\BACKUP\BACKUP_0IJRABD7_1_1 tag=TAG20080923T112526 params=NULL
通道 ORA_DISK_1: 恢复完成
完成 restore 于 23-9月 -08

RMAN> recover datafile 8;

启动 recover 于 23-9月 -08
使用通道 ORA_DISK_1

正在开始介质的恢复
完成介质的恢复

完成 recover 于 23-9月 -08

RMAN> exit


恢复管理器完成。

D:\oracle\oradata\test>sqlplus "/as sysdba"

SQL*Plus: Release 9.2.0.1.0 - Production on 星期二 9月 23 11:42:47 2008

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


连接到:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production

SQL> alter database datafile 'D:\ORACLE\ORADATA\TEST\TOOLS01.DBF' online;

数据库已更改。

SQL> select count(*) from test;

  COUNT(*)
----------
   1888768

SQL>

--也恢复成功

请使用浏览器的分享功能分享到微信等