硬盘故障数据库恢复 amdu 使用小记

来源:互联网 发布:vmware mac os 流畅 编辑:程序博客网 时间:2024/05/01 06:39
2012年9月份,东南亚印尼现场的磁阵出现问题, ASM实例不能启动,通过amdu 恢复了6T的数据,http://space.itpub.net/?uid-8013558-action-viewspace-itemid-746078
一直没有一像样的amdu 的使用文档。现有转自来自崔华老师

http://www.dbsnake.net/amdu-extract-asm-files-from-unmount-diskgroup.html


Posted: March 4, 2012 | Author: Cui Hua | Filed under: Oracle | 2 Comments ?

AMDU是Oracle 11g里自带的一个免费的工具,用于分析ASM磁盘组的元数据以及从不能mount的磁盘组中往外抽取数据文件。

“NOTE:553639.1 Placeholder for AMDU binaries and using with ASM 10g”明确指出:AMDU也可用于10g,并提供了可用于10g的AMDU的各个操作系统的版本供大家下载。



AMDU的原理是解析file directory,这一点ODU也是一样,只不过ODU做的更彻底一些,即使file directory全部损坏,ODU也可以把数据文件抽取出来,尽最大的可能挽救用户的数据。



我们来看一个用AMDU从不能mount的磁盘组中往外抽取数据文件的实例:

我们现在shutdown Oracle实例和ASM实例:

[root@bspdev odu]# su – oracle

[oracle@bspdev ~]$ sqlplus ‘/ as sysdba’;



SQL*Plus: Release 11.2.0.1.0 Production on Thu Feb 23 10:43:36 2012



Copyright (c) 1982, 2009, Oracle.  All rights reserved.





Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 – Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options



SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.



SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 – Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options



[oracle@bspdev ~]$ su – grid

Password:

[grid@bspdev ~]$ sqlplus ‘/ as sysasm’;



SQL*Plus: Release 11.2.0.1.0 Production on Thu Feb 23 10:45:05 2012



Copyright (c) 1982, 2009, Oracle.  All rights reserved.





Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 – Production

With the Automatic Storage Management option



SQL> shutdown immediate

ASM diskgroups dismounted

ASM instance shutdown



SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 – Production

With the Automatic Storage Management option



[grid@bspdev ~]$ crsctl status res

NAME=ora.DATA.dg

TYPE=ora.diskgroup.type

TARGET=OFFLINE

STATE=OFFLINE



NAME=ora.LISTENER.lsnr

TYPE=ora.listener.type

TARGET=ONLINE

STATE=ONLINE on bspdev



NAME=ora.RECO.dg

TYPE=ora.diskgroup.type

TARGET=OFFLINE

STATE=OFFLINE



NAME=ora.asm

TYPE=ora.asm.type

TARGET=OFFLINE

STATE=OFFLINE



NAME=ora.cssd

TYPE=ora.cssd.type

TARGET=ONLINE

STATE=ONLINE on bspdev



NAME=ora.diskmon

TYPE=ora.diskmon.type

TARGET=ONLINE

STATE=ONLINE on bspdev



NAME=ora.ora11g.db

TYPE=ora.database.type

TARGET=OFFLINE

STATE=OFFLINE



在ASM diskgroup不能mount的情况下asmcmd不能使用:

[grid@bspdev ~]$ asmcmd

Connected to an idle instance.

ASMCMD> ls

ASMCMD-08102: no connection to ASM; command requires ASM to run



但此时ODU内嵌的asmcmd是可以使用的,所以我们可以轻易的使用ODU内嵌的asmcmd命令来得到所有的datafile的名称:

[grid@bspdev ~]$ su -

Password:

[root@bspdev ~]# cd /u01/app/oracle/odu

[root@bspdev odu]# ./odu



Oracle Data Unloader:Release 4.2.1



Copyright (c) 2008,2009,2010,2011 XiongJun. All rights reserved.



Web: http://www.oracleodu.com

Email: magic007cn@gmail.com



loading default config…….



byte_order little

block_size  8192

block_buffers 1024

db_timezone -7

Invalid db timezone:-7

client_timezone 8

Invalid client timezone:8

asmfile_extract_path   /odu/asmfile

data_path   data

lob_path    /odu/data/lob

charset_name AL32UTF8

ncharset_name AL16UTF16

output_format text

lob_storage infile

clob_byte_order big

trace_level 1

delimiter |

unload_deleted no

file_header_offset 0

is_tru64 no

record_row_addr no

convert_clob_charset yes

use_scanned_lob  yes

trim_scanned_blob yes

lob_switch_dir_rows 20000

