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
".We use essential cookies to make this site work, and optional cookies to enhance your experience.