A background pattern of shaded interlocking triangles

A simple, centralised approach to backing-up multiple Proxmox VE hosts

The article shares a simple way of backing up multiple Proxmox VE hosts using a single script.

The Proxmox VE host backup gap

 
Proxmox VE lacks an official way of backing up hosts. To address, some commentators suggest scripts to backup individual Proxmox VE hosts, many of which can be found by searching. Such scripts are designed to run on the individual host, and back up configuration to a (typically) remote location. 

Scale challenges

 
Such scripts work very well for single hosts and smaller installations, however, for larger numbers of hosts the approach may fail to scale elegantly due to the necessity to install and maintain individual backup scripts across multiple hosts.

Scripting for scale

 
To fix the problem of scale, the following script extends previous work to provide a single, simple and centralised script to back up multiple Proxmox VE hosts at once. 
 
This means a single management machine can back up entire Proxmox VE clusters of many hosts without requirement to manage individual backup scripts. This reduces administrative effort as only a single instance of the backup script needs to be maintained.

Additional backup features

 
As a bonus, the script also backs-up additional configuration elements typical to Proxmox VE hosts, including:
  • NTP configuration 
  • Telegraph monitoring agent
  • Syslog configuration 
  • SNMP configuration 
  • Zabbix  monitoring agent, and 
  • NFS exports.  
 
The script could be extended to backup other elements by modifying the pattern of directories and files captured to better reflect your own requirements. 

Usage

 
Select a host upon which the backup script will run. This host should have connectivity to all of the Proxmox VE hosts to be backed-up. You could use one of your existing Proxmox VE hosts, or another machine; perhaps one dedicated to centralised monitoring or administration.
 
The host upon which the backup script will run should also have mounted a location at which the backups can be copied-to and stored. This might be a local or remote location depending upon your requirement. 
 
Ensure the host upon which the backup script will run can connect to each Proxmox VE hosts to be backed-up via SSH using key-based authentication. This is required to enable non-interactive login.
 
Amend the variables within the script template below to suit your environment, where:
  • DEST is the path to the directory where backups will be stored. This can (and possibly should) be a mount from a remote location.
  • HOSTS is the list of Proxmox VE hosts to be backed-up
  • RETENTIONDAYS is the number of days for which backups will be retained for each host.   
 
Save the file using a text editor of your choice, eg:
/root/backupProxmoxHosts.sh
 
Make it executable:
chmod +x /root/backupProxmoxHosts.sh
 
Test it and verify it works as expected, and if so, schedule it to run automatically via crontab:
 
crontab -e
22 23 * * *   /root/backupProxmoxHosts.sh

The Script

#!/bin/bash

DEST="/mnt/YourNetwork/Backups/ProxmoxVeHosts"
DATE=$(date +%F)
HOSTS=("PveHost1" "PveHost2" "PveHost3")
RETENTIONDAYS=29

mkdir -p $DEST

for HOST in ${HOSTS[@]}
  do
    # perform backup
    echo "Backing-up host: ${HOST}"
    ssh root@$HOST  \
	  'tar czf - \
	    /etc/pve /etc/network /etc/hosts /etc/chrony \
		/etc/telegraf /etc/rsyslog.conf /etc/snmp \
		/etc/zabbix /etc/exports' > \
	  $DEST/$HOST-pve-config-$DATE.tar.gz
    #apply retention
    find $DEST/${HOST}-pve-config*.gz \
     -mtime +${RETENTIONDAYS} \
     -exec rm -r {} \;
  done
  echo "Backup complete"

Conclusion

 
I hope this script is useful for those of us that run multiple Proxmox VE servers and need a simple, single and centralised way of backing up host configurations