diff --git a/docker/src/helper_scripts/list-all-backup-files b/docker/src/helper_scripts/list-all-backup-files new file mode 100644 index 0000000..a602197 --- /dev/null +++ b/docker/src/helper_scripts/list-all-backup-files @@ -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] + } + }' diff --git a/docker/src/helper_scripts/list-all-backups b/docker/src/helper_scripts/list-all-backups new file mode 100644 index 0000000..aa853f4 --- /dev/null +++ b/docker/src/helper_scripts/list-all-backups @@ -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")' diff --git a/docker/src/helper_scripts/list-backup-files b/docker/src/helper_scripts/list-backup-files new file mode 100644 index 0000000..cfab6d0 --- /dev/null +++ b/docker/src/helper_scripts/list-backup-files @@ -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] + } + }'