Last active
January 24, 2020 13:02
-
-
Save duboisph/943cb4132866fd6e44cfeba72d81051f to your computer and use it in GitHub Desktop.
Remove K8s EBS snapshots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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