Add list-backup helper scripts.

This commit is contained in:
Aterfax 2024-03-29 00:52:35 +00:00
parent d33a3eef6a
commit ace195fa1e
No known key found for this signature in database
GPG Key ID: 51E7ED3290C121FE
3 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,33 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
source /etc/s6-overlay/s6-rc.d/setup_check/run_include
# We need to build this command in case namespaces are in use.
LISTCMD="proxmox-backup-client snapshot list"
if [ -n "$PBS_DATASTORE_NS" ]; then
LISTCMD+=" --ns ${PBS_DATASTORE_NS}"
fi
LISTCMD+=" --output-format json"
data=$(${LISTCMD})
host_name=$(hostname)
echo "$data" | jq -r --arg host "$host_name" '
.[] |
select(.["backup-id"] == $host) |
"\(.["backup-type"])/\($host)/\(.["backup-time"] | tonumber | strftime("%Y-%m-%dT%H:%M:%SZ")): \(.files[].filename)"' |
awk -F ': ' '
{
if (timestamps[$1]) {
timestamps[$1] = timestamps[$1] "\n\t" $2
} else {
timestamps[$1] = "\t" $2
}
}
END {
for (ts in timestamps) {
print ts ":"
print timestamps[ts]
}
}'

View File

@ -0,0 +1,18 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
source /etc/s6-overlay/s6-rc.d/setup_check/run_include
# We need to build this command in case namespaces are in use.
LISTCMD="proxmox-backup-client snapshot list"
if [ -n "$PBS_DATASTORE_NS" ]; then
LISTCMD+=" --ns ${PBS_DATASTORE_NS}"
fi
LISTCMD+=" --output-format json"
data=$(${LISTCMD})
host_name=$(hostname)
echo "${data}" | jq -r --arg host "${host_name}" '
map(select(.["backup-id"] == $host)) |
map("\(.["backup-type"])/\($host)/\(.["backup-time"] | tonumber | strftime("%Y-%m-%dT%H:%M:%SZ")) \(.size / (1024 * 1024) | tostring + " MB" | split(".") | .[0] + "." + .[1][:2] + " MB")") |
join("\n")'

View File

@ -0,0 +1,53 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
source /etc/s6-overlay/s6-rc.d/setup_check/run_include
# We need to build this command in case namespaces are in use.
LISTCMD="proxmox-backup-client snapshot list"
if [ -n "$PBS_DATASTORE_NS" ]; then
LISTCMD+=" --ns ${PBS_DATASTORE_NS}"
fi
LISTCMD+=" --output-format json"
data=$(${LISTCMD})
host_name=$(hostname)
backup_times=($(echo "$data" | jq -r --arg host "$host_name" '
.[] |
select(.["backup-id"] == $host) |
.["backup-time"] | tonumber | strftime("%Y-%m-%dT%H:%M:%SZ")' |
sort | uniq))
# Display numbered list of backup times for selection
echo "Select a backup time:"
for ((i=0; i<${#backup_times[@]}; i++)); do
echo "$((i+1)). ${backup_times[i]}"
done
# Prompt to select a backup time
read -p "Enter the number of the backup you want to select: " selection
# Validate user input
if [[ $selection =~ ^[0-9]+$ && $selection -ge 1 && $selection -le ${#backup_times[@]} ]]; then
# Store selected backup time in a variable
selected_backup_time="${backup_times[$((selection-1))]}"
else
echo "Invalid selection."
exit 1
fi
echo "$data" | jq -r --arg host "$host_name" --arg timestamp "$selected_backup_time" '
.[] |
select(.["backup-id"] == $host and (.["backup-time"] | tonumber | strftime("%Y-%m-%dT%H:%M:%SZ")) == $timestamp) |
"\(.["backup-type"])/\($host)/\($timestamp): \(.files[].filename)"' |
awk -F ': ' '
{
filenames[$1] = filenames[$1] ? filenames[$1] "\n\t" $2 : "\t" $2
}
END {
for (ts in filenames) {
print ts ":"
print filenames[ts]
}
}'