#!/bin/ksh # # 12/06/2003, Thomas Sluyter, UNIX Support # EMC-migrate - a script designed to migrate any and all volumes on a server, with the exception of the rootdg, # onto the EMC central storage. # # 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 LOCCONTS=`vxdmpadm listctlr all | grep -v "=" | grep -v "emc" | grep -v "CTLR-NAME" | awk '{print $1}' | sed -e 's/c//' | tr -d '\n'` # Following var changed for MIRROR subroutine. q.v. #EMCCONTS=`vxdmpadm listctlr all | grep -v "=" | grep "emc" | grep -v "CTLR-NAME" | awk '{print $1}' | sed -e 's/c//' | tr -d '\n'` EMCCONTS=`vxdmpadm listctlr all | grep -v "=" | grep "emc" | grep -v "CTLR-NAME" | awk '{print $1}' | tr -s '\n' ' ' | awk '{print $1}'` #echo "The non-EMC disk controllers are: " $LOCCONTS #echo "The EMC disk controllers are: " $EMCCONTS # 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 EMC 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 # Change following line. Original line didn't work since you need to have seperate # !ctlr statements for each controler. Instead I'd just use one ctlr statement with # the one (out of two) EMC controller from $EMCCONTS #vxassist -g $DG mirror $VOL !ctlr:$LOCCONTS vxassist -g $DG mirror $VOL ctlr:$EMCCONTS done rm /tmp/migrate.vols done } # End of MIRROR subroutine UNMIRROR() { # Remove the mirrors created on EMC hard disks for DG in `cat /tmp/migrate.dg` do for CTLR in `vxdmpadm listctlr all | grep -v "=" | grep "emc" | grep -v "CTLR-NAME" | awk '{print $1}'` do vxdisk list | grep $DG | grep "^$CTLR" | awk '{print $3}' >> /tmp/migrate.disks done 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() { for DG in `cat /tmp/migrate.dg` do for CTLR in `vxdmpadm listctlr all | grep -v "=" | grep -v "emc" | grep -v "CTLR-NAME" | awk '{print $1}'` do vxdisk list | grep $DG | grep "^$CTLR" | awk '{print $3}' >> /tmp/migrate.disks done 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() { for DG in `cat /tmp/migrate.dg` do for CTLR in `vxdmpadm listctlr all | grep -v "=" | grep -v "emc" | grep -v "CTLR-NAME" | awk '{print $1}'` do vxdisk list | grep $DG | grep "^$CTLR" | awk '{print $3}' >> /tmp/migrate.disks done 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 EMC storage _only_. Only perform this command once the EMC 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 for CTLR in `vxdmpadm listctlr all | grep -v "=" | grep -v "emc" | grep -v "CTLR-NAME" | awk '{print $1}'` do vxdisk list | grep $DG | grep "^$CTLR" | awk '{print $3}' >> /tmp/migrate.disks done 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 -gt 1 ]; then echo "BAILING OUT! This server is also connected to the HP XP1024!" exit 1 fi PARAM=$1 case $PARAM in mirror) MIRROR;; unmirror) UNMIRROR;; detach) DETACH;; attach) ATTACH;; murder) MURDER;; *) echo ""; echo "Usage: EMC-migrate [mirror|unmirror|detach|attach|murder]";echo "" echo "mirror: Create mirrors of every volume (outside rootdg) on EMC storage." echo "unmirror: Remove the EMC 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