Posted:March 4,2012 |Author:Cui Hua|Filed under:Oracle|2Comments »
AMDU是Oracle11g里自带的一个免费的工具,用于分析ASM磁盘组的元数据以及从不能mount的磁盘组中往外抽取数据文件。
“NOTE:553639.1 Placeholder for AMDU binaries and using with ASM10g”明确指出: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: Release11.2.0.1.0 Production on Thu Feb 23 10:43:36 2012
Copyright (c) 1982,2009,Oracle.All rights reserved.
Connected to:
Oracle Database11gEnterpriseEdition Release11.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 Database11gEnterpriseEdition Release11.2.0.1.0 – Production
With the Partitioning,Data Mining
and Real Application Testing options
[oracle@bspdev ~]$ su – grid
Password:
[grid@bspdev ~]$ sqlplus ‘/ as sysasm’;
sql*Plus: Release11.2.0.1.0 Production on Thu Feb 23 10:45:05 2012
With the Automatic Storage Management option
sql> shutdown immediate
ASM diskgroups dismounted
ASM instance shutdown
sql> exit
Disconnected from Oracle Database11gEnterpriseEdition Release11.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
NAME=ora.asm
TYPE=ora.asm.type
NAME=ora.cssd
TYPE=ora.cssd.type
NAME=ora.diskmon
TYPE=ora.diskmon.type
NAME=ora.ora11g.db
TYPE=ora.database.type
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:Release4.2.1
Copyright (c) 2008,2010,2011 XiongJun. All rights reserved.
Web: http://www.oracleodu.com
Email: magic007cn@gmail.com
loading default config…….
byte_order little
block_size8192
block_buffers 1024
db_timezone -7
Invalid db timezone:-7
client_timezone 8
Invalid client timezone:8
asmfile_extract_path/odu/asmfile
data_pathdata
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_lobyes
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 disknamegroupnamepath
—- —- —– —— ——– ————— ————— ——————————————–
1040961024K9000 DATA_0000DATA/dev/sda3
1140961024K9000 DATA_0001DATA/dev/sda5
1240961024K9000 DATA_0002DATA/dev/sda6
2040961024K9000 RECO_0000RECO/dev/sda7
2140961024K7288 RECO_0001RECO/dev/sda8
load asm disk file ‘asmdisk.txt’ successful
loading default control file ……
ts#fnrfn bsizeblocks 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
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
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 root8600 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
0118192112640 N0 +DATA/ORA11G/DATAFILE/SYSTEM.256.747310449
1228192119040 N0 +DATA/ORA11G/DATAFILE/SYSAUX.257.747310449
233819270400 N0 +DATA/ORA11G/DATAFILE/UNDOTBS1.258.747310451
44481924960 N0 +DATA/ORA11G/DATAFILE/USERS.259.747310451
load control file ‘oductl.dat’ successful
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 root40640512Feb 23 11:21 DATA_259.f
-rw-r–r–. 1 root root40640512Feb 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: Release11.2.0.1.0 – Production on Thu Feb 23 11:29:50 2012
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: Release11.2.0.1.0 – Production on Thu Feb 23 11:30:11 2012
DBVERIFY – Verification starting : FILE = /u01/app/oracle/odu/amdu_2012_02_23_11_21_34/user01.dbf
Highest block SCN: 2132237218 (1932.2132237218)