|
目的:对于多路径的SAN DISK(multipath)自动按照WWN创建md设备(使用mdadm),另外两个相同的存储(SUN6920)之间做同步复制,最终目的是要达到相同内容的LUN创建成相同的md设备。
配置文件/etc/wwn_md.conf:
[HTML]#
#
#6920_222 6920_223 partid mddev mountpoint
3600015d00004d300000000000000073d 5600015d07004d30000000000000006ae 1 md1
3600015d00004d3000000000000000743 6600015d07004d30000000000000002fc 1 md2
[/HTML]
脚本:
[HTML]#!/bin/bash
#please configure the file /etc/wwn_md.conf!
#
USAGE="Usage: $0 '[-f] [-s] [6920_222,6920_223]'"
FORCE=false
#get the param from shell
while getopts fs: OPTION ; do
case "$OPTION" in
s) Storage="$OPTARG" ;;
f) FORCE=true ;;
\?) echo "$USAGE" ;
exit 1
;;
esac
done
#check the -s param is in 6920_222,6920_223
echo $Storage
case "$Storage" in
6920_222) post=1 ;
#get the disk's wwn from the configure file---/etc/wwn_md.conf
wwn=`awk '/^[^#]/{print $1}' /etc/wwn_md.conf`;;
6920_223) post=2 ;
wwn=`awk '/^[^#]/{print $2}' /etc/wwn_md.conf`;;
*) echo "Sorry $Storage is not a valid Storage!";
exit 1
;;
esac
echo Storage is $Storage
echo In Force Mode FORCE
#wwn=`awk '/^[^#]/{print $port}' /etc/wwn_md.conf`
#clear the temp file
for i in $wwn
do
echo >/tmp/$i
done
for i in $wwn
do
#get the partition number from the configure file
part=`awk '/'$i'/{print $3}' /etc/wwn_md.conf`
#get the md device name from the configure file
md=`awk '/'$i'/{print $4}' /etc/wwn_md.conf`
echo $md
#get all the disk device name
dev=`ls /dev/sd[a-z]|awk -F/ '{print $3}'`;
for v_dev in $dev
do
#get each disk's scsi_id
sd=`scsi_id -g -s /block/$v_dev`
if [ $sd = $i ]
then
echo $i $v_dev$part
#get disks which have the same wwn/scsi_id,and save them name to tempfile /tmp/$i
echo "/dev/"$v_dev$part >>/tmp/$i
fi
done
#combination the disk name
disk=`cat /tmp/$i | sed '{N;s/\n/ /}'`
#use mdadm to create the md device
if [ $FORCE = true ]
then
echo "force create md device is set true!"
mdadm -C /dev/$md -l multipath -n2 $disk <<EOF
y
EOF
else
echo "force create md device is set false!"
mdadm -C /dev/$md -l multipath -n2 $disk
fi
#mdadm -C /dev/$md -l multipath -n2 $disk
done[/HTML] |
|