Skip to content

Example Proxmox

DatuX edited this page Nov 13, 2026 · 4 revisions

Backup a proxmox cluster with HA replication

This script backs up all important data of a Proxmox cluster. The cluster must use ZFS.

Proxmox can replicate ZFS datasets between nodes. A dataset can then exist on more than one node, but it is only active on one node. The script must only back up the active dataset. --exclude-unchanged does this: the copies that are not active do not change.

This example has 3 nodes: pve1, pve2 and pve3.

Preparing the proxmox nodes

Only set up the SSH keys, so that the backup server can log in to the Proxmox nodes. The script does all other steps.

Tip: Use a firewall on the backup server. Production machines must not have access to it.

SSH config on backup server

Put the SSH settings in ~/.ssh/config. In this example, the backup is offsite and uses port forwarding to the Proxmox nodes:

Host *
    ControlPath ~/.ssh/control-master-%r@%h:%p
    ControlMaster auto
    ControlPersist 3600
    Compression yes

Host pve1
    Hostname some.host.com
    Port 10001

Host pve2
    Hostname some.host.com
    Port 10002

Host pve3
    Hostname some.host.com
    Port 10003

Backup script

Run this script on the backup server. Change HOSTS, TARGET and NAME for your setup.

For each node, the script makes two backups:

  • rpool/ROOT (the system) to a separate directory per node.
  • rpool/data (the VM and container disks) to one shared directory.
#!/bin/bash

#v1.1: use  --exclude-unchanged instead of --ignore-replicated

HOSTS="pve1 pve2 pve3"
TARGET=rpool/pvebackups
NAME=prox

zfs create -p $TARGET/data &>/dev/null
for HOST in $HOSTS; do

  echo "################################### RPOOL $HOST"

  # enable backup
  ssh $HOST "zfs set autobackup:rpool_$NAME=child rpool/ROOT"

  #backup rpool to specific directory per host
  zfs create -p $TARGET/rpools/$HOST &>/dev/null
  zfs-autobackup --keep-source=1d1w,1w1m --ssh-source $HOST rpool_$NAME $TARGET/rpools/$HOST --clear-mountpoint --clear-refreservation --ignore-transfer-errors --strip-path 2 --verbose   --no-holds   $@

  zabbix-job-status backup_$HOST""_rpool_$NAME daily $? >/dev/null 2>/dev/null


  echo "################################### DATA $HOST"

  # enable backup
  ssh $HOST "zfs set autobackup:data_$NAME=child rpool/data"

  #backup data filesystems to a common directory
  zfs-autobackup --keep-source=1d1w,1w1m --ssh-source $HOST data_$NAME $TARGET/data --clear-mountpoint --clear-refreservation --ignore-transfer-errors --strip-path 2 --verbose   --exclude-unchanged 300000 --no-holds   $@

  zabbix-job-status backup_$HOST""_data_$NAME daily $? >/dev/null 2>/dev/null

done

The script also sends the backup status to Zabbix, if you installed my zabbix-job-status script.

Clone this wiki locally