db_block_checksum yes

db_block_checking yes

rdba_file_bits 10

compatible 10

load config file ‘config.txt’ successful

loading default asm disk file ……





grp# dsk# bsize ausize disksize diskname        groupname       path

—- —- —– —— ——– ————— ————— ——————————————–

   1    0  4096  1024K     9000 DATA_0000       DATA            /dev/sda3

   1    1  4096  1024K     9000 DATA_0001       DATA            /dev/sda5

   1    2  4096  1024K     9000 DATA_0002       DATA            /dev/sda6

   2    0  4096  1024K     9000 RECO_0000       RECO            /dev/sda7

   2    1  4096  1024K     7288 RECO_0001       RECO            /dev/sda8



load asm disk file ‘asmdisk.txt’ successful

loading default control file ……





ts#   fn  rfn bsize   blocks bf offset filename

—- —- —- —– ——– — —— ——————————————–

load control file ‘control.txt’ successful

loading dictionary data……done



loading scanned data……done



ODU> asmcmd



Entering asmcmd module.



ASMCMD> ls



Current directory: <root>



Disk Group

————————————

DATA

RECO



ASMCMD> cd +DATA



Current directory: +DATA



ASMCMD> ls 



Current directory: +DATA



Name                                  

—————————————-

ASM                                       <DIR>

ORA11G                                    <DIR>



ASMCMD> cd ORA11G



Current directory: +DATA/ORA11G



ASMCMD> ls



Current directory: +DATA/ORA11G



Name                                  

—————————————-

DATAFILE                                  <DIR>

CONTROLFILE                               <DIR>

ONLINELOG                                 <DIR>

TEMPFILE                                  <DIR>

PARAMETERFILE                             <DIR>

spfileora11g.ora                           => +DATA.265.747311071



ASMCMD> cd DATAFILE  



Current directory: +DATA/ORA11G/DATAFILE



可以看到,当前的第259号(这个259是ASM的internal file number)文件名称为+DATA/ORA11G/DATAFILE / USERS.259.747310451:

ASMCMD> ls



Current directory: +DATA/ORA11G/DATAFILE



Name                                  

—————————————-

SYSTEM.256.747310449                  

SYSAUX.257.747310449                  

UNDOTBS1.258.747310451                

USERS.259.747310451                   

MYTEST.266.761050749                  

GAOZCINDEX.267.770299335              

GAOZCINDEX1                                => +DATA.267.770299335

GAOZCDATA.268.770299347               

GAOZCDATA1                                 => +DATA.268.770299347



现在我们用AMDU把这个文件给抽出来,注意现在这个文件所在的磁盘组DATA还是处于unmount状态。

用AMDU抽取数据文件的语法非常简单,只需要指定磁盘组所在的设备文件名称(可以用*号模糊匹配),以及磁盘组的名称和待抽取的数据文件号(这里的数据文件号是指ASM的internal file number)就可以了:

[root@bspdev odu]# /u01/app/oracle/bin/amdu -diskstring ‘/dev/sda*’ -extract ‘DATA.259′

amdu_2012_02_23_11_21_34/



进入上述目录,可以看到抽取出的第259号文件DATA_259.f已经生成:

[root@bspdev odu]# cd amdu_2012_02_23_11_21_34



[root@bspdev amdu_2012_02_23_11_21_34]# ls -lrt

total 39744

-rw-r–r–. 1 root root     8600 Feb 23 11:21 report.txt

-rw-r–r–. 1 root root 40640512 Feb 23 11:21 DATA_259.f



我们现在再用ODU把259号文件提出来,跟AMDU做一个对比:

[root@bspdev amdu_2012_02_23_11_21_34]# cd ..

[root@bspdev odu]# ./odu



Oracle Data Unloader:Release 4.2.1



Copyright (c) 2008,2009,2010,2011 XiongJun. All rights reserved.



Web: http://www.oracleodu.com

Email: magic007cn@gmail.com



loading default config…….



byte_order little

block_size  8192

block_buffers 1024

db_timezone -7

Invalid db timezone:-7

client_timezone 8

Invalid client timezone:8

asmfile_extract_path   /odu/asmfile

data_path   data

lob_path    /odu/data/lob

charset_name AL32UTF8

ncharset_name AL16UTF16

output_format text

lob_storage infile

clob_byte_order big

trace_level 1

delimiter |

unload_deleted no

file_header_offset 0

is_tru64 no

record_row_addr no

convert_clob_charset yes

use_scanned_lob  yes

trim_scanned_blob yes

lob_switch_dir_rows 20000

db_block_checksum yes

db_block_checking yes

