Skip to content

Instantly share code, notes, and snippets.

@mokkabonna
Created February 28, 2014 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokkabonna/9266784 to your computer and use it in GitHub Desktop.
Save mokkabonna/9266784 to your computer and use it in GitHub Desktop.
Daily automatic backup/snapshots and purging for EC2 volumes
#!/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