rman validate(block head corrupted)

这篇文章主要是想要说明validate命令的基础语法,为此我故意破坏了一个表空间的文件头,当然在这之前我是有做好rman全库备份的.
(您可千万别在生产库上乱来啊~~~)

rdbms information:

SQL> select * from v$version where rownum<2 
  2  /

BANNER
------------------------------------------------------------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

创建表空间

create tablespace test001  datafile  size 20m autoextend on  next 5m maxsize unlimited
  2  /

这里我用了OMF,要不然我每次还得为文件想个名字

然后,创建一个segment(table t1)

SQL> alter user hdp  default tablespace test001 
  2  /

User altered.

SQL> drop table t1 
  2  /

Table dropped.

SQL> create table t1  as select * from dba_objects
  2  /

Table created.

备份好该表空间

RMAN> backup tablespace test001 
2> ;

Starting backup at 14-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=70 device type=DISK
allocated channel: ORA_DISK_2
(***ignore somethings***)
Starting Control File and SPFILE Autobackup at 14-AUG-17
piece handle=/u02/backup/ORCL/autobackup/2017_08_14/o1_mf_s_951964101_ds16l5mn_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 14-AUG-17

RMAN> 
[oracle@hdp datafile]$ ll -h
total 21M
-rw-r-----. 1 oracle oinstall 21M Aug 14 02:28 o1_mf_test001_ds16fwnb_.dbf
[oracle@hdp datafile]$ 

故意破坏文件头(vim)

'hello world'
^^@^@^@^ÿ^@^@^@^@^@^@^@^@fð^@^@^@ ^@^@^@
@                                           

这里我故意破坏了o1_mf_test001_ds16fwnb_.dbf 的head信息

再次查询 发现报错。t1表已经不可访问

SQL> conn hdp/123123
Connected.
SQL> select * from t1 
  2  /
select * from t1
              *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 131)
ORA-01110: data file 5: '/u02/oradata/ORCL/datafile/o1_mf_test001_ds16fwnb_.dbf'

这时候我们可以检测预警日志:

提示我们文件头有损坏

Reread of blocknum=1, file=/u02/oradata/ORCL/datafile/o1_mf_test001_ds16fwnb_.dbf. found same corrupt data
Reread of blocknum=1, file=/u02/oradata/ORCL/datafile/o1_mf_test001_ds16fwnb_.dbf. found same corrupt data
Reread of blocknum=1, file=/u02/oradata/ORCL/datafile/o1_mf_test001_ds16fwnb_.dbf. found same corrupt data
Reread of blocknum=1, file=/u02/oradata/ORCL/datafile/o1_mf_test001_ds16fwnb_.dbf. found same corrupt data
Reread of blocknum=1, file=/u02/oradata/ORCL/datafile/o1_mf_test001_ds16fwnb_.dbf. found same corrupt data
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_31362/orcl_ora_2885_i31362.trc:
ORA-19563: datafile header validation failed for file /u02/oradata/ORCL/datafile/o1_mf_test001_ds16fwnb_.dbf
ORA-01251: Unknown File Header Version read for file number 5
ORA-01578: ORACLE data block corrupted (file # 5, block # 131)
ORA-01110: data file 5: '/u02/oradata/ORCL/datafile/o1_mf_test001_ds16fwnb_.dbf'
Mon Aug 14 02:32:31 2017
Dumping diagnostic data in directory=[cdmp_20170814023231], requested by (instance=1, osid=2885), summary=[incident=31361].
Mon Aug 14 02:32:34 2017

ORACLE 甚至连里面的对象,对象拥有者都提示了,这也是一个高级DBA以后要研究的方向

Reading datafile '/u02/oradata/ORCL/datafile/o1_mf_test001_ds16fwnb_.dbf' for corruption at rdba: 0x01400084 (file 5, block 132)
Reread (file 5, block 132) found same corrupt data (no logical check)
Corrupt Block Found
         TSN = 6, TSNAME = TEST001
         RFN = 5, BLK = 131, RDBA = 20971651
         OBJN = 87560, OBJD = 87560, OBJECT = T1, SUBOBJECT = 
         SEGMENT OWNER = HDP, SEGMENT TYPE = Table Segment


RMAN> validate datafile 5;

Starting validate at 14-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=132 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=197 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=12 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=73 device type=DISK
allocated channel: ORA_DISK_5
channel ORA_DISK_5: SID=200 device type=DISK
allocated channel: ORA_DISK_6
channel ORA_DISK_6: SID=134 device type=DISK
RMAN-06169: could not read file header for datafile 5 error reason 7
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of validate command at 08/14/2017 02:41:15
RMAN-06056: could not access datafile 5

可以看到该文件已经无法访问了

RMAN> validate tablespace test001;

Starting validate at 14-AUG-17
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6
RMAN-06169: could not read file header for datafile 5 error reason 7
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of validate command at 08/14/2017 02:41:35
RMAN-06056: could not access datafile 5

RMAN> advise failure;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of advise command at 08/14/2017 02:41:47
RMAN-07211: failure option not specified

意思是我们错误选项没有指定,原来错误不止一个

RMAN> list failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
9248       HIGH     OPEN      14-AUG-17     One or more non-system datafiles are corrupt
1454       HIGH     OPEN      11-AUG-17     Tablespace 4: 'USERS' is offline
1442       HIGH     OPEN      11-AUG-17     One or more non-system datafiles are offline

RMAN> advise failure 9248;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
9248       HIGH     OPEN      14-AUG-17     One or more non-system datafiles are corrupt

advise failure 提示我们数据不会有丢失,这是个好消息 

analyzing automatic repair options; this may take some time
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
no manual actions available

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Restore and recover datafile 5  
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/orcl/orcl/hm/reco_2393879581.hm

RMAN> 

查看生成文件的内容:

[oracle@hdp datafile]$ cd /u01/app/oracle/diag/rdbms/orcl/orcl/hm/
[oracle@hdp hm]$ ls
reco_2393879581.hm
[oracle@hdp hm]$ vim reco_2393879581.hm 
[oracle@hdp hm]$ cat reco_2393879581.hm 
   # restore and recover datafile
   sql 'alter database datafile 5 offline';
   restore datafile 5;
   recover datafile 5;
   sql 'alter database datafile 5 online';

按这个提示的脚本来吧(当然自己敲也可以咯)

[oracle@hdp hm]$ rman target/ @reco_2393879581.hm  (注意“/”后面的空格)

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Aug 14 02:45:45 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1477533441)

