Skip to content

Instantly share code, notes, and snippets.

@duboisph
Last active January 24, 2020 13:02
Show Gist options
  • Save duboisph/943cb4132866fd6e44cfeba72d81051f to your computer and use it in GitHub Desktop.
Save duboisph/943cb4132866fd6e44cfeba72d81051f to your computer and use it in GitHub Desktop.
Remove K8s EBS snapshots
#!/usr/bin/env bash
# $1: Cluster Name
# $2: Date
# $3: --yes
SNAPS=$(aws ec2 describe-snapshots --filter "Name=tag:kubernetes.io/cluster/$1,Values=owned" --query "Snapshots[?StartTime<=\`$2\`].SnapshotId" --output text)
SNAPS_NUMBER=$(wc -w <<< "$SNAPS")
echo "Snapshots to delete: $SNAPS_NUMBER"
if [[ "$3" == "--yes" ]]; then
for SNAP in $SNAPS; do
echo "$SNAP"
aws ec2 delete-snapshot --snapshot-id "$SNAP"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment