Tag Snapshot using Backup_Monkey

14 / Apr / 2014 by Vikash Jha 0 comments

In continuation with my previous article EBS Snapshot using Backup_Monkey, we have discussed one issue associated with BackUp Monkey utility.

The issue was that it use’s “BACKUP_MONKEY” prefix and tag the snapshot with this prefix.

As you can see in the Description, BACKUP_MONKEY prefix is used. So this create’s a redundancy while finding the exact snapshot, as every snapshot is tagged with this same format. But we want a snapshot with the name same as “Instance Name” so that we can identify the snapshot easily. To do so we have to modify the source code.
backup-monkey command uses /usr/local/lib/python27/dist-packages/backup_monkey/core.py

File to be modified: /usr/local/lib/python27/dist-packages/backup_monkey/core.py

Locate line number 29 and comment it out

and Replace it with

self.conn.get_all_instances() will return all instances Reservation id

Now, Replace original code in “core.py” with this following code.

48 i=0
49 for volume in volumes:
51 #     description_parts = [self._prefix] //Comment this line
52     description_parts=[self._prefix[i].instances[0].tags['Name']]
53     i=i+1
54     description_parts.append(volume.id)
55     if volume.attach_data.instance_id:
56         description_parts.append(volume.attach_data.instance_id)
57     if volume.attach_data.device:
58         description_parts.append(volume.attach_data.device)
59     description = ' '.join(description_parts)
60     log.info('Creating snapshot of %s: %s', volume.id, description)
61     volume.create_snapshot(description)
62     return True

We added this line


This is basically extracting the Tag Name associated with the Reservation Id extracted above.

Next part is to modify the remove_old_snapshots() section.

Below code is used for removing snapshots with the extracted Tag Name.

73 j=0
74 for snapshot in snapshots:
75 #    if not snapshot.description.startswith(self._prefix):
76      if not snapshot.description.startswith(self._prefix[j].instances[0].tags['Name']):
77         log.debug('Skipping %s as prefix does not match', snapshot.id)
78     continue
79     if not snapshot.status == 'completed':
80         log.debug('Skipping %s as it is not a complete snapshot', snapshot.id)
81     continue
82     j=j+1

We are done with the modification. Lets Test it out.

This is my Instance with Tag Name “Testing Instance”.

Lets run
$backup-monkey --region us-west-2

Now you can see below the difference between the two snapshot. One with “BACKUP_MONKEY” which was the previous one, other with “Testing Instance” name

References: backup-monkey source code


Tag -

EBS python

Leave a Reply

Your email address will not be published. Required fields are marked *