diff --git a/defaults.inc b/defaults.inc index 2b582ad..e08a5c3 100755 --- a/defaults.inc +++ b/defaults.inc @@ -3,7 +3,7 @@ action="${1:-}" FOLDER='/opt/idssys/ta-proxmenu' -VERS='2026.7.25-13' +VERS='2026.7.25-14' noupdate=' ' diff --git a/inc/evacuate-proxmox-node.sh b/inc/evacuate-proxmox-node.sh index 2a893b4..287ab9f 100755 --- a/inc/evacuate-proxmox-node.sh +++ b/inc/evacuate-proxmox-node.sh @@ -7,8 +7,12 @@ set -u HA_WAIT_SECONDS=300 MAINTENANCE_WAIT_SECONDS=60 +MAX_PARALLEL_MIGRATIONS=3 SHUTDOWN_TIMEOUT=180 LOCAL_NODE="$(hostname -s)" +MIGRATION_LOG_DIR="$(mktemp -d)" + +trap 'rm -rf "$MIGRATION_LOG_DIR"' EXIT log() { printf '\n[%s] %s\n' "$(date '+%F %T')" "$*" @@ -227,6 +231,39 @@ migrate_guest() { fi } +wait_for_migration_batch() { + local index + local pid + local guest + local log_file + local vmid + local guest_type + local status + local name + + for index in "${!batch_pids[@]}"; do + pid="${batch_pids[$index]}" + guest="${batch_guests[$index]}" + log_file="${batch_logs[$index]}" + IFS=$'\x1f' read -r vmid guest_type status name <<< "$guest" + + if wait "$pid"; then + log "Migration completed for ${guest_type} ${vmid} (${name:-unnamed})." + else + warn "Migration failed for ${guest_type} ${vmid} (${name:-unnamed})." + migration_failures+=("$guest") + fi + + if [[ -s "$log_file" ]]; then + sed 's/^/ /' "$log_file" + fi + done + + batch_pids=() + batch_guests=() + batch_logs=() +} + shutdown_guest() { local vmid="$1" local guest_type="$2" @@ -330,15 +367,27 @@ read -r -p "Proceed with shared-storage guest migration? [y/N] " answer [[ "$answer" =~ ^[Yy]$ ]] || { echo "Evacuation cancelled."; exit 0; } declare -a migration_failures=() +declare -a batch_pids=() +declare -a batch_guests=() +declare -a batch_logs=() + for guest in "${shared_guests[@]}"; do IFS=$'\x1f' read -r vmid guest_type status name <<< "$guest" - log "Migrating ${guest_type} ${vmid} (${name:-unnamed}) to ${TARGET_NODE}." - if ! migrate_guest "$vmid" "$guest_type" "$status"; then - warn "Migration failed for ${guest_type} ${vmid}." - migration_failures+=("$guest") + log "Starting migration for ${guest_type} ${vmid} (${name:-unnamed}) to ${TARGET_NODE}." + + log_file="${MIGRATION_LOG_DIR}/${guest_type}-${vmid}.log" + migrate_guest "$vmid" "$guest_type" "$status" >"$log_file" 2>&1 & + batch_pids+=("$!") + batch_guests+=("$guest") + batch_logs+=("$log_file") + + if (( ${#batch_pids[@]} >= MAX_PARALLEL_MIGRATIONS )); then + wait_for_migration_batch fi done +(( ${#batch_pids[@]} == 0 )) || wait_for_migration_batch + declare -a running_local_guests=() for guest in "${local_guests[@]}"; do IFS=$'\x1f' read -r vmid guest_type status name reason <<< "$guest"