從ORACLE9i開(kāi)始,rman支持基于數(shù)據(jù)庫(kù)的恢復(fù),這一功能有很大的好處,既不影響業(yè)務(wù),甚至不影響有壞塊的數(shù)據(jù)文件,恢復(fù)可以是在線(xiàn)恢復(fù)。但是恢復(fù)是完全恢復(fù),所以要求完整的備份。
下面測(cè)試:
-
對(duì)數(shù)據(jù)庫(kù)進(jìn)行完整備份
Rman>backup database;
-
破壞數(shù)據(jù)
參看日志《RMAN進(jìn)行基于數(shù)據(jù)塊的恢復(fù)》
-
使用rman驗(yàn)證數(shù)據(jù)文件
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
警告日志和數(shù)據(jù)庫(kù)中都會(huì)記錄損壞的數(shù)據(jù),如下
SQL> select * from v$database_block_corruption ;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
5 49316 1 0 CORRUPT
-
通過(guò)備份基于數(shù)據(jù)快級(jí)的恢復(fù)
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未必可以恢復(fù)得了:
[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
這個(gè)塊損壞已經(jīng)嚴(yán)重破壞了數(shù)據(jù)的存放規(guī)律,發(fā)生了邏輯損壞,所以blockrecover沒(méi)辦法恢復(fù),必須首先restore這個(gè)文件然后通過(guò)recvoer命令進(jìn)行恢復(fù).
通過(guò)常規(guī)方法恢復(fù)這個(gè)錯(cuò)誤:
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、數(shù)據(jù)庫(kù)必須在A(yíng)RCHIVELOG模式下才可以使用這個(gè)功能;
2、數(shù)據(jù)庫(kù)必須是mount或open狀態(tài);
3、不能對(duì)一個(gè)offline的datafile進(jìn)行BLOCKRECOVER;
4、blcokrecover需要通過(guò)一個(gè)full backups 恢復(fù)datra block,不能使用incremental backups進(jìn)行錯(cuò)誤恢復(fù);
5、blockrecover不能跨越archivelog丟失或損壞,也就是說(shuō)在恢復(fù)的過(guò)程中,不能丟失需要的歸檔日志;
6、blockrecover不能恢復(fù)邏輯壞塊,邏輯壞塊必須首先restore損壞的數(shù)據(jù)文件,然后在用recover進(jìn)行恢復(fù);
7、blockrecvoer不能恢復(fù)file header block.(block=1).
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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