rdba_file_bits 10

compatible 10

load config file ‘config.txt’ successful

loading default asm disk file ……





grp# dsk# bsize ausize disksize diskname        groupname       path

—- —- —– —— ——– ————— ————— ——————————————–

   1    0  4096  1024K     9000 DATA_0000       DATA            /dev/sda3

   1    1  4096  1024K     9000 DATA_0001       DATA            /dev/sda5

   1    2  4096  1024K     9000 DATA_0002       DATA            /dev/sda6

   2    0  4096  1024K     9000 RECO_0000       RECO            /dev/sda7

   2    1  4096  1024K     7288 RECO_0001       RECO            /dev/sda8



load asm disk file ‘asmdisk.txt’ successful

loading default control file ……





ts#   fn  rfn bsize   blocks bf offset filename

—- —- —- —– ——– — —— ——————————————–

   0    1    1  8192   112640 N       0 +DATA/ORA11G/DATAFILE/SYSTEM.256.747310449

   1    2    2  8192   119040 N       0 +DATA/ORA11G/DATAFILE/SYSAUX.257.747310449

   2    3    3  8192    70400 N       0 +DATA/ORA11G/DATAFILE/UNDOTBS1.258.747310451

   4    4    4  8192     4960 N       0 +DATA/ORA11G/DATAFILE/USERS.259.747310451

load control file ‘oductl.dat’ successful

loading dictionary data……done



loading scanned data……done



ODU> asmcmd



Entering asmcmd module.



注意:ODU的最新版本中extract命令已被copy命令替换了:

ASMCMD> extract asmfile +DATA/ORA11G/DATAFILE/USERS.259.747310451 to /u01/app/oracle/odu/amdu_2012_02_23_11_21_34/user01.dbf



starting extract asm file ‘+DATA/ORA11G/DATAFILE/USERS.259.747310451′ to ‘/u01/app/oracle/odu/amdu_2012_02_23_11_21_34/user01.dbf’,file size is 40640512

asm file extract completed.



ASMCMD> exit



Exiting asmcmd module.



[root@bspdev odu]# cd amdu_2012_02_23_11_21_34

[root@bspdev amdu_2012_02_23_11_21_34]# ls -lrt

total 79476

-rw-r–r–. 1 root root     8600 Feb 23 11:21 report.txt

-rw-r–r–. 1 root root 40640512 Feb 23 11:21 DATA_259.f

-rw-r–r–. 1 root root 40640512 Feb 23 11:27 user01.dbf

从结果里可以看到,两者大小一模一样。



从dbv校验的结果来看,两者内容也是一模一样:

[oracle@bspdev ~]$ dbv file=/u01/app/oracle/odu/amdu_2012_02_23_11_21_34/DATA_259.f blocksize=8192



DBVERIFY: Release 11.2.0.1.0 – Production on Thu Feb 23 11:29:50 2012



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



DBVERIFY – Verification starting : FILE = /u01/app/oracle/odu/amdu_2012_02_23_11_21_34/DATA_259.f





DBVERIFY – Verification complete



Total Pages Examined         : 4960

Total Pages Processed (Data) : 4442

Total Pages Failing   (Data) : 0

Total Pages Processed (Index): 33

Total Pages Failing   (Index): 0

Total Pages Processed (Other): 334

Total Pages Processed (Seg)  : 0

Total Pages Failing   (Seg)  : 0

Total Pages Empty            : 151

Total Pages Marked Corrupt   : 0

Total Pages Influx           : 0

Total Pages Encrypted        : 0

Highest block SCN            : 2132237218 (1932.2132237218)



[oracle@bspdev ~]$ dbv file=/u01/app/oracle/odu/amdu_2012_02_23_11_21_34/user01.dbf blocksize=8192



DBVERIFY: Release 11.2.0.1.0 – Production on Thu Feb 23 11:30:11 2012



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



DBVERIFY – Verification starting : FILE = /u01/app/oracle/odu/amdu_2012_02_23_11_21_34/user01.dbf





DBVERIFY – Verification complete



Total Pages Examined         : 4960

Total Pages Processed (Data) : 4442

Total Pages Failing   (Data) : 0

Total Pages Processed (Index): 33

Total Pages Failing   (Index): 0

Total Pages Processed (Other): 334

Total Pages Processed (Seg)  : 0

Total Pages Failing   (Seg)  : 0

Total Pages Empty            : 151

Total Pages Marked Corrupt   : 0

Total Pages Influx           : 0

Total Pages Encrypted        : 0

Highest block SCN            : 2132237218 (1932.2132237218)

原创粉丝点击