RMAN - blockrecover实现数据块恢复

对于数据块的损坏除了BBED方式恢复外,还可以通过RMAN的blockrecover块介质恢复功能来修复受损块,使用RMAN块介质恢复的前提是必须要有一个可以使用RMAN备份,因此备份重于一切,切记盖老师的教诲,呵呵。

1、创建演示环境
点击( 此处 )折叠或打开
  1. SQL> create table tt (id number ,name varchar2(10)) tablespace tbs;

  2. Table created.

  3. SQL> insert into tt values (1,'AAAA');

  4. 1 row created.

  5. SQL> insert into tt values (2,'BBBB');

  6. 1 row created.

  7. SQL> commit;

  8. Commit complete.

  9. SQL> col file_name for a50
    SQL> select file_id ,file_name from dba_data_files where tablespace_name='TBS';


       FILE_ID FILE_NAME
    ---------- --------------------------------------------------
            11 /oracle/database/oradata/primary/tbs01.dbf

  10. #通过RMAN对数据文件11或是database进行backup#

  11. RMAN> backup datafile 11; 


    Starting backup at 2016-07-22 21:49:54
    using target database control file instead of recovery catalog
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=27 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=00011 name=/oracle/database/oradata/primary/tbs01.dbf
    channel ORA_DISK_1: starting piece 1 at 2016-07-22 21:49:55
    channel ORA_DISK_1: finished piece 1 at 2016-07-22 21:49:56
    piece handle=/oracle/database/fast_recovery_area/PRIMARY/backupset/2016_07_22/o1_mf_nnndf_TAG20160722T214955_cs49439t_.bkp tag=TAG20160722T214955 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
    Finished backup at 2016-07-22 21:49:56


    Starting Control File and SPFILE Autobackup at 2016-07-22 21:49:56
    piece handle=/opt/oracle/obak/controlc-1743469316-20160722-01 comment=NONE
    Finished Control File and SPFILE Autobackup at 2016-07-22 21:49:57
  12. #记录对象TT的对应的文件信息、头部块、总块数#
  13. SQL> col segment_name for a40
  14. SQL> select segment_name,header_file,header_block,blocks
      2  from dba_segments
      3  where segment_name = 'TT' and owner = 'SCOTT';

    SEGMENT_NAME                             HEADER_FILE HEADER_BLOCK     BLOCKS
    ---------------------------------------- ----------- ------------ ----------
    TT                                                11          130          8


2、数据块损坏的恢复处理过程
模拟块损坏,可以通过操作系统命令dd 对块写入, 也可以通过上篇博客中BBED工具对块进行更改,这里我们BBED方式

