從ORACLE9i開始,rman支持基于數據庫的恢復,這一功能有很大的好處,既不影響業務,甚至不影響有壞塊的數據文件,恢復可以是在線恢復。但是恢復是完全恢復,所以要求完整的備份。
下面測試:
-
對數據庫進行完整備份
Rman>backup database;
-
破壞數據
參看日志《RMAN進行基于數據塊的恢復》
-
使用rman驗證數據文件
RMAN> backup validate datafile 5;
Starting backup at 29-AUG-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=139 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00005 name=/opt/oracle/oradata/orcla/xzsp.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 29-AUG-14
警告日志和數據庫中都會記錄損壞的數據,如下
SQL> select * from v$database_block_corruption ;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
5 49316 1 0 CORRUPT
-
通過備份基于數據快級的恢復
RMAN> blockrecover datafile 5 block 49316 from backupset;
Starting blockrecover at 29-AUG-14
using channel ORA_DISK_1
using channel ORA_DISK_2
?
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00005
channel ORA_DISK_1: reading from backup piece /opt/oracle/flash_recovery_area1/ORCLA/backupset/2014_08_29/o1_mf_nnndf_TAG20140829T032828_9zz0px68_.bkp
channel ORA_DISK_1: restored block(s) from backup piece 1
piece handle=/opt/oracle/flash_recovery_area1/ORCLA/backupset/2014_08_29/o1_mf_nnndf_TAG20140829T032828_9zz0px68_.bkp tag=TAG20140829T032828
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:26
?
starting media recovery
?
archive log thread 1 sequence 5 is already on disk as file /opt/oracle/flash_recovery_area1/ORCLA/archivelog/2014_08_29/o1_mf_1_5_9zz2mqwo_.arc
archive log thread 1 sequence 6 is already on disk as file /opt/oracle/flash_recovery_area1/ORCLA/archivelog/2014_08_29/o1_mf_1_6_9zz2v3jj_.arc
archive log thread 1 sequence 7 is already on disk as file /opt/oracle/flash_recovery_area1/ORCLA/archivelog/2014_08_29/o1_mf_1_7_9zz3hfff_.arc
media recovery complete, elapsed time: 00:00:01
Finished blockrecover at 29-AUG-14
-
清楚壞塊記錄
SQL> select * from v$database_block_corruption ;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
5 49316 1 0 CORRUPT
RMAN> backup validate datafile 5;
Starting backup at 29-AUG-14
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00005 name=/opt/oracle/oradata/orcla/xzsp.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 29-AUG-14
SQL> select * from v$database_block_corruption ;
?
no rows selected
?
注意:
但有些情況下,BLOCKRECOVER未必可以恢復得了:
[oracle@ique datafile]$ sqlplus mayp/mayp
SQL*Plus: Release 10.1.0.5.0 – Production on Mon Jul 14 17:08:06 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 – Production
With the Partitioning, OLAP and Data Mining options
SQL> select count(*) from mssm;
select count(*) from mssm
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 9)
ORA-01110: data file 5: '/data/mayp/MAYP/datafile/o1_mf_mssm_4789hznr_.dbf'
[oracle@ique datafile]$ rman target /
Recovery Manager: Release 10.1.0.5.0 – Production
Copyright (c) 1995, 2004, Oracle. All rights reserved.
connected to target database: MAYP (DBID=412172232)
RMAN> blockrecover datafile 5 block 9;
Starting blockrecover at 14-JUL-08
using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=378 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of blockrecover command at 07/14/2008 17:08:37
ORA-01455: converting column overflows integer datatype
RMAN-06010: error while looking up datafile: 5
這個塊損壞已經嚴重破壞了數據的存放規律,發生了邏輯損壞,所以blockrecover沒辦法恢復,必須首先restore這個文件然后通過recvoer命令進行恢復.
通過常規方法恢復這個錯誤:
RMAN> sql 'alter database datafile 5 offline';
sql statement: alter database datafile 5 offline
RMAN> restore datafile 5;
Starting restore at 14-JUL-08
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00005 to /data/mayp/MAYP/datafile/o1_mf_mssm_4789hznr_.dbf
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/product/10.2/dbs/full_2_MAYP.rman tag=TAG20080714T152854
channel ORA_DISK_1: restore complete
Finished restore at 14-JUL-08
RMAN> recover datafile 5;
Starting recover at 14-JUL-08
using channel ORA_DISK_1
starting media recovery
media recovery complete
Finished recover at 14-JUL-08
RMAN> sql 'alter database datafile 5 online';
sql statement: alter database datafile 5 online
RMAN> exit
BLOCKRECOVER 的使用限制:
1、數據庫必須在ARCHIVELOG模式下才可以使用這個功能;
2、數據庫必須是mount或open狀態;
3、不能對一個offline的datafile進行BLOCKRECOVER;
4、blcokrecover需要通過一個full backups 恢復datra block,不能使用incremental backups進行錯誤恢復;
5、blockrecover不能跨越archivelog丟失或損壞,也就是說在恢復的過程中,不能丟失需要的歸檔日志;
6、blockrecover不能恢復邏輯壞塊,邏輯壞塊必須首先restore損壞的數據文件,然后在用recover進行恢復;
7、blockrecvoer不能恢復file header block.(block=1).
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
