Skip to content

Instantly share code, notes, and snippets.

@pmoranga
Last active August 29, 2015 14:09
Show Gist options
  • Save pmoranga/d6f79765789a28502cd5 to your computer and use it in GitHub Desktop.
Save pmoranga/d6f79765789a28502cd5 to your computer and use it in GitHub Desktop.
AWS - EC2 - Create snapshot from all volumes attached to host. also notify deadmanssnitch.com about the procedure replace xxxxxxxxxxx, yyyyyyyyyyyy and zzzzzzzzzz with appropriate values
#!/usr/bin/python
from boto.ec2.connection import EC2Connection
from boto.utils import get_instance_metadata
from datetime import datetime
import sys
conn = EC2Connection('xxxxxxxxxxxx', 'yyyyyyyyyyyyyyy')
hostname = socket.gethostname()
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 ,'CronBKP '+ datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') + ' - '+ hostname + ':' + os.path.basename(v.attach_data.device) + ' ' )
print "Snapshot of %s triggered" % v.id
import urllib2
import urllib
url='https://nosnch.in/zzzzzzzzzzzz'
res = urllib2.urlopen(url, urllib.urlencode({'m': 'snaps done'}) )
print res.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment