昨天研究了一下HP_UX 11.31操作系统里用Shell脚本实现vg00根盘的自动镜像,今天看到另一个命令lvsync可以让vg00里所有的LV逻辑卷同时进行镜像,Scripts如下:

##############################################################
# create vg00 mirror shell
##############################################################

# /usr/bin/sh
disk=/dev/disk/$1
rdisk=/dev/rdisk/$1
LOG=/tmp/vg00_mirror.log

 

echo "\n=====================Start `date \"+%Y-%m-%d %H:%M:%S\"`====================="
#1. Create a temporary file /tmp/partitionfile
echo "3" > /tmp/partitionfile
echo "EFI 500MB" >>/tmp/partitionfile
echo "HPUX 100%" >>/tmp/partitionfile
echo "HPSP 400MB" >>/tmp/partitionfile

#2.Use the file created in Step 1 to partition the mirror disk with idisk:
echo yes|idisk -wf /tmp/partitionfile $rdisk >>$LOG 2>&1

#3.insf newly-created partitions
LUN=`ioscan -m lun $rdisk|grep esdisk|awk '{print $3}'` >>$LOG 2>&1
insf -eH $LUN >>$LOG 2>&1
idisk -p $rdisk >>$LOG 2>&1

#4.Run the pvcreate command on the character device file for the HP-UX (second) partition
#pvcreate -B $rdisk'_p2'
pvcreate -f -B $rdisk'_p2'

#5.Extend vg to _p2 of the mirror disk, using the block device file of _p2
vgextend vg00 $disk'_p2'

#6.Run mkboot to complete the setup of the disk as a boot disk
mkboot -e -l $disk

#7.Create a temporary AUTO file and use the efi_cp command to copy it to the mirror
echo "boot vmunix -lq">/tmp/AUTO
efi_cp -d $rdisk'_p1' /tmp/AUTO /EFI/HPUX/AUTO >>$LOG 2>&1

#8.Run lvextend to mirror each logical volume:
vgdisplay -v vg00
vgdisplay -v vg00|grep "LV Name"|awk '{print $3}'|while read lvname
do
lvextend -s -m 1 $lvname >>$LOG 2>&1
done

lvsync -T `vgdisplay -v vg00|grep LV Name awk '{ORS= }{ print $3 }END{print n} '`
###vgdisplay -v vg00grep LV Name awk '{ORS= }{ print $3 }END{print n} 'sed 's^lvsync -T '`

#9.Run the lvlnboot commands to reestablish LVM
lvlnboot -b /dev/vg00/lvol1 /dev/vg00 >>$LOG 2>&1
lvlnboot -r /dev/vg00/lvol3 /dev/vg00 >>$LOG 2>&1
lvlnboot -s /dev/vg00/lvol2 /dev/vg00 >>$LOG 2>&1
lvlnboot -d /dev/vg00/lvol2 /dev/vg00 >>$LOG 2>&1
lvlnboot -Rv >>$LOG 2>&1

#10.Add the block device file of _p2 of the mirror to the file /stand/bootconf
echo "l $disk"_p2"">> /stand/bootconf

#11.Set the alternate boot path to the mirror_disk
setboot -a $rdisk

banner " end"
echo "\n=====================End `date \"+%Y-%m-%d %H:%M:%S\"`====================="

vg00原有根盘是/dev/disk/disk1,现在需要镜像到/dev/disk/disk2上,使用以下命令:

#./vg00_mirror.sh disk2

posted on 2016-08-28 12:37  zlg88  阅读(639)  评论(0编辑  收藏  举报