Recovering Individual Data Blocks
RMAN can recover individual corrupted datafile blocks. When RMAN performs a complete scan of a file for a backup, any corrupted blocks are listed in V$DATABASE_BLOCK_CORRUPTION. Corruption is usually reported in alert logs, trace files, or results of SQL queries.
To recover data blocks:
Obtain the block numbers of the corrupted blocks if you do not already have this information.
The easiest way to locate trace files and the alert log is to connect SQL*Plus to the target database and execute the following query:
SQL> SELECT NAME, VALUE
2 FROM V$DIAG_INFO;
Start RMAN and connect to the target database.
Run the RECOVER command to repair the blocks.
The following RMAN command recovers all corrupted blocks:
RMAN> RECOVER CORRUPTION LIST;
You can also recover individual blocks, as shown in the following example:
RMAN> RECOVER DATAFILE 1 BLOCK 233, 235 DATAFILE 2 BLOCK 100 TO 200;
模拟测试(生产环境一定要谨慎操作)
SQL> create tablespace netdata datafile '/data/netdata/netdata01.dbf' size 10M autoextend on next 20M maxsize 1G;
表空间已创建。
SQL> create user netdata identified by netdata default tablespace netdata temporary tablespace temp
2 ;
用户已创建。
SQL> grant connect,resource to netdata;
授权成功。
SQL> conn netdata/netdata;
已连接。
SQL> create table test (id int,name varchar2(20));
表已创建。
insert into test
select b.id,a.name from (select 'test' name from dual)a,
(select rownum id from dual connect by level <100000000)b
SQL> commit;
提交完成。
关闭数据库
并用UE修改数据库netdata01.dbf文件,随便修改几个字符
数据库open
SQL> startup;
ORACLE 例程已经启动。
Total System Global Area 855982080 bytes
Fixed Size 2258040 bytes
Variable Size 692063112 bytes
Database Buffers 155189248 bytes
Redo Buffers 6471680 bytes
数据库装载完毕。
数据库已经打开。
SQL> select count(*) from netdata.test;
select count(*) from netdata.test
*
第 1 行出现错误:
ORA-01578: ORACLE 数据块损坏 (文件号 7, 块号 9020) ORA-01110:
数据文件 7: '/data/netdata/netdata01.dbf'
SQL> select * from v$database_block_corruption;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
7 9020 1 0 CHECKSUM
RMAN> blockrecover datafile 7 block 9020;
启动 recover 于 21-6月 -15
使用目标数据库控制文件替代恢复目录
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: SID=400 设备类型=DISK
通道 ORA_DISK_1: 正在还原块
通道 ORA_DISK_1: 正在指定要从备份集还原的块
正在还原数据文件 00007 的块
通道 ORA_DISK_1: 正在读取备份片段 +FRA/netdata/backupset/2015_06_21/nnndf0_tag20150621t025253_0.276.882931979
通道 ORA_DISK_1: 段句柄 = +FRA/netdata/backupset/2015_06_21/nnndf0_tag20150621t025253_0.276.882931979 标记 = TAG20150621T025253
通道 ORA_DISK_1: 已从备份片段 1 还原块
通道 ORA_DISK_1: 块还原完成, 用时: 00:00:07
正在开始介质的恢复
介质恢复完成, 用时: 00:00:08
完成 recover 于 21-6月 -15
RMAN>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24486203/viewspace-1708581/
,如需转载,请注明出处,否则将追究法律责任。