#!/bin/bash
svc_cluster_ip=10.0.0.10
svc_priv_dsa=~/.ssh/id_dsa
if [ -z $2 ] ; then
echo
echo " ${0##*/} [ original_mdiskgrp | target_mdiskgrp | (threads) ]"
echo
echo " mdiskgrp_old - The MDisk Group which currently contains"
echo " the VDisks."
echo " mdiskgrp_new - The MDisk Group you wish to migrate the"
echo " VDisks migrated to."
echo " threads - Number of processes to use for the migration."
echo " By default, `migratevdisk` uses 2."
echo
exit 1;
fi
if [ ! -f $svc_priv_dsa ] ; then
echo " ${0##*/} is missing the SSH DSA private key"
echo " needed to access the SAN Volume controller."
echo " Please specify the correct path!"
fi
mdiskgrp_old=$1
mdiskgrp_new=$2
threads=$3
: ${threads:=2}
check_running_migrations() {
# Get the number of already running migrations. The SVC is currently
# able to run 32 migrations at the same time.
running="$( ssh -i $svc_priv_dsa admin@$svc_cluster_ip svcinfo lsmigrate
| grep progress | wc -l )"
if [ $running -ge 32 ] ; then
echo
echo " The SVC is already running the maximum amount of migrations"
echo " at this time. Please retry, once the running migrations"
echo " finished."
echo
exit 1
fi
}
check_running_migrations
if [ "$( ssh -i $svc_priv_dsa admin@$svc_cluster_ip svcinfo lsmdiskgrp
$mdiskgrp_new &>/dev/null ; echo $? )" = 1 ] ; then
echo "${0##*/}: The MDisk Group ($mdiskgrp_new) doesn't existent!"
exit 1
fi
echo "Legend:"
echo
echo -e " 33[0;32m*33[0m VDisk migration started successfully"
echo -e " 33[0;36m*33[0m VDisk migration skipped (already running?)"
echo -e " 33[0;31m*33[0m VDisk migration failed to start (wrong name?)"
echo
echo "Starting the tasks to migrate VDisks of $mdiskgrp_old to $mdiskgrp_new"
for vdisk in $( ssh -i $svc_priv_dsa admin@$svc_cluster_ip svcinfo
lsvdisk -nohdr -delim : -filtervalue mdisk_grp_name=$mdiskgrp_old ); do
vdisk_id="$( echo $vdisk | cut -d: -f1 )"
vdisk_name="$( echo $vdisk | cut -d: -f2 )"
# Check if there's already a migration running for this vdisk
if [ "$( ssh -i $svc_priv_dsa admin@$svc_cluster_ip svcinfo lsmigrate
| grep "migrate_source_vdisk_index $vdisk_id$" )" != "" ] ; then
echo -e " 33[0;36m*33[0m VDisk $vdisk_name ($vdisk_id)"
continue
fi
check_running_migrations
ssh -i $svc_priv_dsa admin@$svc_cluster_ip svctask migratevdisk
-mdiskgrp $mdiskgrp_new -threads $threads
-vdisk $vdisk_name &>/dev/null
response=$?
[ $response -eq 0 ] &&
echo -e " 33[0;32m*33[0m VDisk $vdisk_name ($vdisk_id)"
|| echo -e " 33[0;31m*33[0m VDisk $vdisk_name ($vdisk_id)"
running=$((running+1))
done
echo