Files
proxmox/scripts/archive/backups/migrate-vms-backup-restore-complete.sh
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands
- CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround
- CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check
- NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere
- MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates
- LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 15:46:57 -08:00

174 lines
5.7 KiB
Bash

#!/bin/bash
# Migrate VMIDs 100-130 and 7800-7811 using backup/restore method
# VMIDs 100-130 → thin1 storage
# VMIDs 7800-7811 → local storage
set -euo pipefail
# Load IP configuration
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
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
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"
BACKUP_STORAGE="local"
# VMs to migrate
VMIDS_100_130=(100 101 102 103 104 105 130)
VMIDS_7800_7811=(7800 7801 7802 7810 7811)
log_section "VM Migration to r630-01 (Backup/Restore)"
log_info "Source Node: $SOURCE_NODE"
log_info "Target Node: $TARGET_NODE"
log_info "VMIDs 100-130 → thin1 storage (96 GB)"
log_info "VMIDs 7800-7811 → local storage (210 GB)"
echo ""
log_warn "This will migrate ${#VMIDS_100_130[@]} + ${#VMIDS_7800_7811[@]} = $((${#VMIDS_100_130[@]} + ${#VMIDS_7800_7811[@]})) containers using backup/restore"
echo ""
read -p "Continue with migration? (yes/no): " confirm
if [[ "$confirm" != "yes" ]]; then
log_info "Migration cancelled."
exit 0
fi
FAILED=()
SUCCESS=()
# Migrate VMIDs 100-130 to thin1
log_section "Migrating VMIDs 100-130 to thin1 storage"
for vmid in "${VMIDS_100_130[@]}"; 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, skipping"
continue
fi
# Create backup (this will work since VMs are stopped)
log_info " Creating backup..."
sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_02:-192.168.11.12} \
"vzdump $vmid --storage $BACKUP_STORAGE --compress gzip --mode stop 2>&1 | tail -5"
# Find backup file
BACKUP_FILE=$(sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_02:-192.168.11.12} \
"ls -t /var/lib/vz/dump/vzdump-lxc-$vmid-*.tar.gz 2>/dev/null | head -1" 2>/dev/null)
if [ -z "$BACKUP_FILE" ]; then
log_error " Backup file not found for VMID $vmid"
FAILED+=($vmid)
continue
fi
log_info " Backup: $BACKUP_FILE"
# Restore to target
log_info " Restoring to $TARGET_NODE (thin1 storage)..."
RESTORE_OUTPUT=$(sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_02:-192.168.11.12} \
"pct restore $vmid $BACKUP_FILE --storage thin1 --target $TARGET_NODE 2>&1")
if [ $? -eq 0 ]; then
log_success " VMID $vmid migrated successfully"
SUCCESS+=($vmid)
# Remove from source
sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_02:-192.168.11.12} \
"pct destroy $vmid 2>&1" || true
else
log_error " Restore failed: $RESTORE_OUTPUT"
FAILED+=($vmid)
fi
echo ""
done
# Migrate VMIDs 7800-7811 to local storage
log_section "Migrating VMIDs 7800-7811 to local storage"
for vmid in "${VMIDS_7800_7811[@]}"; 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, skipping"
continue
fi
# Create backup
log_info " Creating backup..."
sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_02:-192.168.11.12} \
"vzdump $vmid --storage $BACKUP_STORAGE --compress gzip --mode stop 2>&1 | tail -5"
# Find backup file
BACKUP_FILE=$(sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_02:-192.168.11.12} \
"ls -t /var/lib/vz/dump/vzdump-lxc-$vmid-*.tar.gz 2>/dev/null | head -1" 2>/dev/null)
if [ -z "$BACKUP_FILE" ]; then
log_error " Backup file not found for VMID $vmid"
FAILED+=($vmid)
continue
fi
log_info " Backup: $BACKUP_FILE"
# Restore to target
log_info " Restoring to $TARGET_NODE (local storage)..."
RESTORE_OUTPUT=$(sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_02:-192.168.11.12} \
"pct restore $vmid $BACKUP_FILE --storage local --target $TARGET_NODE 2>&1")
if [ $? -eq 0 ]; then
log_success " VMID $vmid migrated successfully"
SUCCESS+=($vmid)
# Remove from source
sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_02:-192.168.11.12} \
"pct destroy $vmid 2>&1" || true
else
log_error " Restore failed: $RESTORE_OUTPUT"
FAILED+=($vmid)
fi
echo ""
done
log_section "Migration Summary"
log_info "Successful: ${#SUCCESS[@]}"
if [ ${#SUCCESS[@]} -gt 0 ]; then
echo " VMIDs: ${SUCCESS[*]}"
fi
if [ ${#FAILED[@]} -gt 0 ]; then
log_warn "Failed: ${#FAILED[@]}"
echo " VMIDs: ${FAILED[*]}"
fi
log_section "Verification"
sshpass -p "password" ssh -o StrictHostKeyChecking=no root@${PROXMOX_HOST_R630_01:-192.168.11.11} \
"pct list 2>/dev/null | grep -E '100|101|102|103|104|105|130|7800|7801|7802|7810|7811'" 2>/dev/null || true
log_section "Complete"