分享

基于rman的坏块恢复

 崔锋1v14jbrb4q 2018-03-04

转载请注明出处 http://blog.csdn.net/guoyjoe/article/details/30965303

  实验步骤如下:

1、使用rman备份全库

  1. Recovery Manager: Release 11.2.0.3.0 - Production on Sun Jun 8 15:30:35 2014  
  2.   
  3. Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.  
  4.   
  5. connected to target database: PROD (DBID=254815294)  
  6.   
  7. RMAN> backup database;  
  8.   
  9. Starting backup at 08-JUN-14  
  10. using target database control file instead of recovery catalog  
  11. allocated channel: ORA_DISK_1  
  12. channel ORA_DISK_1: SID=142 device type=DISK  
  13. channel ORA_DISK_1: starting full datafile backup set  
  14. channel ORA_DISK_1: specifying datafile(s) in backup set  
  15. input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/system01.dbf  
  16. input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/tp01.dbf  
  17. input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbf  
  18. input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbf  
  19. input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbf  
  20. channel ORA_DISK_1: starting piece 1 at 08-JUN-14  
  21. channel ORA_DISK_1: finished piece 1 at 08-JUN-14  
  22. piece handle=/u01/app/oracle/product/11.2.0/dbs/01pab691_1_1 tag=TAG20140608T153040 comment=NONE  
  23. channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25  
  24. channel ORA_DISK_1: starting full datafile backup set  
  25. channel ORA_DISK_1: specifying datafile(s) in backup set  
  26. including current control file in backup set  
  27. including current SPFILE in backup set  
  28. channel ORA_DISK_1: starting piece 1 at 08-JUN-14  
  29. channel ORA_DISK_1: finished piece 1 at 08-JUN-14  
  30. piece handle=/u01/app/oracle/product/11.2.0/dbs/02pab69q_1_1 tag=TAG20140608T153040 comment=NONE  
  31. channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01  
  32. Finished backup at 08-JUN-14  

2、利用BBED破坏块

(1)针对gyj_t1表的20869号块做测试,现在可以查出记录

  1. gyj@PROD> select id,name,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from gyj_t1;  
  2.   
  3.         ID NAME       DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)  
  4. ---------- ---------- ------------------------------------ ------------------------------------  
  5.          1 oracledba                                     5                                20869  

