2024-09-18 16:53:20 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2025-01-07 14:31:03 +00:00
|
|
|
# Exit immediately on error
|
|
|
|
set -e
|
|
|
|
|
2024-09-18 16:53:20 +00:00
|
|
|
# Display usage if no tag is provided
|
|
|
|
if [ "$#" -ne 1 ]; then
|
|
|
|
echo "Usage: $0 <tag>"
|
|
|
|
echo "Available tags: main_backup, wordpress_db, core_files, media_themes, full_backup"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2025-01-07 14:31:03 +00:00
|
|
|
# Assign input argument
|
2024-09-18 16:53:20 +00:00
|
|
|
TAG=$1
|
|
|
|
backupPath='/mnt/backups'
|
2025-01-07 14:31:03 +00:00
|
|
|
password_file="/etc/restic-password" # Use a password file instead of embedding the password
|
2024-09-18 16:53:20 +00:00
|
|
|
|
2025-01-07 14:31:03 +00:00
|
|
|
# Validate if the password file exists
|
|
|
|
if [ ! -f "$password_file" ]; then
|
|
|
|
echo "Error: Password file not found at $password_file"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-09-18 16:53:20 +00:00
|
|
|
|
2025-01-07 14:31:03 +00:00
|
|
|
# Set Restic environment variables
|
2024-09-18 16:53:20 +00:00
|
|
|
export RESTIC_REPOSITORY="$backupPath"
|
2025-01-07 14:31:03 +00:00
|
|
|
export RESTIC_PASSWORD=$(cat "$password_file")
|
2024-09-18 16:53:20 +00:00
|
|
|
|
|
|
|
# Validate the provided tag against known tags
|
|
|
|
case "$TAG" in
|
|
|
|
main_backup|wordpress_db|core_files|media_themes|full_backup)
|
|
|
|
# Use the --json flag to output the snapshots in JSON format
|
2025-01-07 14:31:03 +00:00
|
|
|
if restic -r "$RESTIC_REPOSITORY" snapshots --tag "$TAG" --json; then
|
|
|
|
echo "Snapshots for tag '$TAG' displayed successfully."
|
|
|
|
else
|
|
|
|
echo "Error: Unable to display snapshots for tag '$TAG'."
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-09-18 16:53:20 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Error: Unknown tag '$TAG'."
|
|
|
|
echo "Available tags: main_backup, wordpress_db, core_files, media_themes, full_backup"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|