ansible-on-prem/roles/pve/pve_backup/templates/backup_pve_config.sh.j2
2025-07-10 21:24:28 -06:00

24 lines
714 B
Django/Jinja

#!/bin/bash
set -e
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
BACKUP_DIR="/home/xbazzi/pve_backup_${TIMESTAMP}"
NODE_NAME=$(hostname)
echo "🔒 Creating backup directory at $BACKUP_DIR..."
mkdir -p "$BACKUP_DIR"
echo "📁 Backing up /etc/pve..."
cp -a /etc/pve "$BACKUP_DIR/etc_pve"
echo "📄 Saving VM and container config files..."
mkdir -p "$BACKUP_DIR/qemu-server" "$BACKUP_DIR/lxc"
cp -a /etc/pve/qemu-server/*.conf "$BACKUP_DIR/qemu-server/" 2>/dev/null || true
cp -a /etc/pve/lxc/*.conf "$BACKUP_DIR/lxc/" 2>/dev/null || true
echo "💽 Saving storage.cfg..."
cp -a /etc/pve/storage.cfg "$BACKUP_DIR/" 2>/dev/null || true
echo "📦 Backup complete on $NODE_NAME."
echo "🗃️ Location: $BACKUP_DIR"