Files
proxmox/scripts/maintenance/migrate-ct-r630-01-data-to-thin1.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

83 lines
2.7 KiB
Bash

#!/usr/bin/env bash
# Migrate one LXC container from r630-01 data pool to thin1 (same host).
# Use to free space on data (currently 72%). See docs/04-configuration/MIGRATION_PLAN_R630_01_DATA.md
#
# Usage: bash scripts/maintenance/migrate-ct-r630-01-data-to-thin1.sh <VMID> [--dry-run]
# Example: bash scripts/maintenance/migrate-ct-r630-01-data-to-thin1.sh 10232
# Requires: SSH to r630-01. Run from project root (LAN).
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
[[ -f "${PROJECT_ROOT}/config/ip-addresses.conf" ]] && source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
R630_01="${PROXMOX_HOST_R630_01:-192.168.11.11}"
TARGET="thin1"
SSH_OPTS="-o ConnectTimeout=10 -o StrictHostKeyChecking=no"
VMID="${1:-}"
DRY_RUN=false
[[ "${2:-}" == "--dry-run" ]] && DRY_RUN=true
if [[ -z "$VMID" ]] || ! [[ "$VMID" =~ ^[0-9]+$ ]]; then
echo "Usage: $0 <VMID> [--dry-run]"
echo " Migrates CT VMID from data to thin1 on r630-01."
echo " Suggested VMIDs (small first): 10232 10233 10120 10100 10101 10235 10236 7804 8640 8642"
exit 1
fi
run() { ssh $SSH_OPTS "root@$R630_01" "$@"; }
echo "=== Migrate CT $VMID from data to $TARGET on r630-01 ==="
echo " dry-run=$DRY_RUN"
echo ""
# Check CT exists and is on data
ROOTFS=$(run "pct config $VMID 2>/dev/null | grep '^rootfs:'" || true)
if [[ -z "$ROOTFS" ]]; then
echo "ERROR: CT $VMID not found on r630-01."
exit 1
fi
if ! echo "$ROOTFS" | grep -q 'local-lvm\|data'; then
echo "WARNING: CT $VMID rootfs does not look like data pool: $ROOTFS"
read -p "Continue anyway? [y/N] " -n 1 -r; echo
[[ "${REPLY:-}" =~ ^[yY]$ ]] || exit 1
fi
if $DRY_RUN; then
echo "Would: stop $VMID -> vzdump -> destroy -> restore --storage $TARGET -> start"
exit 0
fi
echo "1. Stopping CT $VMID..."
run "pct stop $VMID" 2>/dev/null || true
sleep 3
echo "2. Backup (vzdump)..."
run "vzdump $VMID --storage local --compress gzip --mode stop --remove 0 2>&1" || true
BACKUP_FILE=$(run "ls -t /var/lib/vz/dump/vzdump-lxc-$VMID-*.tar.gz 2>/dev/null | head -1" || true)
if [[ -z "$BACKUP_FILE" ]]; then
echo "ERROR: Backup not found. Start CT back: ssh root@$R630_01 'pct start $VMID'"
exit 1
fi
echo " Backup: $BACKUP_FILE"
echo "3. Destroy CT..."
run "pct destroy $VMID --force 2>/dev/null" || true
sleep 2
echo "4. Restore to $TARGET..."
run "pct restore $VMID $BACKUP_FILE --storage $TARGET 2>&1" || {
echo "ERROR: Restore failed. Restore backup manually."
exit 1
}
echo "5. Remove backup..."
run "rm -f $BACKUP_FILE" 2>/dev/null || true
echo "6. Start CT..."
run "pct start $VMID"
echo ""
echo "Done. CT $VMID is now on $TARGET. Verify: ssh root@$R630_01 'pct config $VMID | grep rootfs'"