Files
ansible/proxmox/admin_scripts/migrate_running.sh

25 lines
556 B
Bash
Executable File

#!/bin/bash
set -e
if ! which jq >> /dev/null; then
echo "jq not found"
exit 1
fi
if [ "$#" -ne 2 ]; then
pvesh get /nodes
echo "usage: $0 <node_from> <node_to>"
exit 1
fi
from="$1"
target="$2"
migratable_ids="$(pvesh get "/nodes/${from}/qemu" --output-format json |\
jq -r 'map(select( .status == "running" and (.tags | split(";") | all(.!="nomigrate")) ) | .vmid) | @csv')"
if [[ "$migratable_ids" != "" ]]; then
echo "$from $target $migratable_ids"
pvesh create "/nodes/${from}/migrateall" -vms "$migratable_ids" -target "$target"
fi