#!/bin/bash
set -Eeuo pipefail
set -a
source /etc/pbs-client/env
set +a
HOSTNAME_SHORT="$(hostname -s)"
PATHS=()
{% for path in pbs_backup_paths %}
PATHS+=( "{{ path }}" )
{% endfor %}
ARGS=()
for dest in "${PATHS[@]}"; do
# The 'archive-name' must only contain alphanumerics, hyphens and
# underscores.
name=$(basename "$dest" | sed 's/[^A-Za-z0-9_-]/_/g')
# Determination of data type. References:
# https://forum.proxmox.com/threads/proxmox-backup-client-only-one-file.104437/
# https://pbs.proxmox.com/docs/backup-client.html#creating-backups
# https://pbs.proxmox.com/docs/command-syntax.html#proxmox-backup-client
# https://pbs.proxmox.com/docs/terminology.html
if ! [ -e "$dest" ]; then
echo "Warning: $dest does not exist, skipping" >&2
continue
elif [ -d "$dest" ]; then
# pxar: Proxmox File Archive Format (stores a full directory tree)
type="pxar"
elif [ -f "$dest" ]; then
size=$(stat -c%s "$dest")
if [ "$size" -lt $((16 * 1024 * 1024)) ]; then
# conf/log: smaller (< 16MB) binary data (eg: config/log files)
# we trim the suffix, if possible, to avoid *_conf.conf and *_log.log in the server
if [[ $dest == *.log ]]; then
if [[ $name != _log ]]; then
name=${name%_log}
fi
type="log"
else
if [[ $dest == *.conf && $name != _conf ]]; then
name=${name%_conf}
fi
type="conf"
fi
else
# over 16MB, docs don't recommend blob
type="img"
fi
elif [ -b "$dest" ]; then
# img: image archive (VM images and other large binary data)
type="img"
else
echo "Error: $dest is unknown path type" >&2
exit 1
fi
ARGS+=("${name}.${type}:${dest}")
done
proxmox-backup-client backup \
"${ARGS[@]}" \
--backup-id "${HOSTNAME_SHORT}"