Files
backup_to_external_m.2/preview_snapshot_migration.sh
root 29347fc8a6 Add snapshot-based LVM migration scripts
- snapshot_migrate_to_internal.sh: Complete snapshot-based migration from external M.2 to internal NVMe
- preview_snapshot_migration.sh: Preview script showing snapshot migration process
- migrate_lvm_to_internal.sh: Alternative rsync-based migration script
- preview_migration.sh: Preview for rsync-based migration

Key features:
- LVM snapshot creation of ALL logical volumes (root, home, boot, swap)
- Block-level dd copying for exact system clone
- Automatic LVM structure setup on internal drive
- GRUB/EFI boot configuration
- Future snapshot management tools
- Space-efficient one-at-a-time processing

Migration preserves complete live system state with bit-perfect accuracy.
2025-09-30 17:35:22 +02:00

104 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
# Snapshot Migration Preview Script
# Shows what the snapshot-based migration will do
set -euo pipefail
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${BLUE}=== Snapshot-Based LVM Migration Preview ===${NC}"
echo
echo -e "${GREEN}Current System Status:${NC}"
echo "✅ Booted from: $(findmnt -n -o SOURCE /)"
echo "✅ Volume Group: migration-vg"
echo
echo -e "${GREEN}Current Logical Volumes:${NC}"
sudo lvs migration-vg --units g -o lv_name,lv_size,data_percent 2>/dev/null
echo
echo -e "${GREEN}Available Space for Snapshots:${NC}"
free_space=$(sudo vgs --noheadings --units m --nosuffix -o vg_free migration-vg | tr -d ' ' | tr ',' '.')
if command -v bc >/dev/null 2>&1; then
snapshot_size_per_lv=$(echo "$free_space * 0.8 / 4" | bc 2>/dev/null | cut -d. -f1)
else
snapshot_size_per_lv=$((${free_space%.*} * 80 / 100 / 4))
fi
echo "Free space: ${free_space}MB"
echo "Snapshot size per LV: ${snapshot_size_per_lv}MB"
if (( snapshot_size_per_lv < 100 )); then
echo -e "${RED}⚠️ WARNING: Limited space for snapshots!${NC}"
echo "Consider freeing up space or expanding the volume group"
else
echo -e "${GREEN}✅ Sufficient space for snapshots${NC}"
fi
echo
echo -e "${GREEN}Target Drive Analysis:${NC}"
echo "Internal NVMe (nvme0n1):"
lsblk /dev/nvme0n1
echo "Size: $(lsblk -b -n -o SIZE /dev/nvme0n1 | awk '{printf "%.1fGB", $1/1024/1024/1024}')"
echo
echo -e "${YELLOW}Snapshot Migration Process:${NC}"
echo "1. 📸 Create temporary snapshots of ALL logical volumes:"
echo " • root (${snapshot_size_per_lv}MB snapshot)"
echo " • home (${snapshot_size_per_lv}MB snapshot)"
echo " • boot (${snapshot_size_per_lv}MB snapshot)"
echo " • swap (${snapshot_size_per_lv}MB snapshot)"
echo
echo "2. 🔧 Prepare internal drive:"
echo " • Copy partition table from external M.2"
echo " • Create LVM physical volume"
echo " • Create volume group 'internal-vg'"
echo " • Create logical volumes with exact same sizes"
echo
echo "3. 📋 Transfer data using block-level copy:"
echo " • Use dd to copy each snapshot to internal LV"
echo " • Process one LV at a time to manage space"
echo " • Remove each snapshot after successful copy"
echo
echo "4. ⚙️ Configure boot:"
echo " • Update fstab for new volume group"
echo " • Install GRUB on internal drive"
echo " • Update initramfs for LVM"
echo
echo "5. 🛠️ Setup snapshot tools:"
echo " • Install lvm-snapshot-manager"
echo " • Reserve space for future snapshots"
echo
echo -e "${RED}⚠️ CRITICAL WARNINGS:${NC}"
echo "• Internal NVMe will be COMPLETELY WIPED"
echo "• This creates an EXACT copy including all current data"
echo "• Process takes 1-3 hours depending on data size"
echo "• Snapshots use limited available space"
echo
echo -e "${GREEN}Advantages of Snapshot Method:${NC}"
echo "✅ Exact bit-for-bit copy of live system"
echo "✅ No filesystem corruption risks"
echo "✅ Can capture running system state"
echo "✅ Uses LVM native capabilities"
echo "✅ Block-level transfer (faster than file copy)"
echo
echo -e "${GREEN}Post-Migration Capabilities:${NC}"
echo "• sudo lvm-snapshot-manager create - Create system snapshots"
echo "• sudo lvm-snapshot-manager list - Show snapshots"
echo "• sudo lvm-snapshot-manager remove - Clean up snapshots"
echo "• sudo lvm-snapshot-manager merge - Restore from snapshot"
echo
echo -e "${BLUE}Ready to proceed with snapshot migration?${NC}"
echo "Run: sudo ./snapshot_migrate_to_internal.sh"
echo
echo -e "${YELLOW}Estimated time: 1-3 hours${NC}"