List all automated snapshots for a given RDS instance in local TZ

 Here is the  script that lists all automated snapshots for a given RDS instance, and includes:


  • Snapshot ID
  • Creation (Start) Time in UTC and AEST/AEDT
  • Snapshot Status
  • Allocated Size (in GiB)






Script: rds_automated_snapshot_details.sh


#!/bin/bash


DB_INSTANCE_ID="$1"


if [ -z "$DB_INSTANCE_ID" ]; then

  echo "Usage: $0 <db-instance-identifier>"

  exit 1

fi


echo "Fetching detailed info for automated snapshots of: $DB_INSTANCE_ID"

echo


SNAPSHOTS=$(aws rds describe-db-snapshots \

  --db-instance-identifier "$DB_INSTANCE_ID" \

  --snapshot-type automated \

  --query "sort_by(DBSnapshots, &SnapshotCreateTime)[].{ID:DBSnapshotIdentifier, Time:SnapshotCreateTime, Status:Status, Size:AllocatedStorage}" \

  --output json)


if [ -z "$SNAPSHOTS" ]; then

  echo "No automated snapshots found."

  exit 0

fi


echo "=== Snapshot Details ==="

printf "%-35s %-25s %-25s %-10s %-6s\n" "Snapshot ID" "UTC Time" "Local (AEST/AEDT)" "Status" "Size"

echo "--------------------------------------------------------------------------------------------------------------"


echo "$SNAPSHOTS" | jq -r '.[] | "\(.ID)\t\(.Time)\t\(.Status)\t\(.Size)"' | while IFS=$'\t' read -r SNAP_ID UTC_TIME STATUS SIZE

do

  LOCAL_TIME=$(TZ="Australia/Melbourne" date -d "$UTC_TIME" "+%Y-%m-%d %H:%M:%S %:z")

  printf "%-35s %-25s %-25s %-10s %-6s\n" "$SNAP_ID" "$UTC_TIME" "$LOCAL_TIME" "$STATUS" "${SIZE}G"

done





Instructions to Use:



  1. Save as: rds_automated_snapshot_details.sh
  2. Make executable:


chmod +x rds_automated_snapshot_details.sh



  1. Run it:


./rds_automated_snapshot_details.sh my-postgres-db






Sample Output:


=== Snapshot Details ===

Snapshot ID                        UTC Time                 Local (AEST/AEDT)        Status     Size  

--------------------------------------------------------------------------------------------------------------

rds:my-postgres-db-2025-05-15-17-30 2025-05-15T17:30:00Z    2025-05-16 03:30:00 +10:00 available 100G

rds:my-postgres-db-2025-05-14-17-30 2025-05-14T17:30:00Z    2025-05-15 03:30:00 +10:00 available 100G



No comments:

Post a Comment