RMAN blockrecover命令恢復資料塊

muxinqing發表於2014-04-22
 在有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 <
> 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 <
> 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

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29065182/viewspace-1147263/,如需轉載,請註明出處,否則將追究法律責任。

相關文章