RMAN>    # restore and recover datafile
2>    sql 'alter database datafile 5 offline';
3>    restore datafile 5;
4>    recover datafile 5;
5>    sql 'alter database datafile 5 online';
6> 
using target database control file instead of recovery catalog
sql statement: alter database datafile 5 offline

Starting restore at 14-AUG-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=71 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=134 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=200 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=12 device type=DISK
allocated channel: ORA_DISK_5
channel ORA_DISK_5: SID=70 device type=DISK
allocated channel: ORA_DISK_6
channel ORA_DISK_6: SID=197 device type=DISK

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 00005 to /u02/oradata/ORCL/datafile/o1_mf_test001_ds16fwnb_.dbf
channel ORA_DISK_1: reading from backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T022820_ds16l4h6_.bkp
channel ORA_DISK_1: piece handle=/u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T022820_ds16l4h6_.bkp tag=TAG20170814T022820
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 14-AUG-17

Starting recover at 14-AUG-17
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 14-AUG-17

sql statement: alter database datafile 5 online

Recovery Manager complete.
[oracle@hdp hm]$ 

再次查看文件的状态

SQL> col file_name for a15
SQL> col file_id for a15
SQL> col status for a15 
SQL> /

FILE_NAME      FILE_ID STATUS
--------------- ---------- ---------------
/u01/app/oracle ########## AVAILABLE
/oradata/orcl/u
sers01.dbf

/u01/app/oracle ########## AVAILABLE
/oradata/orcl/u
ndotbs01.dbf

/u01/app/oracle ########## AVAILABLE
/oradata/orcl/s
ysaux01.dbf

/u01/app/oracle ########## AVAILABLE
/oradata/orcl/s
ystem01.dbf

/u02/oradata/OR ########## AVAILABLE
CL/datafile/o1_
mf_test001_ds17
lv9r_.dbf

rman 甚至可以提前检测备份文件是否可以重建数据库

[oracle@hdp hm]$ rman target/

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Aug 14 03:08:17 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1477533441)

RMAN> RESTORE DATABASE VALIDATE;

