Skip to content

Commit

Permalink
Skip deletion of snapshots in non-terminal state (#1863)
Browse files Browse the repository at this point in the history
Signed-off-by: karishma-chawla <74574173+karishma-chawla@users.noreply.github.com>
Co-authored-by: karishma-chawla <74574173+karishma-chawla@users.noreply.github.com>
  • Loading branch information
kachawla and kachawla authored Oct 9, 2024
1 parent 4b9600b commit 3af0fcf
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions .github/scripts/purge-aws-rds-snapshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@

set -xe

aws rds describe-db-snapshots --query 'DBSnapshots[].DBSnapshotIdentifier' --output text >snapshots.txt
for rds_snapshot_identifier in $(cat ./snapshots.txt); do
aws rds delete-db-snapshot --db-snapshot-identifier $rds_snapshot_identifier
done
# Get the list of snapshots IDs and their states
aws rds describe-db-snapshots --query 'DBSnapshots[*].[DBSnapshotIdentifier,Status]' --output text > snapshots.txt

# Delete snapshots that are in 'available' or 'failed' state
while read -r rds_snapshot_identifier rds_snapshot_status; do
if [[ "$rds_snapshot_status" == "available" || "$rds_snapshot_status" == "failed" ]]; then
echo "Deleting snapshot: $rds_snapshot_identifier"
aws rds delete-db-snapshot --db-snapshot-identifier "$rds_snapshot_identifier"
else
echo "Skipping snapshot $rds_snapshot_identifier (status: $rds_snapshot_status)"
fi
done < snapshots.txt

# Delete the temporary snapshots file
rm snapshots.txt

0 comments on commit 3af0fcf

Please sign in to comment.