RMAN blockrecover命令恢复数据块

RMAN可以通过备份修复坏块。

0.修复过程是在线操作,不需要文件offline

1.修复是针对块级别,修复时间很短

2.修复命令使用blockrecover

4.可以同时修复多个文件的多个坏块


以下转自:http://blog.csdn.net/seertan/article/details/8502377 作者:seertan



   在有rman备份的情况下,可以使用rman的blockrecover命令实行块恢复。
SYS@orcl>create tablespace test datafile '/u01/app/oracle/oradata/orcl/test01.dbf' size 10m;
Tablespace created.

SYS@orcl>create table scott.test tablespace test as select * from dba_objects where rownum <=100;
Table created.

---test表在6号数据文件,开始于第128号块,共占用8个数据块

SYS@orcl>select a.file_id,a.block_id,a.blocks,b.name from dba_extents a,v$datafile b  where a.file_id=b.file# and a.owner='SCOTT' and a.segment_name='TEST';

  FILE_ID   BLOCK_ID      BLOCKS    NAME
---------- ----------             ----------    ----------------------------------------------
6      128      8           u01/app/oracle/oradata/orcl/test01.dbf

---备份6号数据文件
RMAN> backup datafile 6;

Starting backup at 14-JAN-13
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=00006 name=/u01/app/oracle/oradata/orcl/test01.dbf
channel ORA_DISK_1: starting piece 1 at 14-JAN-13
channel ORA_DISK_1: finished piece 1 at 14-JAN-13
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_01_14/o1_mf_nnndf_TAG20130114T200736_8h7x896y_.bkp tag=TAG20130114T200736 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 14-JAN-13

---破坏数据块130和131
[oracle@ora ~]$ dd of=/u01/app/oracle/oradata/orcl/test01.dbf bs=8192 conv=notrunc seek=130 <<EOF
> abcdefghijklmnopqrst
> EOF
0+1 records in
0+1 records out
21 bytes (21 B) copied, 4.6654e-05 s, 450 kB/s
[oracle@ora ~]$ dd of=/u01/app/oracle/oradata/orcl/test01.dbf bs=8192 conv=notrunc seek=131 <<EOF
> abcdefghijklmnopqrst
> EOF
0+1 records in
0+1 records out
21 bytes (21 B) copied, 2.5004e-05 s, 840 kB/s

---验证6号数据文件是否有数据块错误
RMAN> backup validate datafile 6;

Starting backup at 14-JAN-13
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=00006 name=/u01/app/oracle/oradata/orcl/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
---- ------ -------------- ------------ --------------- ----------
6    FAILED 0              1148         1280            1358146  
 File Name: /u01/app/oracle/oradata/orcl/test01.dbf
 Block Type Blocks Failing Blocks Processed
 ---------- -------------- ----------------
 Data       0              1              
 Index      0              0              
Other      2              131            

validate found one or more corrupt blocks
See trace file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_8456.trc for details

Finished backup at 14-JAN-13

---发现有2个数据块错误,可以通过trace文件查看更详细的信息


---也可通过视图v$database_block_corruption查询
SYS@orcl>select * from v$database_block_corruption;
    FILE#     BLOCK#      BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
    6      130           2          0 CORRUPT
---6号文件130号数据块开始有2个数据块损坏

---恢复130和131数据块,也可以执行blockrecover corruption list命令恢复视图中标记的所有块
RMAN> blockrecover datafile 6 block 130,131;
Starting recover at 14-JAN-13
using channel ORA_DISK_1
searching flashback logs for block images until SCN 1358226
finished flashback log search, restored 2 blocks

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

Finished recover at 14-JAN-13

---再次验证6号数据文件,检查发现没有块损坏
RMAN> backup validate datafile 6;
Starting backup at 14-JAN-13
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=00006 name=/u01/app/oracle/oradata/orcl/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
---- ------ -------------- ------------ --------------- ----------
6    OK     0              1148         1280            1358152  
 File Name: /u01/app/oracle/oradata/orcl/test01.dbf
 Block Type Blocks Failing Blocks Processed
 ---------- -------------- ----------------
 Data       0              2              
 Index      0              0              
 Other      0              130            

Finished backup at 14-JAN-13

SYS@orcl>select * from v$database_block_corruption;
no rows selected


   blockrecover命令不能恢复数据文件1号块的损坏,如果1号块损坏了只能恢复整个数据文件,例如:
---破坏6号数据文件的1号块
[oracle@ora ~]$ dd if=/dev/zero of=/u01/app/oracle/oradata/orcl/test01.dbf bs=8192 conv=notrunc count=1
1+0 records in
1+0 records out
8192 bytes (8.2 kB) copied, 2.633e-05 s, 311 MB/s

---验证6号数据文件
RMAN> backup validate datafile 6;

Starting backup at 14-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 01/14/2013 20:19:22
ORA-01122: database file 6 failed verification check
ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/test01.dbf'
ORA-01565: error in identifying file '/u01/app/oracle/oradata/orcl/test01.dbf'
ORA-27048: skgfifi: file header information is invalid
Additional information: 11


---使用blockrecover命令恢复6号文件的1号块,提示恢复成功
RMAN> blockrecover datafile 6 block 1;
Starting recover at 14-JAN-13
using channel ORA_DISK_1

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

Finished recover at 14-JAN-13

---再次验证还是报错
RMAN> backup validate datafile 6;

Starting backup at 14-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 01/14/2013 20:20:03
ORA-01122: database file 6 failed verification check
ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/test01.dbf'
ORA-01565: error in identifying file '/u01/app/oracle/oradata/orcl/test01.dbf'
ORA-27048: skgfifi: file header information is invalid
Additional information: 11


---只能恢复整个6号数据文件
RMAN> run{
2> sql 'alter database datafile 6 offline';
3> restore datafile 6;
4> recover datafile 6;
5> sql 'alter database datafile 6 online';
6> }


sql statement: alter database datafile 6 offline

Starting restore at 14-JAN-13
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/orcl/test01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_01_14/o1_mf_nnndf_TAG20130114T200736_8h7x896y_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_01_14/o1_mf_nnndf_TAG20130114T200736_8h7x896y_.bkp tag=TAG20130114T200736
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 14-JAN-13

Starting recover at 14-JAN-13
using channel ORA_DISK_1

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

Finished recover at 14-JAN-13

sql statement: alter database datafile 6 online


---再次验证6号数据文件,没有数据块损坏
RMAN> backup validate datafile 6;

Starting backup at 14-JAN-13
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=00006 name=/u01/app/oracle/oradata/orcl/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
---- ------ -------------- ------------ --------------- ----------
6    OK     0              60           1281            1358152  
 File Name: /u01/app/oracle/oradata/orcl/test01.dbf
 Block Type Blocks Failing Blocks Processed
 ---------- -------------- ----------------
 Data       0              2              
 Index      0              0              
 Other      0              1218            

Finished backup at 14-JAN-13


你可能感兴趣的:(rman,blockrecover,块修复)