#!/bin/ksh # # 09/09/2003, Thomas Sluyter, UNIX Support # HP-migrate - a script designed to migrate any and all volumes on a server, with the # exception of the rootdg volumes, onto the HP central storage. This will also move # any data on EMC storage over to the HP boxen. # # PLEASE NOTE: this script needs to be run from the root account # # Initial clean up, in case this script ran earlier with a failure rm /tmp/migrate.* >/dev/null 2>&1 # Build list of controlers # The HPCONTS var will contain the primary controller number for EMC, which incidentally # is the _same_ for HP. LOCCONTS=`vxdmpadm listctlr all | grep -v "=" | grep -v "emc" | grep -v "CTLR-NAME" | awk '{print $1}' | sed -e 's/c//' | tr -d '\n'` HPCONT=`vxdmpadm listctlr all | grep -v "=" | grep -i xp1024 | grep -v "CTLR-NAME" | awk '{print $1}' | head -1` # Build list of HP primary target WWN_PREAMBLE="" if [ "$WWN_PREAMBLE" != "" ]; then HPTARGET=`grep $WWN_PREAMBLE /kernel/drv/lpfc.conf | grep lpfc0 | sed -e 's/^.*t/t/;s/".*//' | head -1` else HPTARGET="" fi # Build list of disk groups vxprint | grep "Disk group" |awk '{print $3}' | grep -v rootdg > /tmp/migrate.dg MIRROR() { # Find out if there are any RAID-5 volumes around. We don't want those on HP since that'll bork performance # to no end. So we'll need to convert those to concat first. # This'll probably only apply to the TTSSUNs 38 and 57. "But we're not going to migrate them, thomas!", you'll say... # I'm well aware of that, but this is just to make the script more optimal, so we can use the same script at a later # time for other servers as well (which leads to a win++). for DG in `cat /tmp/migrate.dg` do vxprint -g $DG | grep raid5 | awk '{print $2}' > /tmp/migrate.raid if [[ `wc -l /tmp/migrate.raid | awk '{print $1}'` -gt 0 ]] then for RAID in `cat /tmp/migrate.raid` do vxassist -g $DG relayout $RAID layout=nomirror done rm /tmp/migrate.raid fi done # Create a mirror for each volume in the relevant disk groups for DG in `cat /tmp/migrate.dg` do vxprint -g $DG | grep "v " | awk '{print $2}' > /tmp/migrate.vols for VOL in `cat /tmp/migrate.vols` do #Original line from EMC migration script. #vxassist -g $DG mirror $VOL ctlr:$HPCONTS vxassist -g $DG mirror $VOL target:$HPCONT$HPTARGET done rm /tmp/migrate.vols done } # End of MIRROR subroutine UNMIRROR() { # Remove the mirrors created on HP hard disks for DG in `cat /tmp/migrate.dg` do vxdisk list | grep $DG | grep $HPCONT$HPTARGET | awk '{print $3}' >> /tmp/migrate.disks for DISK in `cat /tmp/migrate.disks` do vxprint -g $DG | grep -v "^dm" | grep $DISK | awk '{print $3}' >> /tmp/migrate.plex done for PLEX in `cat /tmp/migrate.plex` do VOL=`echo $PLEX | sed -e 's/-.*//'` vxplex -g $DG -v $VOL -o rm dis $PLEX done rm /tmp/migrate.disks /tmp/migrate.plex done } # End of UNMIRROR subroutine DETACH() { # Detach the original data volumes on EMC / local storage for testing for DG in `cat /tmp/migrate.dg` do vxdisk list | grep $DG | grep $HPCONT$HPTARGET | awk '{print $3}' >> /tmp/migrate.disks for DISK in `cat /tmp/migrate.disks` do vxprint -g $DG | grep -v "^dm" | grep -v LOG| grep $DISK | awk '{print $3}' >> /tmp/migrate.plex done for PLEX in `cat /tmp/migrate.plex` do VOL=`echo $PLEX | sed -e 's/-.*//'` vxplex -g $DG -v $VOL det $PLEX done rm /tmp/migrate.disks /tmp/migrate.plex done } # End of DETACH subroutine ATTACH() { # Reattach the original data volumes to the mirror set, after testing. for DG in `cat /tmp/migrate.dg` do vxdisk list | grep $DG | grep $HPCONT$HPTARGET | awk '{print $3}' >> /tmp/migrate.disks for DISK in `cat /tmp/migrate.disks` do vxprint -g $DG | grep -v "^dm" | grep $DISK | awk '{print $3}' >> /tmp/migrate.plex done for PLEX in `cat /tmp/migrate.plex` do VOL=`echo $PLEX | sed -e 's/-.*//'` vxplex -g $DG att $VOL $PLEX done rm /tmp/migrate.disks /tmp/migrate.plex done } # End of ATTACH subroutine MURDER() { echo ""; echo "WARNING!" echo "Proceeding will destroy the original data on the local/external storage and will leave you with" echo "the data on the HP storage _only_. Only perform this command once the HP storage has been succes-" echo "fully tested and approved." echo ""; echo "Proceed? (yes/no): "; read ANSWER case $ANSWER in yes) echo "Well, here we go then. *takes out the 12 gauge*";; *) echo "Alright, we'll quit (or you just entered -y- instead of -yes-"; exit 1;; esac # Making sure that all of the originals are attached so we can delete them ATTACH >/dev/null 2>&1 for DG in `cat /tmp/migrate.dg` do vxdisk list | grep $DG | grep -v $HPCONT$HPTARGET | awk '{print $3}' >> /tmp/migrate.disks for DISK in `cat /tmp/migrate.disks` do vxprint -g $DG | grep -v "^dm" | grep $DISK | awk '{print $3}' >> /tmp/migrate.plex done for PLEX in `cat /tmp/migrate.plex` do VOL=`echo $PLEX | sed -e 's/-.*//'` vxplex -g $DG -v $VOL -o rm dis $PLEX echo "*kaclick* *BOOM!* That was the original data for $VOL!" done rm /tmp/migrate.disks /tmp/migrate.plex done } # End of MURDER subroutine PRETEST=`vxdmpadm listctlr all|grep -i emc|awk '{print $1}'|head -1` PRETEST2=`vxdmpadm listctlr all | grep -i $PRETEST | wc -l` if [ PRETEST2 -lt 2 ]; then echo "BAILING OUT! This server is NOT connected to the HP XP1024!" exit 1 fi if [ "$WWN_PREAMBLE" == "" ]; then echo echo "HP XP1024 WWN not set in script. Please verify WWPN in" echo "/kernel/drv/lpfc.conf and set first 14 characters in" echo "\$WWN_PREAMBLE then run script again." exit 1 else echo echo "Are you absolutely sure that the WWPN for the HP XP1024" echo "which is configured in the migration script is correct?" echo "If it is not then the script may corrupt your data!!!" echo "Yes / No:\c" read Y case $Y in y|Y|yes) echo "Alright. I'm continuing..."; echo;; n|N|no) echo "Exiting so you can make sure."; echo "Modify \$WWN_PREAMBLE and enter first 14 chars of WWPN."; echo; exit 1;; *) echo "Enter y or n."; echo "Breaking"; echo; exit 1;; esac fi PARAM=$1 case $PARAM in mirror) MIRROR;; unmirror) UNMIRROR;; detach) DETACH;; attach) ATTACH;; murder) MURDER;; *) echo ""; echo "Usage: HP-migrate [mirror|unmirror|detach|attach|murder]";echo "" echo "mirror: Create mirrors of every volume (outside rootdg) on HP storage." echo "unmirror: Remove the HP mirrors from the mirror sets created with this command." echo "detach: Detach the original data from the mirror sets created using the mirror option." echo "attach: Re-attach the original data from the mirror sets created using the mirror option." echo "murder: Kill the original data on local/external storage." echo "" exit 1 ;; esac rm /tmp/migrate.* > /dev/null 2>&1