Managed IT • Knoxville, TN
Proxmox Config Backups
infrastructure
dateJan 31, 2025
statusIMPLEMENTED
Summary

Deployed automated monthly backup solution for Proxmox VE host configurations using bash script and cron.monthly. Backs up critical system directories to centralized SMB share with 6-month retention. Ensures rapid disaster recovery without relying on VM-level backups for host configuration.

The Challenge

Proxmox VE provides excellent built-in backup solutions for VMs and containers, but host-level configuration is often overlooked. If a Proxmox host fails catastrophically, you need:

critical host config:
network ··········· bridges, bonds, VLANs
scripts ··········· custom automation in /root and /opt
cluster ··········· certificates and membership data
storage ··········· mount points and credentials
system ············ /etc customizations

Without host-level backups, rebuilding a failed Proxmox node means manually reconfiguring everything from memory or outdated documentation.

Solution Architecture

A bash script runs monthly via cron.monthly, creating timestamped tar archives of critical directories and storing them on a network SMB share.

key features:
monthly execution ··· via cron
centralized storage · SMB share accessible by all hosts
timestamped ········ point-in-time recovery
auto retention ····· keeps latest 6, deletes older
logging ············ audit trail in /var/log
pre-flight check ··· verifies SMB mount availability
Directories Backed Up
/etc
system configs: network bridges, storage mounts, services
/root
admin home: custom scripts, SSH keys, tooling
/opt
third-party: monitoring agents, custom apps
/var/lib/pve-cluster
cluster data: VM configs, permissions, datacenter settings
Backup Script

Script placed in /etc/cron.monthly/ runs automatically on the first of each month.

[+] proxmox_config_to_nas
#!/bin/bash

# Define backup location (Proxmox SMB mount point)
SMB_FOLDER="/mnt/pve/proxmox_hosts"
LOG_FILE="/var/log/proxmox_config_backup.log"
TIMESTAMP=$(date +'%Y-%m-%d_%I-%M-%S%p')
HOSTNAME=$(hostname)

# Directories to back up (Absolute Paths)
DIRS_TO_BACKUP=(
  "/etc"
  "/root"
  "/opt"
  "/var/lib/pve-cluster"
)

# Ensure SMB mount is available before proceeding
if ! mount | grep -q "$SMB_FOLDER"; then
  echo "$(date +'%Y-%m-%d %H:%M:%S') - ERROR: SMB Share ${SMB_FOLDER} not mounted!" | tee -a "${LOG_FILE}"
  exit 1
fi

echo "$(date +'%Y-%m-%d %H:%M:%S') - Starting Proxmox config backup for ${HOSTNAME}..." | tee -a "${LOG_FILE}"

# Backup each directory
for dir in "${DIRS_TO_BACKUP[@]}"; do
  if [ -d "$dir" ]; then
    BACKUP_FILE="${SMB_FOLDER}/${HOSTNAME}_$(basename $dir)_${TIMESTAMP}.tgz"
    echo "$(date +'%Y-%m-%d %H:%M:%S') - Backing up ${dir} to ${BACKUP_FILE}" | tee -a "${LOG_FILE}"

    tar --ignore-failed-read -czf "${BACKUP_FILE}" "${dir}" \
      && echo "$(date +'%Y-%m-%d %H:%M:%S') - Backup successful: ${BACKUP_FILE}" | tee -a "${LOG_FILE}" \
      || echo "$(date +'%Y-%m-%d %H:%M:%S') - ERROR: Failed to backup ${dir}" | tee -a "${LOG_FILE}"
  else
    echo "$(date +'%Y-%m-%d %H:%M:%S') - INFO: Skipping ${dir} (not found)" | tee -a "${LOG_FILE}"
  fi
done

# Cleanup: Keep only the last 6 backups per directory
echo "$(date +'%Y-%m-%d %H:%M:%S') - Cleaning up old backups..." | tee -a "${LOG_FILE}"
for dir in "${DIRS_TO_BACKUP[@]}"; do
  BACKUP_PREFIX="${SMB_FOLDER}/${HOSTNAME}_$(basename $dir)_"
  ls -t ${BACKUP_PREFIX}*.tgz | tail -n +7 | xargs rm -f 2>/dev/null
  echo "$(date +'%Y-%m-%d %H:%M:%S') - Cleanup done for ${dir}" | tee -a "${LOG_FILE}"
done

echo "$(date +'%Y-%m-%d %H:%M:%S') - Backup completed successfully for ${HOSTNAME}." | tee -a "${LOG_FILE}"
script behavior:
pre-flight ·········· verifies SMB mount (exits if not)
tar archives ········ timestamped per directory
--ignore-failed-read · continues if files locked
auto cleanup ········ keeps 6 most recent per dir
File Naming
format: {hostname}_{directory}_{timestamp}.tgz
examples:
proxmox01_etc_2025-01-28_11-06-13PM.tgz
proxmox01_root_2025-01-28_11-06-13PM.tgz
proxmox01_opt_2025-01-28_11-06-13PM.tgz
proxmox01_pve-cluster_2025-01-28_11-06-13PM.tgz
Implementation Steps
1. mount SMB share
add to /etc/fstab for persistence
verify: ls /mnt/pve/proxmox_hosts
2. install script
nano /etc/cron.monthly/proxmox_config_to_nas
chmod +x /etc/cron.monthly/proxmox_config_to_nas
3. test manually
/etc/cron.monthly/proxmox_config_to_nas
cat /var/log/proxmox_config_backup.log
4. verify cron
scripts in /etc/cron.monthly/ run automatically
fallback: add to crontab manually

Security: Use credentials file instead of plaintext password in fstab. Create /root/.smbcredentials with permissions 600.

Multi-Host Deployment

Script uses $(hostname) to namespace backups automatically. Deploy the same script to all Proxmox servers without modification.

benefits:
single script ······· works across entire cluster
auto-organized ······ backups sorted by hostname
centralized ········ one location for all hosts
independent ········ each host manages own retention
Outcome

Fully automated host configuration backup solution running across multiple Proxmox nodes. Monthly backups provide 6 months of retention with automatic cleanup.

maintenancezero ongoing
rebuild capabilityrapid (restore /etc, /root, cluster)
cluster-wideno per-host customization
takeaways:
VM backups useless if you can't rebuild the host
network config and cluster data are critical
simple bash + cron beats complex backup solutions
timestamped archives enable audit and rollback
Get Help

Need disaster recovery planning? We design backup strategies that work when you need them - host configs, VMs, databases - all automated and tested.

Contact Us