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.
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:
Without host-level backups, rebuilding a failed Proxmox node means manually reconfiguring everything from memory or outdated documentation.
A bash script runs monthly via cron.monthly, creating timestamped tar archives of critical directories and storing them on a network SMB share.
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}"Security: Use credentials file instead of plaintext password in fstab. Create /root/.smbcredentials with permissions 600.
Script uses $(hostname) to namespace backups automatically. Deploy the same script to all Proxmox servers without modification.
Fully automated host configuration backup solution running across multiple Proxmox nodes. Monthly backups provide 6 months of retention with automatic cleanup.
Need disaster recovery planning? We design backup strategies that work when you need them - host configs, VMs, databases - all automated and tested.
Contact Us