Created
February 28, 2014 07:24
-
-
Save mokkabonna/9266784 to your computer and use it in GitHub Desktop.
Daily automatic backup/snapshots and purging for EC2 volumes
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
#!/bin/bash | |
#create snapshots of all volumes | |
aws ec2 describe-volumes | grep VOLUMES | cut -f 7 | while read volumeid; do aws ec2 create-snapshot --volume-id=$volumeid --description="daily-for-automatical-deletion" ; done | |
#delete all but the last 35 (if 5 volumes, this is keeping the daily automatic backups for the last 7 days) | |
aws ec2 describe-snapshots --owner-id=<insert-owner-id> --filters Name=description,Values="*for-automatical-deletion" | grep SNAPSHOTS | sort -r -k 6 | sed -n 35,1000p | cut -f 5 | while read snapshotid; do aws ec2 delete-snapshot --snapshot-id=$snapshotid; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment