From 70009b58b305ee89767146fa81140906a5faf54a Mon Sep 17 00:00:00 2001 From: damage Date: Thu, 2 Apr 2026 16:24:12 +0200 Subject: [PATCH] group backups by datastore, namespace, backup-type and backup-id --- app/proxmox_backup_server/pbs.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/proxmox_backup_server/pbs.sh b/app/proxmox_backup_server/pbs.sh index 3bacb72..2a02d4e 100755 --- a/app/proxmox_backup_server/pbs.sh +++ b/app/proxmox_backup_server/pbs.sh @@ -12,15 +12,21 @@ IFS=' for datastore in $(echo "${datastores}" |jq --raw-output '.data[].store'); do namespaces=$(wget --header="Authorization: PBSAPIToken=${TOKENID}:${TOKENSECRET}" --content-on-error -q -O - "https://${HOST}:${PORT}/api2/json/admin/datastore/${datastore}/namespace") - ret_namespaces="" for namespace in $(echo "${namespaces}" |jq --raw-output '.data[].ns'); do - backups=$(wget --header="Authorization: PBSAPIToken=${TOKENID}:${TOKENSECRET}" --content-on-error -q -O - "https://${HOST}:${PORT}/api2/json/admin/datastore/${datastore}/snapshots?ns=${namespace}") - backups_json=$(echo "${backups}" |jq '.data') - ret_namespaces="${ret_namespaces}{\"${namespace}\":${backups_json}}," + # group backups by backup-type and backup-id, only get the backup of each group (thus the map) with max backup-time and add datastore and namespace to each backup + temp=$(wget --header="Authorization: PBSAPIToken=${TOKENID}:${TOKENSECRET}" --content-on-error -q -O - "https://${HOST}:${PORT}/api2/json/admin/datastore/${datastore}/snapshots?ns=${namespace}" |jq ".data |group_by([.\"backup-type\", .\"backup-id\"]) |map(max_by(\".backup-time\")) |map(.datastore |= \"${datastore}\") |map(.namespace |= \"${namespace}\")") + + # remove array symbols ([ and ]) + temp="${temp:1}" + temp="${temp::-1}" + + if [[ "${#temp}" -ne 0 ]]; then + backups="${backups}${temp}," + fi done - ret_datastores="${ret_datastores}{\"${datastore}\":[${ret_namespaces::-1}]}," done -ret="[${ret_datastores::-1}]" +# remove last set comma +ret="[${backups::-1}]" echo $ret