Skip to content

Instantly share code, notes, and snippets.

@hoonetorg
Created February 5, 2018 16:14
Show Gist options
  • Save hoonetorg/9ca13558251984fbfa56da4ddece96d4 to your computer and use it in GitHub Desktop.
Save hoonetorg/9ca13558251984fbfa56da4ddece96d4 to your computer and use it in GitHub Desktop.
#!/bin/bash
VM=$1
DESTHOST=$2
[ -z "$VM" ] && exit 1
[ -z "$DESTHOST" ] && exit 1
(virsh list --name |grep -w "$VM") || exit 1
echo "$VM is running here"
DRBDMANAGERESs="`virsh domblklist $VM |grep /dev/drbd/by-res/|perl -pe 's;^.*/dev/drbd/by-res/(.*)/[0-9]+\s*$;$1 ;g'`"
for DRBDMANAGERES in $DRBDMANAGERESs; do
drbdmanage net-options --allow-two-primaries yes --resource $DRBDMANAGERES || exit 1
echo "allow two primaries is set for disk $DRBDMANAGERES"
done
echo "allow two primaries is set for disks: $DRBDMANAGERESs"
virsh migrate $VM qemu+ssh://$DESTHOST/system --live --p2p --undefinesource --verbose --compressed --auto-converge
for DRBDMANAGERES in $DRBDMANAGERESs; do
drbdmanage net-options --unset-allow-two-primaries --resource $DRBDMANAGERES || exit 1
echo "allow two primaries is unset for disk $DRBDMANAGERES"
done
echo "allow two primaries is unset for disks: $DRBDMANAGERESs"
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment