Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit d819d50

Browse files
author
Chris Machler
committed
This fixes issue #1, adding seperate collection for mount point tags.
1 parent 9720340 commit d819d50

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lambda-ebs-backup.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def lambda_handler(event, context):
2121

2222
print "Found %d instances that need backing up" % len(instances)
2323

24-
to_tag = collections.defaultdict(list)
24+
to_tag_retention = collections.defaultdict(list)
25+
to_tag_mount_point = collections.defaultdict(list)
2526

2627
for instance in instances:
2728
try:
@@ -43,9 +44,10 @@ def lambda_handler(event, context):
4344
VolumeId=vol_id,
4445
Description=instance['InstanceId'],
4546
)
46-
47-
to_tag[retention_days].append(snap['SnapshotId'])
48-
47+
48+
to_tag_retention[retention_days].append(snap['SnapshotId'])
49+
to_tag_mount_point[vol_id].append(snap['SnapshotId'])
50+
4951

5052
print "Retaining snapshot %s of volume %s from instance %s for %d days" % (
5153
snap['SnapshotId'],
@@ -55,20 +57,19 @@ def lambda_handler(event, context):
5557
)
5658

5759
ec.create_tags(
58-
Resources=to_tag[retention_days],
60+
Resources=to_tag_mount_point[vol_id],
5961
Tags=[
6062
{'Key': 'Name', 'Value': dev_attachment},
6163
]
6264
)
6365

64-
for retention_days in to_tag.keys():
66+
for retention_days in to_tag_retention.keys():
6567
delete_date = datetime.date.today() + datetime.timedelta(days=retention_days)
6668
delete_fmt = delete_date.strftime('%Y-%m-%d')
67-
print "Will delete %d snapshots on %s" % (len(to_tag[retention_days]), delete_fmt)
69+
print "Will delete %d snapshots on %s" % (len(to_tag_retention[retention_days]), delete_fmt)
6870
ec.create_tags(
69-
Resources=to_tag[retention_days],
71+
Resources=to_tag_retention[retention_days],
7072
Tags=[
7173
{'Key': 'DeleteOn', 'Value': delete_fmt},
7274
]
7375
)
74-

0 commit comments

Comments
 (0)