Files
proxmox/scripts/migrate-vms-to-r630-01.sh
defiQUG b3a8fe4496
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
chore: sync all changes to Gitea
- Config, docs, scripts, and backup manifests
- Submodule refs unchanged (m = modified content in submodules)

Made-with: Cursor
2026-03-02 11:37:34 -08:00

120 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Migrate VMIDs 100-130 and 7800-7811 from r630-02 to r630-01
# Uses thin1 storage on r630-01
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
source "$SCRIPT_DIR/load-physical-inventory.sh" 2>/dev/null || true
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[⚠]${NC} $1"; }
log_error() { echo -e "${RED}[✗]${NC} $1"; }
log_section() { echo -e "\n${CYAN}=== $1 ===${NC}\n"; }
SOURCE_NODE="r630-02"
TARGET_NODE="r630-01"
TARGET_STORAGE="thin1"
# VMs to migrate
VMIDS_100_130=(100 101 102 103 104 105 130)
VMIDS_7800_7811=(7800 7801 7802 7810 7811)
ALL_VMIDS=("${VMIDS_100_130[@]}" "${VMIDS_7800_7811[@]}")
log_section "VM Migration to r630-01"
log_info "Source Node: $SOURCE_NODE"
log_info "Target Node: $TARGET_NODE"
log_info "Target Storage: $TARGET_STORAGE"
log_info "VMs to migrate: ${#ALL_VMIDS[@]} containers"
echo ""
log_warn "This will migrate the following VMs:"
echo " VMIDs 100-130: ${VMIDS_100_130[*]}"
echo " VMIDs 7800-7811: ${VMIDS_7800_7811[*]}"
echo ""
read -p "Continue with migration? (yes/no): " confirm
if [[ "$confirm" != "yes" ]]; then
log_info "Migration cancelled."
exit 0
fi
log_section "Pre-Migration Verification"
log_info "Checking source VMs..."
sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_02:-192.168.11.12} \
"pct list 2>/dev/null | grep -E '$(IFS='|'; echo "${ALL_VMIDS[*]}")'" 2>/dev/null || {
log_warn "Some VMs may not be found (checking individually)"
}
log_info "Checking target storage..."
TARGET_AVAIL=$(sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_01:-192.168.11.11} \
"pvesm status $TARGET_STORAGE 2>/dev/null | awk 'NR>1 {print \$6/1048576}'" 2>/dev/null || echo "0")
log_info "Target storage available: ${TARGET_AVAIL} GB"
log_section "Starting Migration"
FAILED=()
SUCCESS=()
for vmid in "${ALL_VMIDS[@]}"; do
log_info "Migrating VMID $vmid..."
# Check if VM exists
if ! sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_02:-192.168.11.12} \
"pct list 2>/dev/null | grep -q \"^$vmid\"" 2>/dev/null; then
log_warn "VMID $vmid not found on source, skipping"
continue
fi
# Migrate
if sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_02:-192.168.11.12} \
"pct migrate $vmid $TARGET_NODE --storage $TARGET_STORAGE" 2>&1; then
log_success "VMID $vmid migrated successfully"
SUCCESS+=($vmid)
else
log_error "VMID $vmid migration failed"
FAILED+=($vmid)
fi
echo ""
done
log_section "Migration Summary"
log_info "Successful migrations: ${#SUCCESS[@]}"
if [ ${#SUCCESS[@]} -gt 0 ]; then
echo " VMIDs: ${SUCCESS[*]}"
fi
if [ ${#FAILED[@]} -gt 0 ]; then
log_warn "Failed migrations: ${#FAILED[@]}"
echo " VMIDs: ${FAILED[*]}"
fi
log_section "Verification"
log_info "Checking VMs on $TARGET_NODE..."
sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_01:-192.168.11.11} \
"pct list 2>/dev/null | grep -E '$(IFS='|'; echo "${ALL_VMIDS[*]}")'" 2>/dev/null || true
log_section "Migration Complete"
if [ ${#FAILED[@]} -eq 0 ]; then
log_success "All VMs migrated successfully!"
else
log_warn "Some migrations failed. Please check the errors above."
fi