group backups by datastore, namespace, backup-type and backup-id
This commit is contained in:
@@ -12,15 +12,21 @@ IFS='
|
|||||||
for datastore in $(echo "${datastores}" |jq --raw-output '.data[].store'); do
|
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")
|
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
|
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}")
|
# 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
|
||||||
backups_json=$(echo "${backups}" |jq '.data')
|
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}\")")
|
||||||
ret_namespaces="${ret_namespaces}{\"${namespace}\":${backups_json}},"
|
|
||||||
|
# remove array symbols ([ and ])
|
||||||
|
temp="${temp:1}"
|
||||||
|
temp="${temp::-1}"
|
||||||
|
|
||||||
|
if [[ "${#temp}" -ne 0 ]]; then
|
||||||
|
backups="${backups}${temp},"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
ret_datastores="${ret_datastores}{\"${datastore}\":[${ret_namespaces::-1}]},"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
ret="[${ret_datastores::-1}]"
|
# remove last set comma
|
||||||
|
ret="[${backups::-1}]"
|
||||||
|
|
||||||
echo $ret
|
echo $ret
|
||||||
|
|||||||
Reference in New Issue
Block a user