(2)使用BBED破坏20869号块的seq

  1. [root@jfdb ~]# su - oracle  
  2. [oracle@jfdb ~]$ bbed parfile=par.txt  
  3. Password:   
  4.   
  5. BBED: Release 2.0.0.0.0 - Limited Production on Sun Jun 8 15:33:10 2014  
  6.   
  7. Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.  
  8.   
  9. ************* !!! For Oracle Internal Use only !!! ***************  
  10.   
  11. BBED> set file 5   block 20869  
  12.         FILE#           5  
  13.         BLOCK#          20869  
  14.   
  15. BBED> map /v  
  16.  File: /u01/app/oracle/oradata/PROD/tp01.dbf (5)  
  17.  Block: 20869                                 Dba:0x01405185  
  18. ------------------------------------------------------------  
  19.  KTB Data Block (Table/Cluster)  
  20.   
  21.  struct kcbh, 20 bytes                      @0         
  22.     ub1 type_kcbh                           @0         
  23.     ub1 frmt_kcbh                           @1         
  24.     ub1 spare1_kcbh                         @2         
  25.     ub1 spare2_kcbh                         @3         
  26.     ub4 rdba_kcbh                           @4         
  27.     ub4 bas_kcbh                            @8         
  28.     ub2 wrp_kcbh                            @12        
  29.     ub1 seq_kcbh                            @14        
  30.     ub1 flg_kcbh                            @15        
  31.     ub2 chkval_kcbh                         @16        
  32.     ub2 spare3_kcbh                         @18        
  33.   
  34.  struct ktbbh, 72 bytes                     @20        
  35.     ub1 ktbbhtyp                            @20        
  36.     union ktbbhsid, 4 bytes                 @24        
  37.     struct ktbbhcsc, 8 bytes                @28        
  38.     sb2 ktbbhict                            @36        
  39.     ub1 ktbbhflg                            @38        
  40.     ub1 ktbbhfsl                            @39        
  41.     ub4 ktbbhfnx                            @40        
  42.     struct ktbbhitl[2], 48 bytes            @44        
  43.   
  44.  struct kdbh, 14 bytes                      @100       
  45.     ub1 kdbhflag                            @100       
  46.     sb1 kdbhntab                            @101       
  47.     sb2 kdbhnrow                            @102       
  48.     sb2 kdbhfrre                            @104       
  49.     sb2 kdbhfsbo                            @106       
  50.     sb2 kdbhfseo                            @108       
  51.     sb2 kdbhavsp                            @110       
  52.     sb2 kdbhtosp                            @112       
  53.   
  54.  struct kdbt[1], 4 bytes                    @114       
  55.     sb2 kdbtoffs                            @114       
  56.     sb2 kdbtnrow                            @116       
  57.   
  58.  sb2 kdbr[1]                                @118       
  59.   
  60.  ub1 freespace[8038]                        @120       
  61.   
  62.  ub1 rowdata[30]                            @8158      
  63.   
  64.  ub4 tailchk                                @8188      
  65.   
  66.   
  67. BBED> p kcbh  
  68. struct kcbh, 20 bytes                       @0         
  69.    ub1 type_kcbh                            @0        0x06  
  70.    ub1 frmt_kcbh                            @1        0xa2  
  71.    ub1 spare1_kcbh                          @2        0x00  
  72.    ub1 spare2_kcbh                          @3        0x00  
  73.    ub4 rdba_kcbh                            @4        0x01405185  
  74.    ub4 bas_kcbh                             @8        0x00176fed  
  75.    ub2 wrp_kcbh                             @12       0x0000  
  76.    ub1 seq_kcbh                             @14       0x01  
  77.    ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)  
  78.    ub2 chkval_kcbh                          @16       0xc140  
  79.    ub2 spare3_kcbh                          @18       0x0000  
  80.   
  81. BBED> m /x ff offset 14  
  82. Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y  
  83.  File: /u01/app/oracle/oradata/PROD/tp01.dbf (5)  
  84.  Block: 20869            Offsets:   14 to  525           Dba:0x01405185  
  85. ------------------------------------------------------------------------  
  86.  ff0640c1 00000100 00003945 0000eb6f 17000000 00000200 32008051 40010700   
  87.  20008b02 00002c49 c0002301 02000080 0000876d 17000300 1a007503 0000bf1f   
  88.  c0002501 0c000120 0000ed6f 17000000 00000000 00000001 0100ffff 14007a1f   
  89.  741f741f 00000100 7a1f0000 00000000 00000000 00000000 00000000 00000000   
  90.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  91.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  92.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  93.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  94.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  95.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  96.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  97.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  98.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  99.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  100.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  101.  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000   
  102.   
  103.  <32 bytes per line>  
  104.   
  105. BBED> sum apply  
  106. Check value for File 5, Block 20869:  
  107. current = 0xc1be, required = 0xc1be  

 (3)校验报坏块

  1. BBED> verify  
  2. DBVERIFY - Verification starting  
  3. FILE = /u01/app/oracle/oradata/PROD/tp01.dbf  
  4. BLOCK = 20869  
  5.   
  6. Block 20869 is corrupt  
  7. Corrupt block relative dba: 0x01405185 (file 0, block 20869)  
  8. Fractured block found during verification  
  9. Data in bad block:  
  10.  type: 6 format: 2 rdba: 0x01405185  
  11.  last change scn: 0x0000.00176fed seq: 0xff flg: 0x06  
  12.  spare1: 0x0 spare2: 0x0 spare3: 0x0  
  13.  consistency value in tail: 0x6fed0601  
  14.  check value in block header: 0xc1be  
  15.  computed block checksum: 0x0  
  16.   
  17.   
  18. DBVERIFY - Verification complete  
  19.   
  20. Total Blocks Examined         : 1  
  21. Total Blocks Processed (Data) : 0  
  22. Total Blocks Failing   (Data) : 0  
  23. Total Blocks Processed (Index): 0  
  24. Total Blocks Failing   (Index): 0  
  25. Total Blocks Empty            : 0  
  26. Total Blocks Marked Corrupt   : 1  
  27. Total Blocks Influx           : 2  
  28. Message 531 not found;  product=RDBMS; facility=BBED  


