Automating Amazon EBS snapshots anyone have a good script or solution for this on linux [closed]
Asked Answered
H

5

44

I'd expect this to be fairly routine, but cannot find a simple approach for creating an managing EBS snapshots automatically.

Was hoping there'd be a shceduler in the AWS console.. alas not yet.

Would appreciate any suggestions as to how best to do this on from Ubuntu.

Thanks

Hanan answered 24/8, 2009 at 7:53 Comment(2)
Another excellent question closed as "not constructive"Scenography
Yeah, I don't get it either. So it isn't exactly a great question, but it still has a lot of value. Throwing the baby out with the bath water, if you ask me...Monitor
D
13

You can easily script something to do this for you.

  1. setup the EC2 commandline API tools
  2. set EC2_CERT and EC2_PRIVATE_KEY in order to be able to use the API tools
  3. parse the results of ec2-describe-snapshots
  4. delete the appropriate snapshots

The results look something like:

SNAPSHOT    snap-xxxxxxxx   vol-xxxxxxxx    completed   2009-08-26T07:39:33+0000    100%

You can then do some parsing of the dates and sorting and start removing the older snapshots.

NOTE: I don't know if we can trust the sort order but I've never seen it sort any other way than oldest to newest.

To delete a snapshot, use ec2-delete-snapshot snap-xxxxxxxx.

The rest I leave to you as a simple Bash script that you can call daily or however often you need from cron.

Danadanae answered 7/9, 2009 at 21:46 Comment(1)
One can always use 'sort' to ensure the sort order like: "ec2-describe-snapshots | sort -k 5"Weidman
L
23

Take a look at AWS missing tools and especially to https://github.com/colinbjohnson/aws-missing-tools/tree/master/ec2-automate-backup This does what you need.

Lull answered 26/9, 2012 at 16:9 Comment(0)
D
13

You can easily script something to do this for you.

  1. setup the EC2 commandline API tools
  2. set EC2_CERT and EC2_PRIVATE_KEY in order to be able to use the API tools
  3. parse the results of ec2-describe-snapshots
  4. delete the appropriate snapshots

The results look something like:

SNAPSHOT    snap-xxxxxxxx   vol-xxxxxxxx    completed   2009-08-26T07:39:33+0000    100%

You can then do some parsing of the dates and sorting and start removing the older snapshots.

NOTE: I don't know if we can trust the sort order but I've never seen it sort any other way than oldest to newest.

To delete a snapshot, use ec2-delete-snapshot snap-xxxxxxxx.

The rest I leave to you as a simple Bash script that you can call daily or however often you need from cron.

Danadanae answered 7/9, 2009 at 21:46 Comment(1)
One can always use 'sort' to ensure the sort order like: "ec2-describe-snapshots | sort -k 5"Weidman
N
1

I found this, hope it helps:

ec2-describe-snapshots | sort -r -k 5 | sed 1,6d | awk '{print "Deleting snapshot: " $2}'; system("ec2-delete-snapshot " $2)' 

See: Bulk Delete EBS Snapshots From the Command Line (A Howto).

Nabalas answered 25/9, 2009 at 2:23 Comment(0)
M
1

Shameless plug, but - you can give Ebs2s3 a go: https://github.com/ajmfulcher/ebs2s3

Rails app to automate snapshot creation and prune old snapshots. Introduction and some screenshots here: http://ajmfulcher.blogspot.com/2011/04/ebs2s3-automated-backup-for-amazon-ebs.html

Multifold answered 26/4, 2011 at 0:11 Comment(0)
O
0

A wonderful script to create an automatic snapshots.

https://github.com/rakesh-sankar/Tools/blob/master/AmazonAWS/EBS/EBS-Snapshot.sh

Just copy the code and create a file, then add a cronjob whenever you want it to run.

Ohmage answered 2/6, 2011 at 8:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.