您的位置:首页 > 其它

ASM磁盘分区或者设备文件删除后恢复的方法

2009-10-13 22:47 796 查看
转自:http://www.itpub.net/thread-1021898-1-1.html

$ export ORACLE_SID=+ASM

$ sqlplus / as sysdba

查看磁盘组的状态和磁盘组的类型,这里的磁盘组是外部

SQL> select name,type,state from v$asm_diskgroup;

NAME TYPE STATE

-------------------- ------------ ----------------------

DISK_GROUP1 EXTERN MOUNTED

DISK_GROUP2 EXTERN MOUNTED

FLASHBACK_DISKGROUP EXTERN MOUNTED

查看磁盘组对应的磁盘,为什么会ORCL:VOL这些磁盘没有分配,实际这些磁盘就是

ASM磁盘,由于他们有标识设备文件,所以没有对应磁盘组,如果它们没有标识设备,会对应

磁盘,我们看一下:

SQL> select group_number,disk_number,path from v$asm_disk;

GROUP_NUMBER DISK_NUMBER PATH

------------ ----------- --------------------

0 3 ORCL:VOL1

0 5 ORCL:VOL3

0 6 ORCL:VOL4

2 0 /dev/raw/raw3

3 0 /dev/raw/raw2

1 1 /dev/raw/raw4

1 0 ORCL:VOL2

7 rows selected.

$ /etc/init.d/oracleasm listdisks

VOL1

VOL2

VOL3

VOL4

发现其他的ASMDISK的设备文件都直接对应了磁盘组,但是VOL2却直接对应磁盘组.

看到VOL2没有定义标识,我们来定义一下.

$ /etc/init.d/oracleasm querydisk VOL1

Disk "VOL1" is a valid ASM disk on device [8, 17]

$ /etc/init.d/oracleasm querydisk VOL2

ASM disk "VOL2" defines an unmarked device

$ /etc/init.d/oracleasm querydisk VOL3

Disk "VOL3" is a valid ASM disk on device [8, 49]

$ /etc/init.d/oracleasm querydisk VOL4

Disk "VOL4" is a valid ASM disk on device [8, 81]

$ su - root

Password:

-bash: [: missing `]'

[root@dg1 ~]# vi /etc/sysconfig/rawdevices

加入 /dev/raw/raw1 /dev/sdc1这条

[root@dg1 ~]# /sbin/service rawdevices restart

Assigning devices:

/dev/raw/raw3 --> /dev/sdb1

/dev/raw/raw3: bound to major 8, minor 17

/dev/raw/raw2 --> /dev/sdd1

/dev/raw/raw2: bound to major 8, minor 49

/dev/raw/raw4 --> /dev/sdf1

/dev/raw/raw4: bound to major 8, minor 81

/dev/raw/raw1 --> /dev/sdc1

/dev/raw/raw1: bound to major 8, minor 33

done

[root@dg1 ~]# cd /dev/raw

[root@dg1 raw]# ls

raw1 raw2 raw3 raw4

RAW1文件已经生成,在到V$ASM_DISK表看一下

1* select group_number,name,path,state from v$asm_disk

SQL> /

GROUP_NUMBER NAME PATH STATE

------------ ------------------------- -------------------- ----------------

0 ORCL:VOL1 NORMAL

0 ORCL:VOL2 NORMAL

0 ORCL:VOL3 NORMAL

0 ORCL:VOL4 NORMAL

2 DISK_GROUP2_0000 /dev/raw/raw3 NORMAL

3 FLASHBACK_DISKGROUP_0000 /dev/raw/raw2 NORMAL

1 DISK_GROUP1_0001 /dev/raw/raw4 NORMAL

1 DISK_GROUP1_0000 /dev/raw/raw1 NORMAL

8 rows selected.

发现VOL2已经不对应磁盘组了.

模拟删除ASMDISK以及磁盘分区的过程:

首先删除了ASMDISK,并没有实际删除磁盘分区

$ su - root

Password:

-bash: [: missing `]'

[root@dg1 ~]# /etc/init.d/oracleasm deletedisk VOL2

