💾Proxmox Backup

How to setup an automated proxmox backup system (host config + LXCs). With this you'll be able to get your server up and running in a few minutes from scratch.

We'll need to backup 2 things:

  • Proxmox host config (/etc)

  • LXCs/VMs (using Proxmox Backup Server)

Prerequisites

  • Having an external backup location (backup on same drive is useless), can be a ZFS pool, a network drive (NFS,SMB...), or another physical server but for this tutorial we'll set up PBS inside an LXC and back up on a ZFS "backup" dataset.

1

Setting up PBS

We'll need PBS to backup both host config and LXCs/VMs.

  • Pros: deduplication, incremental (fast, light)

  • Cons: adds another LXC that consumes ressources (not much but around 200~ RAM) but I have a solution for that

Install PBS

  1. Just use this scriptarrow-up-right to add PBS LXC (during installation, select PRIVILEGED LXC, it will be easier)

  2. I recommend you then run PBS Post-Install Scriptarrow-up-right in PBS LXC Console.

  3. set root password passwd root

Configuring PBS

  1. Add bind mount to ZFS in PBS LXC, refer to Bind Mount Dataset to LXC, you don't need to handle the uid/gid part because PBS is Privileged LXC

  2. login to PBS ip:8007 (using root and the password you set in the previous step)

  3. Create new datastore with "Backing Path" to our ZFS dataset bind mount

  4. (optionnal) options > check verify new snapshots

  5. (optionnal) Create a dedicated backup user on PBS with user permissions: /datastore, role: DatastoreAdmin

Video tutorial:

(Optionnal) Auto PBS start/shutdown

circle-check

On PVE:

Starts PBS 1m before scheduled backup job:

59 20 * * * /usr/sbin/pct start 105 >> /var/log/pbs-autostart.log 2>&1
circle-exclamation

On PBS LXC:

Copy, paste this script in PBS LXC Shell, it will create a systemd service that will automatically shutdown 5m after the last backup/prune jobs:

#!/bin/bash
apt update > /dev/null 2>&1 && apt install -y jq > /dev/null 2>&1

echo \"Création du script de vérification...\"
cat > /usr/local/sbin/pbs-auto-shutdown.sh <<'EOF'
#!/bin/bash
RUNNING_TASKS=$(proxmox-backup-manager task list --output-format json | jq 'length')

if [ "$RUNNING_TASKS" -eq 0 ]; then
    echo "$(date): Aucune tâche PBS. Attente de 2 minutes..."
    sleep 120
    RUNNING_TASKS=$(proxmox-backup-manager task list --output-format json | jq 'length')
    
    if [ "$RUNNING_TASKS" -eq 0 ]; then
        echo "$(date): Extinction sécurisée."
        shutdown now
    else
        echo "$(date): Tâche apparue. Surveillance continue."
    fi
else
    echo "$(date): Tâches en cours détectées ($RUNNING_TASKS). Le LXC reste allumé."
fi
EOF

chmod +x /usr/local/sbin/pbs-auto-shutdown.sh

cat > /etc/systemd/system/pbs-auto-shutdown.service <<EOF
[Unit]
Description=Proxmox Backup Server Auto Shutdown Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/sbin/pbs-auto-shutdown.sh
EOF

cat > /etc/systemd/system/pbs-auto-shutdown.timer <<EOF
[Unit]
Description=Run PBS Auto Shutdown Service every 5 minutes

[Timer]
OnBootSec=1min
OnUnitActiveSec=5min

[Install]
WantedBy=timers.target
EOF

# Démarrage du service d'arrêt dans le LXC
systemctl daemon-reload
systemctl enable --now pbs-auto-shutdown.timer

echo "✅ Service d'arrêt sécurisé configuré dans le LXC."

useful link if your PBS is on another server:

2

Proxmox Host backup

replace --repository and PBS_PASSWORD according to your PBS config and execute this once manually just to accept the fingerpint.

PBS_PASSWORD='root_password' /usr/bin/proxmox-backup-client backup \
    root.pxar:/etc \
    --repository root@pam@192.168.1.105:backup \
    --backup-id $(hostname)

Then, add it to pve crontab, open pve shell > crontab -e:

00 21 * * * PBS_PASSWORD='root_password' /usr/bin/proxmox-backup-client backup root.pxar:/etc --repository root@pam@192.168.1.105:backup --backup-id $(hostname) >/dev/null 2>&1

Manual

For manual /etc backup, you can just use this scriptarrow-up-right

3

LXCs/VMs Backup

  1. back in PVE, datacenter > storage > add PBS (use the newly created user, you can get fingerprint from previous step or by running this command in PBS LXC shell or in just get it in PBS UI (see video).

proxmox-backup-manager cert info | grep Fingerprint | cut -d ' ' -f 3
  1. create backup job (with PBS as storage)

Video tutorial:

Restore method

circle-info

Since we used PBS on the same server we still need to set up PBS again, which is the only downside I see to this approach. Though this is pretty easy and quick.

  1. Re-install PVE from ISO

  2. Import existing ZFS pool

zpool import -f pool_name
circle-exclamation

You can restore PBS like this:

pct restore 999 /your_zfs_pool/datastore/ct/ID-LXC/DATE/index.json.fidx --storage local-lvm

or you can recreate it and its Datastore manually Setting up PBS

  1. Restore PBS Backup from PBS GUI

Last updated