【ASM】ASMCMD 磁盘元数据的备份与恢复实践-阿里云开发者社区

开发者社区> 数据库> 正文

【ASM】ASMCMD 磁盘元数据的备份与恢复实践

简介:

1 实验目的
对于oracle10g版本的asm,很多功能还不够完善,比如就没有asm磁盘信息元数据有效的备份方式,如断电或者误操作导致asm磁盘头信息丢失,不得不重新创建asm磁盘组,通过备份的方式恢复数据,如果没有备份,则导致数据丢失。oracle11g 在asm命令工具asmcmd中增加了md_backup,md_restore两个命令可以很好的备份和恢复asm磁盘组元数据,使用这两个命令可以方便的备份和恢复asm磁盘的元数据。

2 实验环境
数据库版本     环境  数据库名  实例名IP地址操作系统和主机名
Oracle11.2.0.1 RAC   racdb
                     racdb1     192.168.1.227 Linux as 5.3+rac1
                     Racdb2     192.168.1.228 linux as 5.3+rac2
 
以上环境针对于磁盘组内磁盘头信息丢失恢复
3 实验步骤
3.1 md_backup备份磁盘组元数据
3.1.1查看磁盘组下的磁盘信息
[grid@rac1 ~]$ sqlplus / as sysdba
SQL*Plus: Release11.2.0.1.0 Production on Thu Jul 8 15:24:19 2010
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database11gEnterprise Edition Release11.2.0.1.0 - 64bit Production
With the Real Application Clusters and Automatic Storage Management options
SQL> select name,state from v$asm_diskgroup;
NAME STATE
------------------------------ -----------
CRS MOUNTED --CRS磁盘组(存放ocr和vote盘)
TESTDG MOUNTED
SQL> select name,path from v$asm_disk;
NAME PATH
TESTDG_0000 /dev/raw/raw1
3.1.2用kfed读取磁盘头信息
比如读取磁盘组TESTDG下/dev/raw/raw1磁盘头信息
[grid@rac1 amdu_2010_07_08_15_15_18]$ kfed read /dev/raw/raw1 > /home/grid/raw1bak.txt
[grid@rac1 amdu_2010_07_08_15_15_18]$ more /home/grid/raw1bak.txt
kfbh.endian: 1 ; 0x000: 0x01
kfbh.hard: 130 ; 0x001: 0x82
kfbh.type: 1 ; 0x002: KFBTYP_DISKHEAD
kfbh.datfmt: 1 ; 0x003: 0x01
kfbh.block.blk: 0 ; 0x004: T=0 NUMB=0x0
kfbh.block.obj: 2147483648 ; 0x008: TYPE=0x8 NUMB=0x0
kfbh.check: 534688621 ; 0x00c: 0x1fdeb36d
kfbh.fcn.base: 0 ; 0x010: 0x00000000
kfbh.fcn.wrap: 0 ; 0x014: 0x00000000
kfbh.spare1: 0 ; 0x018: 0x00000000
kfbh.spare2: 0 ; 0x01c: 0x00000000
kfdhdb.driver.provstr: ORCLDISK ; 0x000: length=8
kfdhdb.driver.reserved[0]: 0 ; 0x008: 0x00000000
kfdhdb.driver.reserved[1]: 0 ; 0x00c: 0x00000000
kfdhdb.driver.reserved[2]: 0 ; 0x010: 0x00000000
kfdhdb.driver.reserved[3]: 0 ; 0x014: 0x00000000
kfdhdb.driver.reserved[4]: 0 ; 0x018: 0x00000000
kfdhdb.driver.reserved[5]: 0 ; 0x01c: 0x00000000
kfdhdb.compat: 186646528 ; 0x020: 0x0b200000
kfdhdb.dsknum: 0 ; 0x024: 0x0000
kfdhdb.grptyp: 1 ; 0x026: KFDGTP_EXTERNAL
kfdhdb.hdrsts: 3 ; 0x027: KFDHDR_MEMBER
kfdhdb.dskname: TESTDG_0000 ; 0x028: length=11
kfdhdb.grpname: TESTDG ; 0x048: length=6
kfdhdb.fgname: TESTDG_0000 ; 0x068: length=11
kfdhdb.capname: ; 0x088: length=0
kfdhdb.crestmp.hi: 32939275 ; 0x0a8: HOUR=0xb DAYS=0x8 MNTH=0x7 YEAR=0x7da
kfdhdb.crestmp.lo: 3713031168 ; 0x0ac: USEC=0x0 MSEC=0x17 SECS=0x15 MINS=0x37
kfdhdb.mntstmp.hi: 32939275 ; 0x0b0: HOUR=0xb DAYS=0x8 MNTH=0x7 YEAR=0x7da
kfdhdb.mntstmp.lo: 3725327360 ; 0x0b4: USEC=0x0 MSEC=0x2ff SECS=0x20 MINS=0x37
kfdhdb.secsize: 512 ; 0x0b8: 0x0200
kfdhdb.blksize: 4096 ; 0x0ba: 0x1000
kfdhdb.ausize: 4194304 ; 0x0bc: 0x00400000
kfdhdb.mfact: 454272 ; 0x0c0: 0x0006ee80
kfdhdb.dsksize: 12799 ; 0x0c4: 0x000031ff
kfdhdb.pmcnt: 2 ; 0x0c8: 0x00000002
kfdhdb.fstlocn: 1 ; 0x0cc: 0x00000001
kfdhdb.altlocn: 2 ; 0x0d0: 0x00000002
kfdhdb.f1b1locn: 2 ; 0x0d4: 0x00000002
kfdhdb.redomirrors[0]: 0 ; 0x0d8: 0x0000
kfdhdb.redomirrors[1]: 0 ; 0x0da: 0x0000
kfdhdb.redomirrors[2]: 0 ; 0x0dc: 0x0000
kfdhdb.redomirrors[3]: 0 ; 0x0de: 0x0000
kfdhdb.dbcompat: 168820736 ; 0x0e0: 0x0a100000
kfdhdb.grpstmp.hi: 32939275 ; 0x0e4: HOUR=0xb DAYS=0x8 MNTH=0x7 YEAR=0x7da
kfdhdb.grpstmp.lo: 3712403456 ; 0x0e8: USEC=0x0 MSEC=0x1b2 SECS=0x14 MINS=0x37
kfdhdb.vfstart: 0 ; 0x0ec: 0x00000000
kfdhdb.vfend: 0 ; 0x0f0: 0x00000000
kfdhdb.spfile: 0 ; 0x0f4: 0x00000000
kfdhdb.spfflg: 0 ; 0x0f8: 0x00000000
kfdhdb.ub4spare[0]: 0 ; 0x0fc: 0x00000000
kfdhdb.ub4spare[1]: 0 ; 0x100: 0x00000000
kfdhdb.ub4spare[2]: 0 ; 0x104: 0x00000000
kfdhdb.ub4spare[3]: 0 ; 0x108: 0x00000000
kfdhdb.ub4spare[4]: 0 ; 0x10c: 0x00000000
kfdhdb.ub4spare[5]: 0 ; 0x110: 0x00000000
kfdhdb.ub4spare[6]: 0 ; 0x114: 0x00000000
kfdhdb.ub4spare[7]: 0 ; 0x118: 0x00000000
kfdhdb.ub4spare[8]: 0 ; 0x11c: 0x00000000
kfdhdb.ub4spare[9]: 0 ; 0x120: 0x00000000
kfdhdb.ub4spare[10]: 0 ; 0x124: 0x00000000
kfdhdb.ub4spare[11]: 0 ; 0x128: 0x00000000
kfdhdb.ub4spare[12]: 0 ; 0x12c: 0x00000000
kfdhdb.ub4spare[13]: 0 ; 0x130: 0x00000000
kfdhdb.ub4spare[14]: 0 ; 0x134: 0x00000000
kfdhdb.ub4spare[15]: 0 ; 0x138: 0x00000000
kfdhdb.ub4spare[16]: 0 ; 0x13c: 0x00000000
kfdhdb.ub4spare[17]: 0 ; 0x140: 0x00000000
kfdhdb.ub4spare[18]: 0 ; 0x144: 0x00000000
kfdhdb.ub4spare[19]: 0 ; 0x148: 0x00000000
kfdhdb.ub4spare[20]: 0 ; 0x14c: 0x00000000
kfdhdb.ub4spare[21]: 0 ; 0x150: 0x00000000
kfdhdb.ub4spare[22]: 0 ; 0x154: 0x00000000
kfdhdb.ub4spare[23]: 0 ; 0x158: 0x00000000
kfdhdb.ub4spare[24]: 0 ; 0x15c: 0x00000000
kfdhdb.ub4spare[25]: 0 ; 0x160: 0x00000000
kfdhdb.ub4spare[26]: 0 ; 0x164: 0x00000000
kfdhdb.ub4spare[27]: 0 ; 0x168: 0x00000000
kfdhdb.ub4spare[28]: 0 ; 0x16c: 0x00000000
kfdhdb.ub4spare[29]: 0 ; 0x170: 0x00000000
kfdhdb.ub4spare[30]: 0 ; 0x174: 0x00000000
kfdhdb.ub4spare[31]: 0 ; 0x178: 0x00000000
kfdhdb.ub4spare[32]: 0 ; 0x17c: 0x00000000
kfdhdb.ub4spare[33]: 0 ; 0x180: 0x00000000
kfdhdb.ub4spare[34]: 0 ; 0x184: 0x00000000
kfdhdb.ub4spare[35]: 0 ; 0x188: 0x00000000
kfdhdb.ub4spare[36]: 0 ; 0x18c: 0x00000000
kfdhdb.ub4spare[37]: 0 ; 0x190: 0x00000000
kfdhdb.ub4spare[38]: 0 ; 0x194: 0x00000000
kfdhdb.ub4spare[39]: 0 ; 0x198: 0x00000000
kfdhdb.ub4spare[40]: 0 ; 0x19c: 0x00000000
kfdhdb.ub4spare[41]: 0 ; 0x1a0: 0x00000000
kfdhdb.ub4spare[42]: 0 ; 0x1a4: 0x00000000
kfdhdb.ub4spare[43]: 0 ; 0x1a8: 0x00000000
kfdhdb.ub4spare[44]: 0 ; 0x1ac: 0x00000000
kfdhdb.ub4spare[45]: 0 ; 0x1b0: 0x00000000
kfdhdb.ub4spare[46]: 0 ; 0x1b4: 0x00000000
kfdhdb.ub4spare[47]: 0 ; 0x1b8: 0x00000000
kfdhdb.ub4spare[48]: 0 ; 0x1bc: 0x00000000
kfdhdb.ub4spare[49]: 0 ; 0x1c0: 0x00000000
kfdhdb.ub4spare[50]: 0 ; 0x1c4: 0x00000000
kfdhdb.ub4spare[51]: 0 ; 0x1c8: 0x00000000
kfdhdb.ub4spare[52]: 0 ; 0x1cc: 0x00000000
kfdhdb.ub4spare[53]: 0 ; 0x1d0: 0x00000000
kfdhdb.acdb.aba.seq: 0 ; 0x1d4: 0x00000000
kfdhdb.acdb.aba.blk: 0 ; 0x1d8: 0x00000000
kfdhdb.acdb.ents: 0 ; 0x1dc: 0x0000
kfdhdb.acdb.ub2spare: 0 ; 0x1de: 0x0000
从上面读出的内容,我们可以获取以下信息:

dsknum磁盘号

grptyp磁盘所属类型EXTERNAL REDUNDANCY,主要有以下三种类型

NORMAL REDUNDANCY- Two-way mirroring, requiring two failure groups.
HIGH REDUNDANCY- Three-way mirroring, requiring three failure groups.
EXTERNAL REDUNDANCY- No mirroring for disks that are already protected using hardware mirroring or RAID.
ddrsts      磁盘头状态
dskname在asm中磁盘名
grpname 磁盘组名
fgname failure group name
crestmp.hi   asm磁盘组创建时间
mntstmp.hi   asm磁盘组mount时间
blksize 磁盘头块大小4096
ausize 条带化大小4M
dsksize磁盘大小
f1b1locn File Directory blk 1 AU num   Beginging for file directory
        
3.2 Md_backup备份
[grid@rac1 amdu_2010_07_08_15_15_18]$ asmcmd md_backup /home/grid/asmbk -G 'TESTDG'
Disk group metadata to be backed up: TESTDG
Current alias directory path: rac-cluster/OCRFILE
Current alias directory path: rac-cluster
Current alias directory path: rac-cluster/ASMPARAMETERFILE

3.3 模拟磁盘头信息丢失
[grid@rac1 ~]$ dd if=/dev/zero f=/dev/raw/raw1 bs=4096 count=1
1+0 records in
1+0 records out
4096 bytes (4.1 kB) copied, 0.016114 seconds, 254 kB/s

[grid@rac1 ~]$ kfed read /dev/raw/raw1
kfbh.endian: 0 ; 0x000: 0x00
kfbh.hard: 0 ; 0x001: 0x00
kfbh.type: 0 ; 0x002: KFBTYP_INVALID
kfbh.datfmt: 0 ; 0x003: 0x00
kfbh.block.blk: 0 ; 0x004: T=0 NUMB=0x0
kfbh.block.obj: 0 ; 0x008: TYPE=0x0 NUMB=0x0
kfbh.check: 0 ; 0x00c: 0x00000000
kfbh.fcn.base: 0 ; 0x010: 0x00000000
kfbh.fcn.wrap: 0 ; 0x014: 0x00000000
kfbh.spare1: 0 ; 0x018: 0x00000000
kfbh.spare2: 0 ; 0x01c: 0x00000000
ERROR!!!, failed to get the oracore error message
这时磁盘组testdg下/dev/raw/raw1磁盘头信息丢失,不能正常读取
SQL> alter diskgroup testdg dismount;
Diskgroupaltered.
SQL> alter diskgroup testdg mount;
alter diskgroup testdg mount
*
ERROR at line 1:
ORA-15032: not all alterations performed
ORA-15017: diskgroup "TESTDG" cannot be mounted
ORA-15063: ASM discovered an insufficient number of disks for diskgroup
"TESTDG"

可以看到testdg不能正常提供对外访问。
3.4 md_restore命令恢复磁盘组元数据
3.4.1所有节点把testdg服务offline

Srvctl stop diskgroup –g testdg


否则恢复时会报ORA-15030错误
[grid@rac1 ~]$ asmcmd md_restore /home/grid/asmbk.txt --silent -G 'testdg'
Current Diskgroup metadata being restored: TESTDG
ASMCMD-09352: CREATE DISKGROUP failed
ORA-15018: diskgroup cannot be created
ORA-15030: diskgroup name "TESTDG" is in use by another diskgroup (DBD ERROR: OCIStmtExecute)

3.4.2恢复磁盘组元数据库
[grid@rac1 ~]$ asmcmd md_restore /home/grid/asmbk --silent -G 'testdg'
Current Diskgroup metadata being restored: TESTDG
Diskgroup TESTDG created!
System template ONLINELOG modified!
System template AUTOBACKUP modified!
System template ASMPARAMETERFILE modified!
System template OCRFILE modified!
System template ASM_STALE modified!
System template OCRBACKUP modified!
System template PARAMETERFILE modified!
System template ASMPARAMETERBAKFILE modified!
System template FLASHFILE modified!
System template XTRANSPORT modified!
System template DATAGUARDCONFIG modified!
System template TEMPFILE modified!
System template ARCHIVELOG modified!
System template CONTROLFILE modified!
System template DUMPSET modified!
System template BACKUPSET modified!
System template FLASHBACK modified!
System template DATAFILE modified!
System template CHANGETRACKING modified!
[grid@rac1 ~]$

3.4.3所有节点包testdg服务online
[grid@rac1 ~]$srvctl start diskgroup -g testdg
[grid@rac1 ~]$ sqlplus "/as sysasm"
SQL*Plus: Release11.2.0.1.0 Production on Thu Jul 8 16:43:53 2010
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database11gEnterprise Edition Release11.2.0.1.0 - 64bit Production
With the Real Application Clusters and Automatic Storage Management options

SQL> select name,state from v$asm_diskgroup;
NAME STATE
---------------
CRS    MOUNTED
TESTDG MOUNTED

可以看到磁盘组testdg恢复成功。
3.5 总结
Oracle11gasm磁盘组内元数据备份与恢复非常简单,只需要我们安装完成后做好备份工作即可。

转自:http://space.itpub.net/7199859/viewspace-667730

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
数据库
使用钉钉扫一扫加入圈子
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

其他文章