Removing ASM disk "VOL2": [ OK ]

SQL> startup nomount

ASM instance started

Total System Global Area 83886080 bytes

Fixed Size 1217836 bytes

Variable Size 57502420 bytes

ASM Cache 25165824 bytes

SQL> alter diskgroup DISK_GROUP1 mount;

alter diskgroup DISK_GROUP1 mount

*

ERROR at line 1:

ORA-15032: not all alterations performed

ORA-15063: ASM discovered an insufficient number of disks for diskgroup

"DISK_GROUP1"

再重新创建ASMDISK:

$ su - root

Password:

-bash: [: missing `]'

[root@dg1 ~]# /etc/init.d/oracleasm createdisk VOL2 /dev/sdc1

Marking disk "/dev/sdc1" as an ASM disk: [ OK ]

[root@dg1 ~]# /etc/init.d/oracleasm listdisks

VOL1

VOL2

VOL3

VOL4

发现磁盘组已经不能正常mount:

SQL> alter diskgroup DISK_GROUP1 mount;

alter diskgroup DISK_GROUP1 mount

*

ERROR at line 1:

ORA-15032: not all alterations performed

ORA-15063: ASM discovered an insufficient number of disks for diskgroup

"DISK_GROUP1"

用以前ASM磁盘头的备份信息进行恢复:

SQL> !

$ dd if=/u01/asmdisk_header/raw1_header bs=4096 count=1 of=/dev/raw/raw1

读入了 1+0 个块

输出了 1+0 个块

$ exit

SQL> l

1* alter diskgroup DISK_GROUP1 mount

SQL> /

Diskgroup altered.

现在删除磁盘分区,再测试:

[root@dg1 ~]# fdisk /dev/sdc

Command (m for help): m

Command action

a toggle a bootable flag

b edit bsd disklabel

c toggle the dos compatibility flag

d delete a partition

l list known partition types

m print this menu

n add a new partition

o create a new empty DOS partition table

p print the partition table

q quit without saving changes

s create a new empty Sun disklabel

t change a partition's system id

u change display/entry units

v verify the partition table

w write table to disk and exit

x extra functionality (experts only)

Command (m for help): p

Disk /dev/sdc: 1610 MB, 1610612736 bytes

255 heads, 63 sectors/track, 195 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sdc1 1 195 1566306 83 Linux

磁盘只划了1个分区

Command (m for help): d

Selected partition 1

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

Command (m for help): p

Disk /dev/sdc: 1610 MB, 1610612736 bytes

255 heads, 63 sectors/track, 195 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sdc1 1 195 1566306 83 Linux

实际删除分区

Command (m for help): d

Selected partition 1

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

Command (m for help): p

Disk /dev/sdc: 1610 MB, 1610612736 bytes

255 heads, 63 sectors/track, 195 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

分区已经被删除.

SQL> alter diskgroup DISK_GROUP1 mount;

alter diskgroup DISK_GROUP1 mount

*

ERROR at line 1:

ORA-15032: not all alterations performed

ORA-15063: ASM discovered an insufficient number of disks for diskgroup

"DISK_GROUP1"

SQL> !

$ dd if=/u01/asmdisk_header/raw1_header bs=4096 count=1 of=/dev/raw/raw1

dd: 打开 ‘/dev/raw/raw1’: 没有那个设备或地址

$ cd /dev/raw

$ ls

raw1 raw2 raw3 raw4

$ ls -l

总用量 0

crw-rw---- 1 oracle dba 162, 1 7月 15 11:24 raw1

crw-rw---- 1 oracle dba 162, 2 7月 15 11:24 raw2

crw-rw---- 1 oracle dba 162, 3 7月 15 11:24 raw3

crw-rw---- 1 oracle dba 162, 4 7月 15 11:24 raw4

其实设备文件还在,但是已经不能对应到磁盘分区.因为分区已经删除,这个磁盘组肯定不能mount

尝试重建分区:

[root@dg1 ~]# fdisk /dev/sdc

Command (m for help): m

Command action

a toggle a bootable flag

b edit bsd disklabel

c toggle the dos compatibility flag

d delete a partition

l list known partition types

m print this menu

n add a new partition

o create a new empty DOS partition table

p print the partition table

q quit without saving changes

s create a new empty Sun disklabel

t change a partition's system id

u change display/entry units

v verify the partition table

w write table to disk and exit

x extra functionality (experts only)

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-195, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-195, default 195):

Using default value 195

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

用备份还原磁盘头信息:

$ dd if=/u01/asmdisk_header/raw1_header bs=4096 count=1 of=/dev/raw/raw1

读入了 1+0 个块

输出了 1+0 个块

$ env |grep ORA

ORACLE_BASE=/u01/app/oracle

ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1

ORACLE_SID=+ASM

$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jul 15 13:40:41 2008

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

Connected to an idle instance.

SQL> startup nomount

ASM instance started

Total System Global Area 83886080 bytes

Fixed Size 1217836 bytes

Variable Size 57502420 bytes

ASM Cache 25165824 bytes

SQL>

SQL> alter diskgroup DISK_GROUP1 mount;

Diskgroup altered.

$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jul 15 13:41:28 2008

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

Connected to an idle instance.

SQL> startup mount

ORACLE instance started.

Total System Global Area 197132288 bytes

Fixed Size 1218484 bytes

Variable Size 83888204 bytes

Database Buffers 109051904 bytes

Redo Buffers 2973696 bytes

ORA-00205: error in identifying control file, check alert log for more info

ALTER DATABASE MOUNT

Tue Jul 15 13:41:35 2008

Starting background process ASMB

ASMB started with pid=16, OS id=3352

Starting background process RBAL

RBAL started with pid=17, OS id=3356

Tue Jul 15 13:41:40 2008

SUCCESS: diskgroup DISK_GROUP1 was mounted

Tue Jul 15 13:41:40 2008

ORA-00202: ????: ''+FLASHBACK_DISKGROUP/devdb/controlfile/current.256.657732291''

ORA-17503: ksfdopn: 2 ?????? +FLASHBACK_DISKGROUP/devdb/controlfile/current.256.657732291

ORA-15001: ??? "FLASHBACK_DISKGROUP" ????????

ORA-15001: diskgroup "FLASHBACK_DISKGROUP" does not exist or is not mounted

SUCCESS: diskgroup DISK_GROUP1 was dismounted

Tue Jul 15 13:41:40 2008

ORA-205 signalled during: ALTER DATABASE MOUNT...

因为其他磁盘组没有装载,导致controlfile不能全部找到,回到ASM instance mount所有磁盘组

$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jul 15 13:43:21 2008

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

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

SQL> alter diskgroup DISK_GROUP1 dismount;

Diskgroup altered.

SQL> alter diskgroup all mount;

Diskgroup altered.

QL> startup mount

ORACLE instance started.

Total System Global Area 197132288 bytes

Fixed Size 1218484 bytes

Variable Size 83888204 bytes

Database Buffers 109051904 bytes

Redo Buffers 2973696 bytes

Database mounted.

SQL> alter database open;

Database altered.

SQL> select file_name from dba_data_files;

FILE_NAME

----------------------------------------------------------------------------------------------------

+DISK_GROUP1/devdb/datafile/users.259.657732133

+DISK_GROUP1/devdb/datafile/sysaux.257.657732131

+DISK_GROUP1/devdb/datafile/undotbs1.258.657732131

+DISK_GROUP1/devdb/datafile/system.256.657732131

+DISK_GROUP1/devdb/datafile/example.265.657732351

+DISK_GROUP2/devdb/datafile/users.256.659787481

6 rows selected.

发现数据库可以正常打开,数据没有丢失.

总结: 磁盘划分区以后,在Linux下通过asm lib用oracleasm命令创建ASM磁盘,然后在/etc/sysconfig/rawdevices创建设备文件

disk partition (fdisk -l查看)->asm disk (/etc/init.d/oracleasm listdisks 查看)->more /etc/sysconfig/rawdevices or ls -l

/dev/raw/raw*查看

测试看出,删除raw 设备文件,磁盘组仍然可以直接读取asm disk,但是如果磁盘分区或者asm disk被删除,需要利用备份进行恢复

请兄弟门指正测试中不足,错误的地方

$ kfed read /dev/raw/raw1

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: 452538402 ; 0x00c: 0x1af93022

kfbh.fcn.base: 4532 ; 0x010: 0x000011b4

kfbh.fcn.wrap: 0 ; 0x014: 0x00000000

kfbh.spare1: 0 ; 0x018: 0x00000000

kfbh.spare2: 0 ; 0x01c: 0x00000000

kfdhdb.driver.provstr: ORCLDISKVOL2 ; 0x000: length=12

kfdhdb.driver.reserved[0]: 843861846 ; 0x008: 0x324c4f56

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: 168820736 ; 0x020: 0x0a100000

kfdhdb.dsknum: 0 ; 0x024: 0x0000

kfdhdb.grptyp: 1 ; 0x026: KFDGTP_EXTERNAL

kfdhdb.hdrsts: 3 ; 0x027: KFDHDR_MEMBER

kfdhdb.dskname: DISK_GROUP1_0000 ; 0x028: length=16

kfdhdb.grpname: DISK_GROUP1 ; 0x048: length=11

kfdhdb.fgname: DISK_GROUP1_0000 ; 0x068: length=16

kfdhdb.capname: ; 0x088: length=0

kfdhdb.crestmp.hi: 32905806 ; 0x0a8: HOUR=0xe DAYS=0x12 MNTH=0x6 YEAR=0x7d8

kfdhdb.crestmp.lo: 2565405696 ; 0x0ac: USEC=0x0 MSEC=0x23f SECS=0xe MINS=0x26

kfdhdb.mntstmp.hi: 32906736 ; 0x0b0: HOUR=0x10 DAYS=0xf MNTH=0x7 YEAR=0x7d8

kfdhdb.mntstmp.lo: 2152955904 ; 0x0b4: USEC=0x0 MSEC=0xe0 SECS=0x5 MINS=0x20

kfdhdb.secsize: 512 ; 0x0b8: 0x0200

kfdhdb.blksize: 4096 ; 0x0ba: 0x1000

kfdhdb.ausize: 1048576 ; 0x0bc: 0x00100000

kfdhdb.mfact: 113792 ; 0x0c0: 0x0001bc80

kfdhdb.dsksize: 1529 ; 0x0c4: 0x000005f9

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]: 65535 ; 0x0da: 0xffff

kfdhdb.redomirrors[2]: 65535 ; 0x0dc: 0xffff

kfdhdb.redomirrors[3]: 65535 ; 0x0de: 0xffff

kfdhdb.dbcompat: 168820736 ; 0x0e0: 0x0a100000

kfdhdb.grpstmp.hi: 32905806 ; 0x0e4: HOUR=0xe DAYS=0x12 MNTH=0x6 YEAR=0x7d8

kfdhdb.grpstmp.lo: 2565314560 ; 0x0e8: USEC=0x0 MSEC=0x1e6 SECS=0xe MINS=0x26

kfdhdb.ub4spare[0]: 0 ; 0x0ec: 0x00000000

kfdhdb.ub4spare[1]: 0 ; 0x0f0: 0x00000000

kfdhdb.ub4spare[2]: 0 ; 0x0f4: 0x00000000

kfdhdb.ub4spare[3]: 0 ; 0x0f8: 0x00000000

kfdhdb.ub4spare[4]: 0 ; 0x0fc: 0x00000000

kfdhdb.ub4spare[5]: 0 ; 0x100: 0x00000000

kfdhdb.ub4spare[6]: 0 ; 0x104: 0x00000000

kfdhdb.ub4spare[7]: 0 ; 0x108: 0x00000000

kfdhdb.ub4spare[8]: 0 ; 0x10c: 0x00000000

kfdhdb.ub4spare[9]: 0 ; 0x110: 0x00000000

kfdhdb.ub4spare[10]: 0 ; 0x114: 0x00000000

kfdhdb.ub4spare[11]: 0 ; 0x118: 0x00000000

kfdhdb.ub4spare[12]: 0 ; 0x11c: 0x00000000

kfdhdb.ub4spare[13]: 0 ; 0x120: 0x00000000

kfdhdb.ub4spare[14]: 0 ; 0x124: 0x00000000

kfdhdb.ub4spare[15]: 0 ; 0x128: 0x00000000

kfdhdb.ub4spare[16]: 0 ; 0x12c: 0x00000000

kfdhdb.ub4spare[17]: 0 ; 0x130: 0x00000000

kfdhdb.ub4spare[18]: 0 ; 0x134: 0x00000000

kfdhdb.ub4spare[19]: 0 ; 0x138: 0x00000000

kfdhdb.ub4spare[20]: 0 ; 0x13c: 0x00000000

kfdhdb.ub4spare[21]: 0 ; 0x140: 0x00000000

kfdhdb.ub4spare[22]: 0 ; 0x144: 0x00000000

kfdhdb.ub4spare[23]: 0 ; 0x148: 0x00000000

kfdhdb.ub4spare[24]: 0 ; 0x14c: 0x00000000

kfdhdb.ub4spare[25]: 0 ; 0x150: 0x00000000

kfdhdb.ub4spare[26]: 0 ; 0x154: 0x00000000

kfdhdb.ub4spare[27]: 0 ; 0x158: 0x00000000

kfdhdb.ub4spare[28]: 0 ; 0x15c: 0x00000000

kfdhdb.ub4spare[29]: 0 ; 0x160: 0x00000000

kfdhdb.ub4spare[30]: 0 ; 0x164: 0x00000000

kfdhdb.ub4spare[31]: 0 ; 0x168: 0x00000000

kfdhdb.ub4spare[32]: 0 ; 0x16c: 0x00000000

kfdhdb.ub4spare[33]: 0 ; 0x170: 0x00000000

kfdhdb.ub4spare[34]: 0 ; 0x174: 0x00000000

kfdhdb.ub4spare[35]: 0 ; 0x178: 0x00000000

kfdhdb.ub4spare[36]: 0 ; 0x17c: 0x00000000

kfdhdb.ub4spare[37]: 0 ; 0x180: 0x00000000

kfdhdb.ub4spare[38]: 0 ; 0x184: 0x00000000

kfdhdb.ub4spare[39]: 0 ; 0x188: 0x00000000

kfdhdb.ub4spare[40]: 0 ; 0x18c: 0x00000000

kfdhdb.ub4spare[41]: 0 ; 0x190: 0x00000000

kfdhdb.ub4spare[42]: 0 ; 0x194: 0x00000000

kfdhdb.ub4spare[43]: 0 ; 0x198: 0x00000000

kfdhdb.ub4spare[44]: 0 ; 0x19c: 0x00000000

kfdhdb.ub4spare[45]: 0 ; 0x1a0: 0x00000000

kfdhdb.ub4spare[46]: 0 ; 0x1a4: 0x00000000

kfdhdb.ub4spare[47]: 0 ; 0x1a8: 0x00000000

kfdhdb.ub4spare[48]: 0 ; 0x1ac: 0x00000000

kfdhdb.ub4spare[49]: 0 ; 0x1b0: 0x00000000

kfdhdb.ub4spare[50]: 0 ; 0x1b4: 0x00000000

kfdhdb.ub4spare[51]: 0 ; 0x1b8: 0x00000000

kfdhdb.ub4spare[52]: 0 ; 0x1bc: 0x00000000

kfdhdb.ub4spare[53]: 0 ; 0x1c0: 0x00000000

kfdhdb.ub4spare[54]: 0 ; 0x1c4: 0x00000000

kfdhdb.ub4spare[55]: 0 ; 0x1c8: 0x00000000

kfdhdb.ub4spare[56]: 0 ; 0x1cc: 0x00000000

kfdhdb.ub4spare[57]: 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

从kfed看,这个磁盘的扇区是512,OS块大小是4096,用DD拷贝第一个块就包含磁盘头的信息

是在ASM的第一个块上,ASM块大小为4096,由参数_asm_blksize来控制
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: