Automated Proxmox VM Backups via vzdump Saved to an NFS Share
Nobody wants backups! Everyone wants restores!
Yet on my home server, I'm the only admin, so it was my responsibility to finally tackle backups. On my main Proxmox server "BigCube," the local storage for backups is only 100GB, and running several VMs with their own local storage of 100GB each means that even with the best compression, this wouldn't be a viable solution. However, I also have an ever-growing ZFS LXC container running NFS. Here's how I'm storing my VM backups on an NFS share mounted in the Proxmox host:
The Tool: vzdump
The standard tool to back up all your VMs is vzdump.
vzdump's coolest feature is --mode, which supports snapshot | stop | suspend. I have the QEMU guest agent running on all my VMs, which means downtime of less than 0.5 seconds. The agent calls guest-fsfreeze-freeze and guest-fsfreeze-thaw in the guest. This is why I'm using --mode snapshot – it's also the recommended approach.
Setting Up the Storage
First, we have to mount the NFS share somewhere like /mnt/nfs-backups. For me, it looks like this in /etc/fstab:
$ 192.168.178.128:/srv/nfs/shared /mnt/nfs-backups nfs defaults,_netdev 0 0
Now we have to tell Proxmox that this is actually a place where we want to store backups. Proxmox doesn't allow you to store them just anywhere! :D
# Create backup directory on NFS
$ mkdir -p /mnt/nfs-backups/proxmox-backups
# Add as Proxmox storage
$ pvesm add dir nfs-backups --path /mnt/nfs-backups/proxmox-backups --content backup --maxfiles 7
This tells Proxmox to add a storage of the "dir" type named "nfs-backups" at the path we just created (within our NFS). --content backup tells Proxmox that we may only store data from vzdump here (don't want to accidentally save ISOs or VM disks here), and --maxfiles 7 just tells Proxmox to only keep 7 files per VM.
The Backup Scripts
I created 2 files for this: /root/backup-scripts/daily-backup.sh and /root/backup-scripts/weekly-backup.sh
#!/bin/bash
# Daily backup - 7 day retention
vzdump --mode snapshot --compress zstd --storage nfs-backups --maxfiles 7 --exclude 101 --all 1
#!/bin/bash
# Sunday backup - 4 week retention
vzdump --mode snapshot --compress zstd --storage nfs-backups --maxfiles 4 --exclude 101 --all 1
I'm excluding container 101 because that is my 16TB LXC container running the NFS... I don't want a backup of it on itself! :D
Automation with Cron
Now I've just added 2 cron jobs:
# Daily snapshot at 2 AM (Monday-Saturday)
0 2 * * 1-6 /root/backup-scripts/daily-backup.sh
# Sunday snapshot at 2 AM (kept for 4 weeks)
0 2 * * 0 /root/backup-scripts/weekly-backup.sh
And that was it – pretty simple!
Also, don't worry if you have the NFS share mounted to other VMs while running the backup. By default, additional mount points besides the root disk mount point are not included in backups. For a setup similar to mine, the VM storage itself is not part of the NFS share, so it wouldn't even be part of the VM's "block device."