#!/bin/bash # Exit immediately on error set -e # Display usage if no tag is provided if [ "$#" -ne 1 ]; then echo "Usage: $0 " echo "Available tags: main_backup, wordpress_db, core_files, media_themes, full_backup" exit 1 fi # Assign input argument TAG=$1 backupPath='/mnt/backups' password_file="/etc/restic-password" # Use a password file instead of embedding the password # Validate if the password file exists if [ ! -f "$password_file" ]; then echo "Error: Password file not found at $password_file" exit 1 fi # Set Restic environment variables export RESTIC_REPOSITORY="$backupPath" export RESTIC_PASSWORD=$(cat "$password_file") # 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 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 ;; *) echo "Error: Unknown tag '$TAG'." echo "Available tags: main_backup, wordpress_db, core_files, media_themes, full_backup" exit 1 ;; esac