点击(此处)折叠或打开

  1. #在上古神器BBED中指定file和block,查找到需要修改的内容

  2. BBED> find /c ABCD
     File: /oracle/database/oradata/primary/tbs01.dbf (11)
     Block: 131              Offsets: 8184 to 8191           Dba:0x02c00083
    ------------------------------------------------------------------------
     41424344 01069d37 

     <32 bytes="" per="" line="">

    BBED> modify /c ABCDGGG file 11 block 131 offset 8184         
    Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
     File: /oracle/database/oradata/primary/tbs01.dbf (11)
     Block: 131              Offsets: 8184 to 8191           Dba:0x02c00083
    ------------------------------------------------------------------------
     41424344 47474737 

     <32 bytes="" per="" line="">

    BBED> sum apply
    Check value for File 11, Block 131:
    current = 0x349c, required = 0x349c

    BBED> verify
    DBVERIFY - Verification starting
    FILE = /oracle/database/oradata/primary/tbs01.dbf
    BLOCK = 131

    Block 131 is corrupt
    Corrupt block relative dba: 0x02c00083 (file 0, block 131)
    Fractured block found during verification
    Data in bad block:
     type: 6 format: 2 rdba: 0x02c00083
     last change scn: 0x0000.004a379d seq: 0x1 flg: 0x06
     spare1: 0x0 spare2: 0x0 spare3: 0x0
     consistency value in tail: 0x37474747
     check value in block header: 0x349c
     computed block checksum: 0x0

    DBVERIFY - Verification complete

    Total Blocks Examined         : 1
    Total Blocks Processed (Data) : 0
    Total Blocks Failing   (Data) : 0
    Total Blocks Processed (Index): 0
    Total Blocks Failing   (Index): 0
    Total Blocks Empty            : 0
    Total Blocks Marked Corrupt   : 1
    Total Blocks Influx           : 2
    Message 531 not found;  product=RDBMS; facility=BBED

    BBED> 

  3. #在RMAN中验证datafile 11 ,在BBED中已经通过verify验证发现corrupt

  4. RMAN> backup validate datafile 11;

    Starting backup at 2016-07-22 23:06:25
    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=00011 name=/oracle/database/oradata/primary/tbs01.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
    ---- ------ -------------- ------------ --------------- ----------
    11   FAILED 0              1145         1280            4863898   
      File Name: /oracle/database/oradata/primary/tbs01.dbf
      Block Type Blocks Failing Blocks Processed
      ---------- -------------- ----------------
      Data       1              5               
      Index      0              0               
      Other      0              130             

    validate found one or more corrupt blocks
    See trace file /oracle/database/diag/rdbms/primary/primary/trace/primary_ora_117887.trc for details
    Finished backup at 2016-07-22 23:06:26


    /*
  5. 在视图v$database_block_corruption 记录着自上一次备份以来损坏的数据块、在我们这里发现数据块损坏类型是FRACTURED ,其他类型是 CORRUPTCHECKSUM ALL ZERO 、LOGICAL 五中类型

  6. CORRUPT - Block is wrongly identified or is not a data block (for example, the data block address is missing)
  7. CHECKSUM - optional check value shows that the block is not self-consistent. It is impossible to determine exactly why the check value fails, but it probably fails because sectors in the middle of the block are from different versions.
  8. FRACTURED - Block header looks reasonable, but the front and back of the block are different versions.
  9. ALL ZERO - Block header on disk contained only zeros. The block may be valid if it was never filled and if it is in an Oracle7 file. The buffer will be reformatted to the Oracle8 standard for an empty block.
  10. LOGICAL - Specifies the range is for logically corrupt blocks. CORRUPTION_CHANGE# will have a nonzero value.

  11. */

  12. SQL> select * from v$database_block_corruption;  

  13.      FILE#     BLOCK#     BLOCKS CORRUPTION_CHANGE# CORRUPTION_TYPE
    ---------- ---------- ---------- ------------------ ------------------
            11        131          1                  0 FRACTURED
    SQL> 

  14. #实施blockrecover操作恢复
  15. RMAN>  blockrecover corruption list;            

    Starting recover at 2016-07-22 23:11:31
    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 00011
    channel ORA_DISK_1: reading from backup piece /oracle/database/fast_recovery_area/PRIMARY/backupset/2016_07_22/o1_mf_nnndf_TAG20160722T214955_cs49439t_.bkp
    channel ORA_DISK_1: piece handle=/oracle/database/fast_recovery_area/PRIMARY/backupset/2016_07_22/o1_mf_nnndf_TAG20160722T214955_cs49439t_.bkp tag=TAG20160722T214955
    channel ORA_DISK_1: restored block(s) from backup piece 1
    channel ORA_DISK_1: block restore complete, elapsed time: 00:00:02

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

    Finished recover at 2016-07-22 23:11:36

  16. 恢复完成后,表TT的内容可以访问

  17. SQL> select * from tt;

  18.         ID NAME
    ---------- --------------------
             1 ABCD
             2 BBBB



三、如何发现坏块和定位坏块的位置
3.1 通过DBV命令检查数据文件
点击( 此处 )折叠或打开
  1. [oracle@Primary ~]$ dbv file=/oracle/database/oradata/primary/tbs01.dbf
  2. DBVERIFY: Release 11.2.0.4.0 - Production on Fri Jul 22 23:37:19 2016
  3. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
  4. DBVERIFY - Verification starting : FILE = /oracle/database/oradata/primary/tbs01.dbf
  5. Page 131 is influx - most likely media corrupt
  6. Corrupt block relative dba: 0x02c00083 (file 11, block 131)
  7. Fractured block found during dbv:
  8. Data in bad block:
  9. type: 6 format: 2 rdba: 0x02c00083
  10. last change scn: 0x0000.004a379d seq: 0x1 flg: 0x06
  11. spare1: 0x0 spare2: 0x0 spare3: 0x0
  12. consistency value in tail: 0x37474747
  13. check value in block header: 0x349c
  14. computed block checksum: 0x0

  15. DBVERIFY - Verification complete
  16. Total Pages Examined : 1280
  17. Total Pages Processed (Data) : 4
  18. Total Pages Failing (Data) : 0
  19. Total Pages Processed (Index): 0
  20. Total Pages Failing (Index): 0
  21. Total Pages Processed (Other): 130
  22. Total Pages Processed (Seg) : 0
  23. Total Pages Failing (Seg) : 0
  24. Total Pages Empty : 1145
  25. Total Pages Marked Corrupt : 1
  26. Total Pages Influx : 1
  27. Total Pages Encrypted : 0
  28. Highest block SCN : 4863898 (0.4863898)
  29. [oracle@Primary ~]$
3.2 对坏块的数据访问,提示信息
点击( 此处 )折叠或打开
  1. SQL> select * from tt;
  2. select * from tt
  3.               *
  4. ERROR at line 1:
  5. ORA-01578: ORACLE data block corrupted (file # 11, block # 131)
  6. ORA-01110: data file 11: '/oracle/database/oradata/primary/tbs01.dbf'

  7. SQL>
3.3 RMAN 备份时 数据块检查提示corrupt block
点击( 此处 )折叠或打开
  1. RMAN> backup database;
  2. Starting backup at 2016-07-22 23:41:54
  3. using channel ORA_DISK_1
  4. channel ORA_DISK_1: starting full datafile backup set
  5. channel ORA_DISK_1: specifying datafile(s) in backup set
  6. input datafile file number=00001 name=/oracle/database/oradata/primary/system01.dbf
  7. input datafile file number=00002 name=/oracle/database/oradata/primary/sysaux01.dbf
  8. input datafile file number=00005 name=/oracle/database/oradata/primary/perfstat.dbf
  9. input datafile file number=00004 name=/oracle/database/oradata/primary/users01.dbf
  10. input datafile file number=00003 name=/oracle/database/oradata/primary/undotbs01.dbf
  11. input datafile file number=00010 name=/oracle/database/oradata/primary/users.dbf
  12. input datafile file number=00011 name=/oracle/database/oradata/primary/tbs01.dbf
  13. input datafile file number=00006 name=/oracle/database/oradata/primary/enmo.dbf
  14. input datafile file number=00007 name=/oracle/database/oradata/primary/enmo01.dbf
  15. input datafile file number=00008 name=/oracle/database/oradata/primary/enmo02.dbf
  16. input datafile file number=00009 name=/oracle/database/oradata/primary/enmo003.dbf
  17. channel ORA_DISK_1: starting piece 1 at 2016-07-22 23:41:54
  18. RMAN-00571: ===========================================================
  19. RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
  20. RMAN-00571: ===========================================================
  21. RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/22/2016 23:41:57
  22. ORA-19566: exceeded limit of 0 corrupt blocks for file /oracle/database/oradata/primary/tbs01.dbf
3.4 接下来最重要的事情就是定位受损坏块的对象
点击( 此处 )折叠或打开
  1. SQL> start get_corrupt_block.sql;
  2. Enter value for file_id: 11
  3. old 3: WHERE file_id = &file_id
  4. new 3: WHERE file_id = 11
  5. Enter value for block_id: 131
  6. old 4: AND &block_id BETWEEN block_id AND block_id + blocks - 1
  7. new 4: AND 131 BETWEEN block_id AND block_id + blocks - 1
  8. TABLESPACE_NAME                SEGMENT_TYPE                   OWNER                          SEGMENT_NAME                   PARTITION_NAME
    ------------------------------ ------------------------------ ------------------------------ ------------------------------ ------------------------------
    TBS                            TABLE                          SCOTT                          TT


  9. SQL> host cat get_corrupt_block.sql
  10. set linesize 300
  11. col tablespace_name for a30
  12. col segment_type for a30
  13. col owner for a30
  14. col segment_name for a30
  15. col partition_name for a30
  16. SELECT tablespace_name, segment_type, owner, segment_name, partition_name
  17. FROM dba_extents
  18. WHERE file_id = &file_id
  19. AND &block_id BETWEEN block_id AND block_id + blocks - 1
  20. SQL>

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

转载于:http://blog.itpub.net/27039319/viewspace-2122399/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值