ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 用rman恢复损坏的数据块

用rman恢复损坏的数据块

原创 Linux操作系统 作者:sxitsxit 时间:2012-03-02 10:49:48 0 删除 编辑
试验目的

rman功能很强大,10g以后可以通过rman对某个损坏数据文件的具体块做恢复。


试验环境

OS: redhat linuxas4
DB: oracle10g r2

试验步骤

1:在sxit用户下创建一个表cc,往表里插入数据,并提交。

SQL> select count(*) from sxit.cc;
COUNT(*)
----------
449480

2:根据 dba_data_files 视图和 all_tables 视图查看sxit用户下所创建的表cc 属于哪个数据文件。

3:以nocatalog方式连接到数据库中,用rman工具进行数据库全备

[oracle@catalog ~]$ export PATH=$ORACLE_HOME/binATH:.
[oracle@catalog ~]$ rman target / nocatalog
Recovery Manager: Release 10.2.0.1.0 - Production on Fri Jul 15 17:58:25 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORA10HHA (DBID=3339398398)
using target database control file instead of recovery catalog
RMAN> backup database;

备份后,默认就在闪回区生成一个备份集文件。


4:用 shutdown immediate命令关闭数据库

5:将sxit用户下cc表所属的数据文件下载到本地xp系统上,并通过 ultraedit 工具编辑 数据文件users01.dbf 中的内容,模拟数据块损坏。
注意:不要编辑数据文件的头部前八个字节。(数据库启动的时候,会检查控制文件和数据文件头部,如果不一致数据库就会打不开)
然后保存,重新上传到原始目录下。

6:再次查询cc表,发现表无法访问,并报块折断错误提示。
SQL> select count(*) from sxit.CC;
select count(*) from sxit.CC
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 4, block # 1600)
ORA-01110: data file 4: '/home/oracle/oradata/ora10hha/users01.dbf'

7:在操作系统层面验证数据是否有损坏。

[oracle@catalog ora10hha]$ dbv file='/home/oracle/oradata/ora10hha/users01.dbf'
DBVERIFY: Release 10.2.0.1.0 - Production on Fri Jul 15 17:52:25 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
DBVERIFY - Verification starting : FILE = /home/oracle/oradata/ora10hha/users01.dbf
Page 359 is marked corrupt
Corrupt block relative dba: 0x01000167 (file 4, block 359)
Bad check value found during dbv:
Data in bad block:
type: 6 format: 2 rdba: 0x01000167
last change scn: 0x0000.000ea3fd seq: 0x4c flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0xa3fd064c
check value in block header: 0x59b1
computed block checksum: 0x7981
Page 1600 is marked corrupt
Corrupt block relative dba: 0x01000640 (file 4, block 1600)
Bad check value found during dbv:
Data in bad block:
type: 6 format: 2 rdba: 0x01000640
last change scn: 0x0000.000ff474 seq: 0x1 flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0xf4740601
check value in block header: 0xf984
computed block checksum: 0x9871

DBVERIFY - Verification complete
Total Pages Examined : 16320
Total Pages Processed (Data) : 15470
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 14
Total Pages Failing (Index): 0
Total Pages Processed (Other): 238
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 596
Total Pages Marked Corrupt : 2
Total Pages Influx : 0
Highest block SCN : 1310735 (0.1310735)
[oracle@catalog ora10hha]$

从执行结果可以看出,第4号数据文件的第359个块和第1600个块有损坏。


也可以从rman中进行数据库块是否有损坏

[oracle@catalog ~]$ rman target / nocatalog
Recovery Manager: Release 10.2.0.1.0 - Production on Fri Jul 15 17:58:25 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORA10HHA (DBID=3339398398)
using target database control file instead of recovery catalog
RMAN> backup validate database;
Starting backup at 15-JUL-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=153 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00005 name=/home/oracle/oradata/ora10hha/cata.dbf
input datafile fno=00001 name=/home/oracle/oradata/ora10hha/system01.dbf
input datafile fno=00002 name=/home/oracle/oradata/ora10hha/undotbs01.dbf
input datafile fno=00003 name=/home/oracle/oradata/ora10hha/sysaux01.dbf
input datafile fno=00004 name=/home/oracle/oradata/ora10hha/users01.dbf
input datafile fno=00006 name=/home/oracle/oradata/ora10hha/tz.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:16
Finished backup at 15-JUL-11

然后在以下视图中有记录:

select * from v$database_block_corruption
结果见附件中。


8:用rman恢复对应的数据块。

如果不用rman备份数据文件的话,那么在恢复数据的时候,就需要将这个数据文件全部拷贝过去,然后进行
恢复。如果碰到上百个G的大数据文件,为了几个损坏的块进行恢复需要耗费很久的时间。
但是如果使用rman工具,就可以对单个的数据文件块进行恢复,很方便。

[oracle@catalog ~]$ rman target / nocatalog
Recovery Manager: Release 10.2.0.1.0 - Production on Fri Jul 15 17:58:25 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORA10HHA (DBID=3339398398)
using target database control file instead of recovery catalog

RMAN> blockrecover datafile 4 block 359;
Starting blockrecover at 15-JUL-11
using channel ORA_DISK_1
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00004
channel ORA_DISK_1: reading from backup piece /home/oracle/flash_recovery_area/ORA10HHA/backupset/2011_07_15/o1_mf_nnndf_TAG20110715T163759_71zz37r4_.bkp
channel ORA_DISK_1: restored block(s) from backup piece 1
piece handle=/home/oracle/flash_recovery_area/ORA10HHA/backupset/2011_07_15/o1_mf_nnndf_TAG20110715T163759_71zz37r4_.bkp tag=TAG20110715T163759
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:27
starting media recovery
media recovery complete, elapsed time: 00:00:04
Finished blockrecover at 15-JUL-11
RMAN> blockrecover datafile 4 block 1600;
Starting blockrecover at 15-JUL-11
using channel ORA_DISK_1
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00004
channel ORA_DISK_1: reading from backup piece /home/oracle/flash_recovery_area/ORA10HHA/backupset/2011_07_15/o1_mf_nnndf_TAG20110715T163759_71zz37r4_.bkp
channel ORA_DISK_1: restored block(s) from backup piece 1
piece handle=/home/oracle/flash_recovery_area/ORA10HHA/backupset/2011_07_15/o1_mf_nnndf_TAG20110715T163759_71zz37r4_.bkp tag=TAG20110715T163759
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:35
starting media recovery
media recovery complete, elapsed time: 00:00:04
Finished blockrecover at 15-JUL-11
RMAN>

9:恢复以后,然后查看cc表,可以访问。


SQL> select count(*) from sxit.cc;
COUNT(*)
----------
449480
SQL>









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

请登录后发表评论 登录
全部评论

注册时间:2011-04-14

  • 博文量
    98
  • 访问量
    291826