mirror of
https://github.com/edv-pi/pbs-client-docker.git
synced 2025-04-16 19:42:55 +02:00
Add list-backup helper scripts.
This commit is contained in:
parent
d33a3eef6a
commit
ace195fa1e
33
docker/src/helper_scripts/list-all-backup-files
Normal file
33
docker/src/helper_scripts/list-all-backup-files
Normal 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]
|
||||
}
|
||||
}'
|
18
docker/src/helper_scripts/list-all-backups
Normal file
18
docker/src/helper_scripts/list-all-backups
Normal 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")'
|
53
docker/src/helper_scripts/list-backup-files
Normal file
53
docker/src/helper_scripts/list-backup-files
Normal 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]
|
||||
}
|
||||
}'
|
Loading…
Reference in New Issue
Block a user