Files
proxmox/scripts/restore-lvm-volumes.sh

62 lines
1.8 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
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 to restore LVM logical volumes from backup
# This is needed after RAID recreation
set -u
TARGET_NODE="r630-01"
TARGET_NODE_IP="${PROXMOX_HOST_R630_01}"
TARGET_NODE_PASS="password"
ssh_r630_01() {
sshpass -p "$TARGET_NODE_PASS" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@"$TARGET_NODE_IP" "$@" 2>&1
}
log_info() { echo -e "\033[0;34m[INFO]\033[0m $1"; }
log_success() { echo -e "\033[0;32m[✓]\033[0m $1"; }
log_error() { echo -e "\033[0;31m[✗]\033[0m $1"; }
log_warn() { echo -e "\033[1;33m[⚠]\033[0m $1"; }
# Check if we can find the data on the RAID
log_info "Checking RAID and VG status..."
ssh_r630_01 "cat /proc/mdstat | grep md0"
ssh_r630_01 "vgs pve"
ssh_r630_01 "pvs | grep pve"
log_info "Attempting to restore logical volumes..."
log_warn "This is a critical operation - data recovery may be needed"
# Try to use vgcfgrestore with all available backups
log_info "Checking available backups..."
BACKUP_FILE=$(ssh_r630_01 "ls -t /etc/lvm/backup/pve* /etc/lvm/archive/pve_*.vg 2>/dev/null | head -1")
if [ -n "$BACKUP_FILE" ]; then
log_info "Found backup: $BACKUP_FILE"
log_info "Attempting full restore..."
ssh_r630_01 "vgcfgrestore -f $BACKUP_FILE pve --force" || {
log_error "Restore failed"
exit 1
}
log_info "Activating VG..."
ssh_r630_01 "vgchange -ay pve"
log_info "Scanning for logical volumes..."
ssh_r630_01 "lvscan"
log_info "Current LVM status:"
ssh_r630_01 "lvs -a"
else
log_error "No backup file found"
exit 1
fi
log_info "Done. Check lvs output above to see if volumes were restored."