With the current implementation of Proxmox Backup Server the name of the VM itself isn't sent as part of the backup name. So I had an idea of writing a script that can check for new backups and add the VM name to the comment field.
The below bash script uses
The steps are:
Example output of script:
Note in PBS:
To use this script, you will need PBS credentials that are capable of updating notes on the snapshots. I used the root@pam user via an API token.
Script as text:
The below bash script uses
proxmox-backup-client
to check for and update notes on all snapshots of a repository.The steps are:
- List all snapshots
- Iterate list, check if there is an existing note
- If no note, download qemu-server.conf or pct.conf (depending on name being "ct/" or "vm/")
- Parse config file and fetch hostname of backed up server
- Add comment to snapshot
Example output of script:
Note in PBS:
To use this script, you will need PBS credentials that are capable of updating notes on the snapshots. I used the root@pam user via an API token.
Script as text:
Bash:
#!/bin/bash
export PBS_REPOSITORY='root@pam!apitoken@localhost:local'
export PBS_PASSWORD='changeme'
export PROXMOX_OUTPUT_NO_BORDER='.'
export PROXMOX_OUTPUT_NO_HEADER='.'
DEBUG=1
function _debug {
[ $DEBUG == "1" ] || return
echo "[$(date +%Y%m%d-%H%M%S)] ($0): $*"
}
function _error {
echo "[$(date +%Y%m%d-%H%M%S)] ($0) ERROR: $*" 1>&2
}
function _exit {
ec=0
if [ "z$1" != "z" ]; then
ec=$1
shift
fi
if [ "z$1" != "z" ]; then
_error $*
fi
exit ${ec}
}
while read snapshot; do
if [ "z${snapshot}" == "z" ]; then continue; fi
note=$(proxmox-backup-client snapshot notes show ${snapshot})
if [ "z${note}" == "z" ]; then
name=""
if [[ $snapshot == "vm/"* ]]; then
name=$(proxmox-backup-client restore ${snapshot} qemu-server.conf - | awk '/^name: / {print $2}')
elif [[ $snapshot == "ct/"* ]]; then
name=$(proxmox-backup-client restore ${snapshot} pct.conf - | awk '/^hostname: / {print $2}')
fi
if [ "z${name}" == "z" ]; then
_exit 1 "Unable to get name for snapshot ${snapshot}"
fi
_debug "Updating snapshot '${snapshot}' note: ${name}"
proxmox-backup-client snapshot notes update ${snapshot} ${name}
else
_debug "Note already exists for snapshot '${snapshot}'"
fi
done < <(proxmox-backup-client snapshot list | awk '{print $1}')
Last edited: