I am already using PBS to backup the VMs and CTs, and it's working great, I am looking for an option to backup the PVE Host to PBS as well, what is the right way to do it? Or should I look for a different option?
Thanks
#!/bin/bash
# Configure where to store the backup and what to exclude, as it changes
# regularly and only contains emphemeral data.
pbspasswd="/etc/pbs-passwd"
pbshost="pbs.lan"
pbsns="pve-host"
pbsvol="pve-sys"
exclude=( '/dev/shm' '/tmp' '/run' '/var/cache' '/var/lib/rrdcached'
'/var/tmp' '/var/lib/vz#' '/var/log#' )
# Convert the list of exclusions into command line arguments for the PBS
# client. Treat directories like /var/log special, as we want to keep some
# of the directory structure and permissions in the backup, but want to
# discard all of the actual data.
exdirs=
for ex in "${exclude[@]}"; do
exdirs="${exdirs} --exclude ${ex%#}/?*"
[ "${ex%#}" != "${ex}" ] &&
exdirs="${exdirs} --exclude ${ex%#}/**/?* --exclude !${ex%#}/**/"
done
# Take advantage of ZFS to create an atomic snapshot for backing up.
# We keep this snapshot around afterwards, as it is useful for quickly
# repairing accidentally damaged systems.
root="$(zfs list / | awk 'NR==2{ print $1 }')"
zfs destroy "${root}@backup" >&/dev/null || :
zfs snapshot "${root}@backup"
[ -d "/.zfs/snapshot/" ] || zfs set snapdir=visible "${root}"
# The credentials for accessing the PBS server should be stored in
# /etc/pbs-passwd
export PBS_REPOSITORY="$(sed -n 2p <"${pbspasswd}")@${pbshost}:${pbsvol}"
export PBS_PASSWORD_FILE="${pbspasswd}"
# Create a new namespace if it doesn't exist yet, then backup our snapshot
# to the PBS server. Exclude ephemeral data, as it just fills up the server
# and likely won't deduplicate well.
proxmox-backup-client namespace list 2>/dev/null | egrep "^${pbsns}$" >/dev/null ||
proxmox-backup-client namespace create "${pbsns}"
(set -f
proxmox-backup-client backup "proxmox-root.pxar:/.zfs/snapshot/backup" --ns "${pbsns}" \
--change-detection-mode=metadata ${exdirs})
#!/bin/bash
if [ -f /etc/pve/local/pve-backup.env ] ; then
source /etc/pve/local/pve-backup.env
else
echo "File /etc/pve/local/pve-backup.env missing" > /dev/stderr
exit 1
fi
/usr/bin/proxmox-backup-client backup root.pxar:/ \
--crypt-mode encrypt \
--keyfile /etc/pve/pve-backup.json \
--exclude /bin \
--exclude /boot \
--exclude /dev \
--exclude /lib \
--exclude /lib64 \
--exclude /local-zfs \
--exclude /lost+found \
--exclude /mnt \
--exclude /opt \
--exclude /proc \
--exclude /run \
--exclude /sbin \
--exclude /sys \
--exclude /tmp \
--exclude /usr \
--exclude /var/lib/lxcfs \
--include-dev /etc/pve \
--backup-type host \
--skip-lost-and-found
/usr/local/sbin/pve-backup.sh and executed by cron daily. The referenced file /etc/pve/local/pve-backup.env is a simple key/value file, containing the Proxmox node specifics. That way I can use the same script on all my PVE nodes unchanged, while only having to adjust the host specific configuration in /etc/pve/local/pve-backup.env .export PBS_REPOSITORY=<API TOKEN USER>!<API TOKEN NAME>@<PBS HOST>:<DATASTORE>
export PBS_PASSWORD=<API TOKEN>
export PBS_FINGERPRINT=<PBS HOST FINGERPRINT>
/etc/pve/pve-backup.json. If you don't use encryption, simply remove the lines "--crypt-mode" and "--keyfile".Thanks, backup works just fine. But what is the method to restore such a backup ?Here's the script that I am currently using, it focusses on backing up the host configuration, not the payload (VMs, CT, etc.).
Bash:#!/bin/bash if [ -f /etc/pve/local/pve-backup.env ] ; then source /etc/pve/local/pve-backup.env else echo "File /etc/pve/local/pve-backup.env missing" > /dev/stderr exit 1 fi /usr/bin/proxmox-backup-client backup root.pxar:/ \ --crypt-mode encrypt \ --keyfile /etc/pve/pve-backup.json \ --exclude /bin \ --exclude /boot \ --exclude /dev \ --exclude /lib \ --exclude /lib64 \ --exclude /local-zfs \ --exclude /lost+found \ --exclude /mnt \ --exclude /opt \ --exclude /proc \ --exclude /run \ --exclude /sbin \ --exclude /sys \ --exclude /tmp \ --exclude /usr \ --exclude /var/lib/lxcfs \ --include-dev /etc/pve \ --backup-type host \ --skip-lost-and-found
The file is located at/usr/local/sbin/pve-backup.shand executed by cron daily. The referenced file/etc/pve/local/pve-backup.envis a simple key/value file, containing the Proxmox node specifics. That way I can use the same script on all my PVE nodes unchanged, while only having to adjust the host specific configuration in/etc/pve/local/pve-backup.env.
Content of that file:
Bash:export PBS_REPOSITORY=<API TOKEN USER>!<API TOKEN NAME>@<PBS HOST>:<DATASTORE> export PBS_PASSWORD=<API TOKEN> export PBS_FINGERPRINT=<PBS HOST FINGERPRINT>
Also, since I use encrypted backups, the encryption key (file) needs to be saved as/etc/pve/pve-backup.json. If you don't use encryption, simply remove the lines "--crypt-mode" and "--keyfile".
couple edits and this worked great for me.Here's the script that I am currently using, it focusses on backing up the host configuration, not the payload (VMs, CT, etc.).
Bash:#!/bin/bash if [ -f /etc/pve/local/pve-backup.env ] ; then source /etc/pve/local/pve-backup.env else echo "File /etc/pve/local/pve-backup.env missing" > /dev/stderr exit 1 fi /usr/bin/proxmox-backup-client backup root.pxar:/ \ --crypt-mode encrypt \ --keyfile /etc/pve/pve-backup.json \ --exclude /bin \ --exclude /boot \ --exclude /dev \ --exclude /lib \ --exclude /lib64 \ --exclude /local-zfs \ --exclude /lost+found \ --exclude /mnt \ --exclude /opt \ --exclude /proc \ --exclude /run \ --exclude /sbin \ --exclude /sys \ --exclude /tmp \ --exclude /usr \ --exclude /var/lib/lxcfs \ --include-dev /etc/pve \ --backup-type host \ --skip-lost-and-found
The file is located at/usr/local/sbin/pve-backup.shand executed by cron daily. The referenced file/etc/pve/local/pve-backup.envis a simple key/value file, containing the Proxmox node specifics. That way I can use the same script on all my PVE nodes unchanged, while only having to adjust the host specific configuration in/etc/pve/local/pve-backup.env.
Content of that file:
Bash:export PBS_REPOSITORY=<API TOKEN USER>!<API TOKEN NAME>@<PBS HOST>:<DATASTORE> export PBS_PASSWORD=<API TOKEN> export PBS_FINGERPRINT=<PBS HOST FINGERPRINT>
Also, since I use encrypted backups, the encryption key (file) needs to be saved as/etc/pve/pve-backup.json. If you don't use encryption, simply remove the lines "--crypt-mode" and "--keyfile".
#!/bin/bash
if [ -f ~/backup.env ] ; then
source ~/backup.env
else
echo "File ~/backup.env missing" > /dev/stderr
exit 1
fi
/usr/bin/proxmox-backup-client backup root.pxar:/ \
--exclude /bin \
--exclude /boot \
--exclude /dev \
--exclude /lib \
--exclude /lib64 \
--exclude /local-zfs \
--exclude /lost+found \
--exclude /mnt \
--exclude /opt \
--exclude /proc \
--exclude /run \
--exclude /sbin \
--exclude /sys \
--exclude /tmp \
--exclude /zstor \
--exclude /usr \
--exclude /var/lib/lxcfs \
--include-dev /etc/pve \
--backup-type host \
--skip-lost-and-found
Restoring is more complex, depends a lot more on the specifics of your situation, and that's most likely the reason why Proxmox doesn't officially have any support for backing up the host. It's not that it's difficult per se. But it's difficult to come up with a solution that works for everyone each and every time.
I would imagine that it would be best if it worked a bit like in Home Assistant or the Ubiquiti hardware. The idea would be that you do a clean Proxmox install on a machine and then you get an option to either use it directly or to initialize it from a backup. That process could check if your hardware is compatible with the backup (enough storage for thze pools and such) and would only let you proceed if a restore is possible,
This might not be super helpful when restoring on a totally different system, but it would catch the typical scenario where you need to reinstall on the same hardware for some reason. And given how homogenous server farms often are, it would probably be better than nothing at all even for other scenarios.
We use essential cookies to make this site work, and optional cookies to enhance your experience.