-
Notifications
You must be signed in to change notification settings - Fork 52
/
aws_ec2_snap_instances.py
45 lines (37 loc) · 1.37 KB
/
aws_ec2_snap_instances.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
# 2015-09-17
# https://github.com/akabdog
####USER_CONFIGURABLE_VARIABLES########
#backup all volumes on all instances which contain this substring in their name tag:
search_name="mysql"
#created snapshots will have this description:
snap_desc="test-deleteme"
####END_CONFIGURABLE_VARIABLES################################
import boto.ec2
def connect ( str ):
conn = boto.ec2.connect_to_region("us-west-1", profile_name = str)
return conn
def getInstanceIds ( con, str ):
a = []
instances = con.get_only_instances()
for instance in instances:
if 'Name' in instance.tags:
if str in instance.tags['Name']:
print instance.tags['Name']
print instance.id
a.append(instance.id)
return a
def snapVolumes ( con, i, desc ):
instances = con.get_only_instances(instance_ids=i)
for instance in instances:
print instance
volumes = con.get_all_volumes(filters={'attachment.instance-id': instance.id})
for volume in volumes:
print volume
volume.create_snapshot(description=desc)
#
# MAIN
#
con=connect("aws-prod")
instances=getInstanceIds(con, search_name)
snapVolumes(con, instances, snap_desc)