(4)确定不能查gyj_t1表的记录

  1. gyj@PROD> alter system flush buffer_cache;  
  2.   
  3. System altered.  
  4.   
  5. gyj@PROD> select id,name,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from gyj_t1;  
  6. select id,name,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from gyj_t1  
  7. *  
  8. ERROR at line 1:  
  9. ORA-01578: ORACLE data block corrupted (file # 5, block # 20869)  
  10. ORA-01110: data file 5: '/u01/app/oracle/oradata/PROD/tp01.dbf'  

3、使用RMAN验证5号数据文件

  1. RMAN> backup validate datafile 5;  
  2.   
  3. Starting backup at 08-JUN-14  
  4. using channel ORA_DISK_1  
  5. channel ORA_DISK_1: starting full datafile backup set  
  6. channel ORA_DISK_1: specifying datafile(s) in backup set  
  7. input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/tp01.dbf  
  8. channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07  
  9. List of Datafiles  
  10. =================  
  11. File Status Marked Corrupt Empty Blocks Blocks Examined High SCN  
  12. ---- ------ -------------- ------------ --------------- ----------  
  13. 5    FAILED 0              114          64000           1659211     
  14.   File Name: /u01/app/oracle/oradata/PROD/tp01.dbf  
  15.   Block Type Blocks Failing Blocks Processed  
  16.   ---------- -------------- ----------------  
  17.   Data       1              58883             
  18.   Index      0              4221              
  19.   Other      0              782               
  20.   
  21. validate found one or more corrupt blocks  
  22. See trace file /u01/app/oracle/diag/rdbms/prod/PROD/trace/PROD_ora_2750.trc for details  
  23. Finished backup at 08-JUN-14  

4、查5号文件的坏块

  1. gyj@PROD> select FILE#,BLOCK#,BLOCKS,CORRUPTION_CHANGE#,CORRUPTION_TYPE from v$database_block_corruption where file#=5;  
  2.   
  3.      FILE#     BLOCK#     BLOCKS CORRUPTION_CHANGE# CORRUPTIO  
  4. ---------- ---------- ---------- ------------------ ---------  
  5.          5      20869          1                  0 FRACTURED  


5、使用rman恢复坏块

  1. RMAN> blockrecover datafile 5 block  20869;  
  2.   
  3. Starting recover at 08-JUN-14  
  4. using channel ORA_DISK_1  
  5.   
  6. channel ORA_DISK_1: restoring block(s)  
  7. channel ORA_DISK_1: specifying block(s) to restore from backup set  
  8. restoring blocks of datafile 00005  
  9. channel ORA_DISK_1: reading from backup piece /u01/app/oracle/product/11.2.0/dbs/01pab691_1_1  
  10. channel ORA_DISK_1: piece handle=/u01/app/oracle/product/11.2.0/dbs/01pab691_1_1 tag=TAG20140608T153040  
  11. channel ORA_DISK_1: restored block(s) from backup piece 1  
  12. channel ORA_DISK_1: block restore complete, elapsed time: 00:00:01  
  13.   
  14. starting media recovery  
  15. media recovery complete, elapsed time: 00:00:01  
  16.   
  17. Finished recover at 08-JUN-14  


6、再次查5号文件的坏块,已经消息了(如果还有记录,那再次执行backup validate datafile 5;)

  1. gyj@PROD> select FILE#,BLOCK#,BLOCKS,CORRUPTION_CHANGE#,CORRUPTION_TYPE from v$database_block_corruption where file#=5;  
  2.   
  3. no rows selected  


7、查表gyj_t1记录也有了,说明恢复成功

  1. gyj@PROD> select id,name,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from gyj_t1;  
  2.   
  3.         ID NAME       DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)  
  4. ---------- ---------- ------------------------------------ ------------------------------------  
  5.          1 oracledba                                     5                                20869  



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多