Starting restore at 14-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=131 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=197 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=12 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=73 device type=DISK
allocated channel: ORA_DISK_5
channel ORA_DISK_5: SID=200 device type=DISK
allocated channel: ORA_DISK_6
channel ORA_DISK_6: SID=135 device type=DISK

datafile 4 not processed because file is offline
channel ORA_DISK_1: starting validation of datafile backup set
channel ORA_DISK_2: starting validation of datafile backup set
channel ORA_DISK_3: starting validation of datafile backup set
channel ORA_DISK_4: starting validation of datafile backup set
channel ORA_DISK_1: reading from backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15br2s_.bkp
channel ORA_DISK_2: reading from backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15br10_.bkp
channel ORA_DISK_3: reading from backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15bqy7_.bkp
channel ORA_DISK_4: reading from backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T022820_ds16l4h6_.bkp
channel ORA_DISK_1: piece handle=/u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15br2s_.bkp tag=TAG20170814T020719
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
channel ORA_DISK_4: piece handle=/u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T022820_ds16l4h6_.bkp tag=TAG20170814T022820
channel ORA_DISK_4: restored backup piece 1
channel ORA_DISK_4: validation complete, elapsed time: 00:00:01
channel ORA_DISK_2: piece handle=/u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15br10_.bkp tag=TAG20170814T020719
channel ORA_DISK_2: restored backup piece 1
channel ORA_DISK_2: validation complete, elapsed time: 00:00:03
channel ORA_DISK_3: piece handle=/u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15bqy7_.bkp tag=TAG20170814T020719
channel ORA_DISK_3: restored backup piece 1
channel ORA_DISK_3: validation complete, elapsed time: 00:00:03
Finished restore at 14-AUG-17

这里提示了我的datafile 4 是offline 状态

我移动一下备份集

[oracle@hdp backupset]$ mv 2017_08_14 2017_08_14.bak



RMAN> RESTORE DATABASE VALIDATE;

Starting restore at 14-AUG-17
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6

datafile 4 not processed because file is offline
channel ORA_DISK_1: starting validation of datafile backup set
channel ORA_DISK_2: starting validation of datafile backup set
channel ORA_DISK_3: starting validation of datafile backup set
channel ORA_DISK_4: starting validation of datafile backup set
channel ORA_DISK_1: reading from backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15br2s_.bkp
channel ORA_DISK_2: reading from backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15br10_.bkp
channel ORA_DISK_3: reading from backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15bqy7_.bkp
channel ORA_DISK_4: reading from backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T022820_ds16l4h6_.bkp
channel ORA_DISK_1: ORA-19870: error while restoring backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15br2s_.bkp
ORA-19505: failed to identify file "/u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15br2s_.bkp"
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

channel ORA_DISK_2: ORA-19870: error while restoring backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15br10_.bkp
ORA-19505: failed to identify file "/u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15br10_.bkp"
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

channel ORA_DISK_3: ORA-19870: error while restoring backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15bqy7_.bkp
ORA-19505: failed to identify file "/u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T020719_ds15bqy7_.bkp"
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

channel ORA_DISK_4: ORA-19870: error while restoring backup piece /u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T022820_ds16l4h6_.bkp
ORA-19505: failed to identify file "/u02/backup/ORCL/backupset/2017_08_14/o1_mf_nnndf_TAG20170814T022820_ds16l4h6_.bkp"
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

failover to previous backup

datafile 5 will be created automatically during restore operation
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 08/14/2017 03:11:14
RMAN-06026: some targets not found - aborting restore
RMAN-06023: no backup or copy of datafile 3 found to restore
RMAN-06023: no backup or copy of datafile 2 found to restore
RMAN-06023: no backup or copy of datafile 1 found to restore

RMAN> 

2017.9.2 add
值得注意到是,这次rman的restore过程,是直接绕过已经损坏的文件,新增了一个文件。

[oracle@hdp datafile]$ ll total 40980
-rw-r–r–. 1 oracle oinstall 0 Aug 14 02:44 advise
-rw-r–r–. 1 oracle oinstall 0 Aug 14 02:44 list
-rw-r—–. 1 oracle oinstall 20979728 Aug 14 02:32 o1_mf_test001_ds16fwnb_.dbf
-rw-r—–. 1 oracle oinstall 20979712 Aug 14 08:07 o1_mf_test001_ds17lv9r_.dbf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值