33 lines
1.3 KiB
Bash
Executable File
33 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
HOST="${1}"
|
|
PORT="${2}"
|
|
TOKENID="${3}@${4}!${5}"
|
|
TOKENSECRET="${6}"
|
|
|
|
datastores=$(wget --header="Authorization: PBSAPIToken=${TOKENID}:${TOKENSECRET}" --content-on-error -q -O - "https://${HOST}:${PORT}/api2/json/admin/datastore")
|
|
|
|
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")
|
|
|
|
for namespace in $(echo "${namespaces}" |jq --raw-output '.data[].ns'); do
|
|
# 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
|
|
done
|
|
|
|
# remove last set comma
|
|
ret="[${backups::-1}]"
|
|
|
|
echo $ret
|