Skip to content

Instantly share code, notes, and snippets.

@pmoranga
Created March 19, 2014 12:41
Show Gist options
  • Save pmoranga/9640867 to your computer and use it in GitHub Desktop.
Save pmoranga/9640867 to your computer and use it in GitHub Desktop.
Create EC2 snapshot from all volumes connected in the VM itself.
#!/usr/bin/python
from boto.ec2.connection import EC2Connection
from boto.utils import get_instance_metadata
from datetime import datetime
import sys
conn = EC2Connection('AUTH_KEY', 'SECRET_KEY')
description = 'Created by crontab at ' + datetime.today().isoformat(' ')
m = get_instance_metadata()
volumes = [v for v in conn.get_all_volumes() if v.attach_data.instance_id == m['instance-id']]
for v in volumes :
snapshot = conn.create_snapshot( v.id ,description)
print "Snapshot of %s triggered" % v.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment