oracle 11g md_backup与md_restor命令使用方法(asm磁盘头备份与恢复)
本帖最后由 paulyi 于 2014-2-18 18:46 编辑
oracle 11g md_backup与md_restor命令使用方法(asm磁盘头备份与恢复)
1 实验目的 [color=navy]由于oracle 10g asm存储方式是推出的第一个版本,很多功能没完善,比如就没有asm磁盘信息元数据有效的备份方式,如果误操作导致asm磁盘头信息丢失,而很多人对asm磁盘头信息不熟悉,不得不重新创建asm磁盘组,通过备份的方式恢复数据,如果无备份的话,则导致数据丢失。虽然我已经掌握了oracle 10g asm磁盘头信息损坏后能够及时恢复的技术,但操作起来还是比较麻烦。[color=navy]oracle 11g已经对asmcmd工具增加了md_backup,md_restore两个命令可以很好的备份和恢复asm磁盘组元数据,使的这一操作变的非常简单,下面实验就是来学习md_backup和md_restore的使用方法。[color=navy]Oracle 11g kfed、amdu查看磁盘头信息命令可以直接使用,不需要再编译。
2 实验环境 [table=510]
[td=126][align=right]数据库版本[td=38]环境[td=54]数据库名[td=62]实例名[td=110]IP地址[td=118]操作系统和主机名
[td=126][align=right]所[td=38][td=54][td=62][td=110][td=118]
[td=1,2,126][align=right]Oracle11.2.0.1[td=1,2,38]RAC[td=1,2,54]racdb[td=62]racdb1[td=110]192.168.1.227[td=118]Linux as 5.3+rac1
[td=62]Racdb2[td=110]192.168.1.228[td=118]linux as 5.3+rac2
以上环境针对于磁盘组内磁盘头信息丢失恢复
3 实验步骤
3.1 md_backup 备份磁盘组元数据
3.1.1 查看磁盘组下的磁盘信息
[grid@rac1 ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.1.0 Production on Thu Jul 8 15:24:19 2010Copyright (c) 1982, 2009, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Real Application Clusters and Automatic Storage Management optionsSQL> select name,state from v$asm_diskgroup;NAME STATE------------------------------ -----------CRS MOUNTED --CRS磁盘组(存放ocr和vote盘)TESTDG MOUNTEDSQL> select name,path from v$asm_disk;NAME PATHTESTDG_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.txtkfbh.endian: 1 ; 0x000: 0x01kfbh.hard: 130 ; 0x001: 0x82kfbh.type: 1 ; 0x002: KFBTYP_DISKHEADkfbh.datfmt: 1 ; 0x003: 0x01kfbh.block.blk: 0 ; 0x004: T=0 NUMB=0x0kfbh.block.obj: 2147483648 ; 0x008: TYPE=0x8 NUMB=0x0kfbh.check: 534688621 ; 0x00c: 0x1fdeb36dkfbh.fcn.base: 0 ; 0x010: 0x00000000kfbh.fcn.wrap: 0 ; 0x014: 0x00000000kfbh.spare1: 0 ; 0x018: 0x00000000kfbh.spare2: 0 ; 0x01c: 0x00000000kfdhdb.driver.provstr: ORCLDISK ; 0x000: length=8kfdhdb.driver.reserved[0]: 0 ; 0x008: 0x00000000kfdhdb.driver.reserved[1]: 0 ; 0x00c: 0x00000000kfdhdb.driver.reserved[2]: 0 ; 0x010: 0x00000000kfdhdb.driver.reserved[3]: 0 ; 0x014: 0x00000000kfdhdb.driver.reserved[4]: 0 ; 0x018: 0x00000000kfdhdb.driver.reserved[5]: 0 ; 0x01c: 0x00000000kfdhdb.compat: 186646528 ; 0x020: 0x0b200000kfdhdb.dsknum: 0 ; 0x024: 0x0000kfdhdb.grptyp: 1 ; 0x026: KFDGTP_EXTERNALkfdhdb.hdrsts: 3 ; 0x027: KFDHDR_MEMBERkfdhdb.dskname: TESTDG_0000 ; 0x028: length=11kfdhdb.grpname: TESTDG ; 0x048: length=6kfdhdb.fgname: TESTDG_0000 ; 0x068: length=11kfdhdb.capname: ; 0x088: length=0kfdhdb.crestmp.hi: 32939275 ; 0x0a8: HOUR=0xb DAYS=0x8 MNTH=0x7 YEAR=0x7dakfdhdb.crestmp.lo: 3713031168 ; 0x0ac: USEC=0x0 MSEC=0x17 SECS=0x15 MINS=0x37kfdhdb.mntstmp.hi: 32939275 ; 0x0b0: HOUR=0xb DAYS=0x8 MNTH=0x7 YEAR=0x7dakfdhdb.mntstmp.lo: 3725327360 ; 0x0b4: USEC=0x0 MSEC=0x2ff SECS=0x20 MINS=0x37kfdhdb.secsize: 512 ; 0x0b8: 0x0200kfdhdb.blksize: 4096 ; 0x0ba: 0x1000kfdhdb.ausize: 4194304 ; 0x0bc: 0x00400000kfdhdb.mfact: 454272 ; 0x0c0: 0x0006ee80kfdhdb.dsksize: 12799 ; 0x0c4: 0x000031ffkfdhdb.pmcnt: 2 ; 0x0c8: 0x00000002kfdhdb.fstlocn: 1 ; 0x0cc: 0x00000001kfdhdb.altlocn: 2 ; 0x0d0: 0x00000002kfdhdb.f1b1locn: 2 ; 0x0d4: 0x00000002kfdhdb.redomirrors[0]: 0 ; 0x0d8: 0x0000kfdhdb.redomirrors[1]: 0 ; 0x0da: 0x0000kfdhdb.redomirrors[2]: 0 ; 0x0dc: 0x0000kfdhdb.redomirrors[3]: 0 ; 0x0de: 0x0000kfdhdb.dbcompat: 168820736 ; 0x0e0: 0x0a100000kfdhdb.grpstmp.hi: 32939275 ; 0x0e4: HOUR=0xb DAYS=0x8 MNTH=0x7 YEAR=0x7dakfdhdb.grpstmp.lo: 3712403456 ; 0x0e8: USEC=0x0 MSEC=0x1b2 SECS=0x14 MINS=0x37kfdhdb.vfstart: 0 ; 0x0ec: 0x00000000kfdhdb.vfend: 0 ; 0x0f0: 0x00000000kfdhdb.spfile: 0 ; 0x0f4: 0x00000000kfdhdb.spfflg: 0 ; 0x0f8: 0x00000000kfdhdb.ub4spare[0]: 0 ; 0x0fc: 0x00000000kfdhdb.ub4spare[1]: 0 ; 0x100: 0x00000000kfdhdb.ub4spare[2]: 0 ; 0x104: 0x00000000kfdhdb.ub4spare[3]: 0 ; 0x108: 0x00000000kfdhdb.ub4spare[4]: 0 ; 0x10c: 0x00000000kfdhdb.ub4spare[5]: 0 ; 0x110: 0x00000000kfdhdb.ub4spare[6]: 0 ; 0x114: 0x00000000kfdhdb.ub4spare[7]: 0 ; 0x118: 0x00000000kfdhdb.ub4spare[8]: 0 ; 0x11c: 0x00000000kfdhdb.ub4spare[9]: 0 ; 0x120: 0x00000000kfdhdb.ub4spare[10]: 0 ; 0x124: 0x00000000kfdhdb.ub4spare[11]: 0 ; 0x128: 0x00000000kfdhdb.ub4spare[12]: 0 ; 0x12c: 0x00000000kfdhdb.ub4spare[13]: 0 ; 0x130: 0x00000000kfdhdb.ub4spare[14]: 0 ; 0x134: 0x00000000kfdhdb.ub4spare[15]: 0 ; 0x138: 0x00000000kfdhdb.ub4spare[16]: 0 ; 0x13c: 0x00000000kfdhdb.ub4spare[17]: 0 ; 0x140: 0x00000000kfdhdb.ub4spare[18]: 0 ; 0x144: 0x00000000kfdhdb.ub4spare[19]: 0 ; 0x148: 0x00000000kfdhdb.ub4spare[20]: 0 ; 0x14c: 0x00000000kfdhdb.ub4spare[21]: 0 ; 0x150: 0x00000000kfdhdb.ub4spare[22]: 0 ; 0x154: 0x00000000kfdhdb.ub4spare[23]: 0 ; 0x158: 0x00000000kfdhdb.ub4spare[24]: 0 ; 0x15c: 0x00000000kfdhdb.ub4spare[25]: 0 ; 0x160: 0x00000000kfdhdb.ub4spare[26]: 0 ; 0x164: 0x00000000kfdhdb.ub4spare[27]: 0 ; 0x168: 0x00000000kfdhdb.ub4spare[28]: 0 ; 0x16c: 0x00000000kfdhdb.ub4spare[29]: 0 ; 0x170: 0x00000000kfdhdb.ub4spare[30]: 0 ; 0x174: 0x00000000kfdhdb.ub4spare[31]: 0 ; 0x178: 0x00000000kfdhdb.ub4spare[32]: 0 ; 0x17c: 0x00000000kfdhdb.ub4spare[33]: 0 ; 0x180: 0x00000000kfdhdb.ub4spare[34]: 0 ; 0x184: 0x00000000kfdhdb.ub4spare[35]: 0 ; 0x188: 0x00000000kfdhdb.ub4spare[36]: 0 ; 0x18c: 0x00000000kfdhdb.ub4spare[37]: 0 ; 0x190: 0x00000000kfdhdb.ub4spare[38]: 0 ; 0x194: 0x00000000kfdhdb.ub4spare[39]: 0 ; 0x198: 0x00000000kfdhdb.ub4spare[40]: 0 ; 0x19c: 0x00000000kfdhdb.ub4spare[41]: 0 ; 0x1a0: 0x00000000kfdhdb.ub4spare[42]: 0 ; 0x1a4: 0x00000000kfdhdb.ub4spare[43]: 0 ; 0x1a8: 0x00000000kfdhdb.ub4spare[44]: 0 ; 0x1ac: 0x00000000kfdhdb.ub4spare[45]: 0 ; 0x1b0: 0x00000000kfdhdb.ub4spare[46]: 0 ; 0x1b4: 0x00000000kfdhdb.ub4spare[47]: 0 ; 0x1b8: 0x00000000kfdhdb.ub4spare[48]: 0 ; 0x1bc: 0x00000000kfdhdb.ub4spare[49]: 0 ; 0x1c0: 0x00000000kfdhdb.ub4spare[50]: 0 ; 0x1c4: 0x00000000kfdhdb.ub4spare[51]: 0 ; 0x1c8: 0x00000000kfdhdb.ub4spare[52]: 0 ; 0x1cc: 0x00000000kfdhdb.ub4spare[53]: 0 ; 0x1d0: 0x00000000kfdhdb.acdb.aba.seq: 0 ; 0x1d4: 0x00000000kfdhdb.acdb.aba.blk: 0 ; 0x1d8: 0x00000000kfdhdb.acdb.ents: 0 ; 0x1dc: 0x0000kfdhdb.acdb.ub2spare: 0 ; 0x1de: 0x0000
从上面读出的内容,我们可以获取以下信息:dsknum 磁盘号grptyp 磁盘所属类型EXTERNAL REDUNDANCY,主要有以下三种类型[list]
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 namecrestmp.hi asm磁盘组创建时间mntstmp.hi asm磁盘组mount时间blksize 磁盘头块大小 4096ausize 条带化大小 4Mdsksize 磁盘大小 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: TESTDGCurrent alias directory path: rac-cluster/OCRFILECurrent alias directory path: rac-clusterCurrent alias directory path: rac-cluster/ASMPARAMETERFILE
3.3 模拟磁盘头信息丢失 [grid@rac1 ~]$ dd if=/dev/zero f=/dev/raw/raw1 bs=4096 count=11+0 records in1+0 records out4096 bytes (4.1 kB) copied, 0.016114 seconds, 254 kB/s[grid@rac1 ~]$ kfed read /dev/raw/raw1kfbh.endian: 0 ; 0x000: 0x00kfbh.hard: 0 ; 0x001: 0x00kfbh.type: 0 ; 0x002: KFBTYP_INVALIDkfbh.datfmt: 0 ; 0x003: 0x00kfbh.block.blk: 0 ; 0x004: T=0 NUMB=0x0kfbh.block.obj: 0 ; 0x008: TYPE=0x0 NUMB=0x0kfbh.check: 0 ; 0x00c: 0x00000000kfbh.fcn.base: 0 ; 0x010: 0x00000000kfbh.fcn.wrap: 0 ; 0x014: 0x00000000kfbh.spare1: 0 ; 0x018: 0x00000000kfbh.spare2: 0 ; 0x01c: 0x00000000ERROR!!!, failed to get the oracore error message
这时磁盘组testdg下/dev/raw/raw1磁盘头信息丢失,不能正常读取。SQL> alter diskgroup testdg dismount;Diskgroup altered.SQL> alter diskgroup testdg mount;alter diskgroup testdg mount*ERROR at line 1:ORA-15032: not all alterations performedORA-15017: diskgroup "TESTDG" cannot be mountedORA-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: TESTDGASMCMD-09352: CREATE DISKGROUP failedORA-15018: diskgroup cannot be createdORA-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: TESTDGDiskgroup 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: Release 11.2.0.1.0 Production on Thu Jul 8 16:43:53 2010Copyright (c) 1982, 2009, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Real Application Clusters and Automatic Storage Management optionsSQL> select name,state from v$asm_diskgroup;NAME STATE------------------------------ -----------CRS MOUNTEDTESTDG MOUNTED可以看到磁盘组testdg恢复成功。
3.5 总结 Oracle 11g asm 磁盘组内元数据备份与恢复非常简单,只需要我们安装完成后做好备份工作即可。