Oracle 恢复坏块方法(ORA-01578)—RMAN恢复

之前我们测试过利用bbed跳过坏块进行恢复,但是这种方法却会丢失部分数据,那么有什么办法可以确保数据不会被丢失呢?

如果在坏块之前,有rman备份,可以使用rman的备份来进行恢复,确保数据不会被丢失。

1.创建测试表

SQL> conn test/test
Connected.
SQL> create table test as select * from all_objects;

Table created.

SQL> select count(*) from test;

  COUNT(*)
----------
     80440
2.对数据库进行rman备份

cebpm:/data/backup/cebpm/fullback@cebpm>rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Jan 15 09:24:50 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: CEBPM (DBID=3677012495)

RMAN> backup database format '/data/backup/cebpm/fullback/cebpm';

Starting backup at 2018/01/15 09:25:17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=34 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf
input datafile file number=00002 name=/data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf
input datafile file number=00005 name=/data/CEBPM/datafile/test01.dbf
input datafile file number=00003 name=/data/CEBPM/datafile/undotbs01.dbf
input datafile file number=00004 name=/data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf
channel ORA_DISK_1: starting piece 1 at 2018/01/15 09:25:21
channel ORA_DISK_1: finished piece 1 at 2018/01/15 09:27:07
piece handle=/data/backup/cebpm/fullback/cebpm tag=TAG20180115T092520 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:46
Finished backup at 2018/01/15 09:27:07

Starting Control File and SPFILE Autobackup at 2018/01/15 09:27:09
piece handle=/data/backup/cebpm/ctlbackup/control_c-3677012495-20180115-01 comment=NONE
Finished Control File and SPFILE Autobackup at 2018/01/15 09:27:12
3.利用bbed破坏数据

具体可参考:

http://blog.csdn.net/shiyu1157758655/article/details/79043618

4.验证坏块

cebpm:/home/oracle@cebpm>dbv file=/data/CEBPM/datafile/test01.dbf 

DBVERIFY: Release 11.2.0.4.0 - Production on Mon Jan 15 09:33:09 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : FILE = /data/CEBPM/datafile/test01.dbf
Page 131 is marked corrupt
Corrupt block relative dba: 0x01400083 (file 5, block 131)
Bad check value found during dbv: 
Data in bad block:
 type: 6 format: 2 rdba: 0x01400083
 last change scn: 0x0000.0012dad3 seq: 0x2 flg: 0x04
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0xdad30602
 check value in block header: 0x4fe7
 computed block checksum: 0x33c4



DBVERIFY - Verification complete

Total Pages Examined         : 16384
Total Pages Processed (Data) : 1149
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 155
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 15079
Total Pages Marked Corrupt   : 1
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 1235718 (0.1235718)
SQL> select count(*) from test;
select count(*) from test
                     *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 131)
ORA-01110: data file 5: '/data/CEBPM/datafile/test01.dbf'
5.使用rman进行恢复

cebpm:/home/oracle@cebpm>rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Jan 15 09:34:48 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: CEBPM (DBID=3677012495)

RMAN> blockrecover datafile 5 block 131;

Starting recover at 2018/01/15 09:37:00
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=37 device type=DISK
searching flashback logs for block images until SCN 1235817
finished flashback log search, restored 1 blocks

starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished recover at 2018/01/15 09:37:10
6.检测坏块是否被修复

cebpm:/home/oracle@cebpm>dbv file=/data/CEBPM/datafile/test01.dbf 

DBVERIFY: Release 11.2.0.4.0 - Production on Mon Jan 15 09:38:42 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : FILE = /data/CEBPM/datafile/test01.dbf


DBVERIFY - Verification complete

Total Pages Examined         : 16384
Total Pages Processed (Data) : 1150
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 155
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 15079
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 1235718 (0.1235718)
RMAN> backup check logical validate datafile 5;

Starting backup at 2018/01/15 09:38:24
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/data/CEBPM/datafile/test01.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
5    OK     0              15079        16384           1235718   
  File Name: /data/CEBPM/datafile/test01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              1150            
  Index      0              0               
  Other      0              155             

Finished backup at 2018/01/15 09:38:26
7.验证数据是否正确

SQL> conn test/test
Connected.
SQL> select count(*)  from test;

  COUNT(*)
----------
     80440
由上可知数据已经完全恢复,不存在丢失数据的情况。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雨花石~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值