Created
July 14, 2020 13:08
-
-
Save samson4649/83155e7233f2fe8fedde6e7c601e2fd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
########################### | |
# _ ____ ____ __ ____ ___ __ __ _ ___ _ _ | |
# | |/ /\ \ / / \/ | | _ \ / _ \| \/ | / \ |_ _| \ | | | |
# | ' / \ \ / /| |\/| | | | | | | | | |\/| | / _ \ | || \| | | |
# | . \ \ V / | | | | | |_| | |_| | | | |/ ___ \ | || |\ | | |
# |_|\_\ \_/ |_| |_| |____/ \___/|_| |_/_/ \_\___|_| \_| | |
# | |
# ____ ____ _ ___ _ _ | |
# | _ \| _ \ / \ |_ _| \ | | | |
# | | | | |_) | / _ \ | || \| | | |
# | |_| | _ < / ___ \ | || |\ | | |
# |____/|_| \_\/_/ \_\___|_| \_| | |
# | |
# | |
# v1.0.1 | |
# By: Samuel Lock (github.com/samson4649) | |
# | |
# script used to assist in the migration of virtual machine between blade servers | |
# | |
########################### | |
function _fatal(){ | |
echo "FATAL: $@" | |
exit 99 | |
} | |
let -a DOMAINS | |
let -a POSITIONAL_ARGS | |
while [[ $# -gt 0 ]]; do | |
key="$1" | |
case ${key} in | |
-d|--domain) | |
DOMAINS+=("$2") | |
shift | |
shift | |
;; | |
-r|--remote|--receiver) | |
RECEIVING_HOST="$2" | |
shift | |
shift | |
;; | |
*) | |
POSITIONAL_ARGS+=("$1") | |
shift | |
;; | |
esac | |
done | |
# reset positionals | |
set -- "${POSITIONAL_ARGS[@]}" | |
# capture remote server as positional | |
if [ -z "${RECEIVING_HOST}" ]; then | |
if [[ $# -gt 0 ]]; then | |
RECEIVING_HOST="$1" | |
shift | |
else | |
_fatal "Not able to parse receiving host" | |
fi | |
fi | |
# capture vms as positional | |
for x in "$@"; do | |
DOMAINS+=( "${x}" ) | |
done | |
if [[ ${#DOMAINS[@]} -lt 1 ]]; then | |
_fatal "No virtual machines parsed..." | |
fi | |
# test that KVM_HOST online | |
if ! ping -c 1 -W 5 ${RECEIVING_HOST} &>/dev/null ; then | |
_fatal "Failed to reach kvm host '${RECEIVING_HOST}'" | |
fi | |
# checking that domains exist on this host | |
for domain in "${DOMAINS[@]}"; do | |
virsh list --name | grep -E "^${domain}\$" &>/dev/null \ | |
|| _fatal "Not able to locate domain '${domain}' on this host" | |
done | |
for dom in "${DOMAINS[@]}"; do | |
echo "#### Migrating Domain: ${dom} ####" | |
virsh migrate \ | |
--live \ | |
--persistent \ | |
--undefinesource \ | |
--copy-storage-all \ | |
--verbose \ | |
"${dom}" qemu+ssh://${RECEIVING_HOST}/system | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment