Files
proxmox/scripts/recreate-container-volumes.sh.bak
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

119 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Script to recreate container volumes based on their configurations
# This creates empty volumes - data will need to be restored separately
set -u
TARGET_NODE="r630-01"
TARGET_NODE_IP="192.168.11.11"
TARGET_NODE_PASS="password"
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_error() { echo -e "${RED}[✗]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[⚠]${NC} $1"; }
ssh_r630_01() {
sshpass -p "$TARGET_NODE_PASS" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@"$TARGET_NODE_IP" "$@" 2>&1
}
recreate_container_volume() {
local vmid="$1"
local storage="$2"
local size="$3"
log_info "Recreating volume for container $vmid: storage=$storage, size=$size"
# Map storage names
local thin_pool=""
case "$storage" in
"local-lvm")
thin_pool="data"
;;
"thin1")
thin_pool="thin1"
;;
"data")
thin_pool="data"
;;
*)
log_warn "Unknown storage: $storage, using thin1"
thin_pool="thin1"
;;
esac
# Extract size (format: 10G, 20G, etc.)
local volume_size=$(echo "$size" | grep -oE '[0-9]+[GM]' | head -1 || echo "10G")
log_info "Creating volume vm-$vmid-disk-0 size=$volume_size on pool=$thin_pool"
# Create thin volume (correct syntax: lvcreate -n <name> -V <size> <vg>/<thin_pool>)
if ssh_r630_01 "lvcreate -n vm-$vmid-disk-0 -V $volume_size pve/$thin_pool"; then
log_success "Volume created for container $vmid"
return 0
else
log_error "Failed to create volume for container $vmid"
return 1
fi
}
main() {
echo ""
log_warn "=== WARNING: Volume Recreation ==="
log_warn "This will create EMPTY volumes for containers"
log_warn "Container data will be LOST unless restored from backups"
log_warn ""
read -p "Continue? (yes/no): " confirm
if [ "$confirm" != "yes" ]; then
log_info "Operation cancelled"
exit 0
fi
log_info "Reading container configurations..."
# Get all container IDs
local containers=$(ssh_r630_01 "pct list | awk 'NR>1 {print \$1}'")
local success=0
local failed=0
for vmid in $containers; do
local config=$(ssh_r630_01 "pct config $vmid 2>&1")
if echo "$config" | grep -q "rootfs:"; then
local rootfs_line=$(echo "$config" | grep "^rootfs:")
local storage=$(echo "$rootfs_line" | awk '{print $2}' | cut -d: -f1)
local volume_name=$(echo "$rootfs_line" | awk '{print $2}' | cut -d: -f2 | cut -d, -f1)
local size=$(echo "$rootfs_line" | grep -oE 'size=[0-9]+[GM]' | cut -d= -f2 || echo "10G")
# Check if volume already exists
if ssh_r630_01 "lvs pve | grep -q vm-$vmid-disk-0"; then
log_info "Volume for container $vmid already exists, skipping..."
continue
fi
if recreate_container_volume "$vmid" "$storage" "$size"; then
success=$((success + 1))
else
failed=$((failed + 1))
fi
fi
done
echo ""
log_success "Volume recreation complete: $success succeeded, $failed failed"
log_info "Containers can now be started, but will have empty filesystems"
log_warn "Restore data from backups if available"
}
main "$@"