Skip to content

Instantly share code, notes, and snippets.

@bureado
Created July 30, 2015 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bureado/4a88c5650af20694d9b8 to your computer and use it in GitHub Desktop.
Save bureado/4a88c5650af20694d9b8 to your computer and use it in GitHub Desktop.
Script to switch RAID array from master to slave in Azure
#!/bin/sh
master=$1
slave=$2
date
echo "Assuming master down: $master"
echo "Switching to slave: $slave"
azure vm show $master --json > /tmp/$master.json
disknum=`jq -r '.DataDisks[]|.name' /tmp/$master.json | wc -l`
maxlun=`expr $disknum - 1`
echo "$disknum disks found in $master"
for lun in `seq 0 $maxlun`
do
echo "Detaching LUN $lun from VM $master"
azure vm disk detach $master $lun
azure vm disk list --json > /tmp/$master.$lun.json
done
for disk in `jq -r '.DataDisks[]|.name' /tmp/$master.json`
do
echo "Attaching disk $disk to VM $slave"
azure vm disk attach -c None $slave $disk
done
echo "All disks attached, now log onto $slave and run:"
echo "sudo mdadm --assemble /dev/md0 \`ls -1t /dev/sd* | head -n$disknum | xargs\`"
echo "sudo mount /dev/md0 /nfs"
date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment