{"id":12904,"date":"2014-04-14T11:02:51","date_gmt":"2014-04-14T05:32:51","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=12904"},"modified":"2014-04-14T11:02:51","modified_gmt":"2014-04-14T05:32:51","slug":"tag-snapshot-using-backup_monkey","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/tag-snapshot-using-backup_monkey\/","title":{"rendered":"Tag Snapshot using Backup_Monkey"},"content":{"rendered":"<div style=\"width: 700px\">\n<p style=\"text-align: justify\">In continuation with my previous article <a title=\"EBS Snapshot using Backup_Monkey\" href=\"http:\/\/www.tothenew.com\/blog\/ebs-snaphost-using-backup_monkey\/\">EBS Snapshot using Backup_Monkey<\/a>, we have discussed one issue associated with BackUp Monkey utility.<\/p>\n<p style=\"text-align: justify\"><em>The issue was that it use&#8217;s &#8220;BACKUP_MONKEY&#8221; prefix and tag the snapshot with this prefix.<\/em><\/p>\n<p style=\"text-align: justify\"><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/04\/backup4.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-12906\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/04\/backup4.png\" alt=\"\" width=\"600\" height=\"100\" \/><\/a><\/p>\n<p style=\"text-align: justify\">As you can see in the Description, BACKUP_MONKEY prefix is used. So this create&#8217;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 &#8220;Instance Name&#8221; so that we can identify the snapshot easily. To do so we have to modify the source code.<br \/>\n<code><span class=\"GINGER_SOFTWARE_mark\">backup<\/span>-monkey<\/code> command uses <strong>\/usr\/local\/lib\/python27\/<span class=\"GINGER_SOFTWARE_mark\">dist<\/span>-packages\/backup_monkey\/core<span class=\"GINGER_SOFTWARE_mark\">.<\/span><span class=\"GINGER_SOFTWARE_mark\">py<\/span><\/strong><\/p>\n<p style=\"text-align: justify\"><span class=\"GINGER_SOFTWARE_mark\">File<\/span> to be modified: \/usr\/local\/lib\/python27\/<span class=\"GINGER_SOFTWARE_mark\">dist<\/span>-packages\/backup_monkey\/core<span class=\"GINGER_SOFTWARE_mark\">.<\/span><span class=\"GINGER_SOFTWARE_mark\">py<\/span><\/p>\n<p style=\"text-align: justify\">Locate line number 29 and comment it out<br \/>\n<code><span class=\"GINGER_SOFTWARE_mark\">self<\/span><span class=\"GINGER_SOFTWARE_mark\">.<\/span>_prefix='BACKUP_MONKEY' <\/code><\/p>\n<p style=\"text-align: justify\"><span class=\"GINGER_SOFTWARE_mark\">and<\/span> Replace it with<br \/>\n<code><span class=\"GINGER_SOFTWARE_mark\">self<\/span><span class=\"GINGER_SOFTWARE_mark\">.<\/span>_prefix=self<span class=\"GINGER_SOFTWARE_mark\">.<\/span>_conn<span class=\"GINGER_SOFTWARE_mark\">.<\/span>get_all_instances<span class=\"GINGER_SOFTWARE_mark\">(<\/span>) <\/code><\/p>\n<p style=\"text-align: justify\"><strong><span class=\"GINGER_SOFTWARE_mark\">self<\/span><span class=\"GINGER_SOFTWARE_mark\">.<\/span>conn<span class=\"GINGER_SOFTWARE_mark\">.<\/span>get_all_instances<span class=\"GINGER_SOFTWARE_mark\">(<\/span>) will return all instances Reservation id<\/strong><\/p>\n<p style=\"text-align: justify\">Now, Replace <span class=\"GINGER_SOFTWARE_mark\">original code<\/span> in &#8220;core<span class=\"GINGER_SOFTWARE_mark\">.<\/span><span class=\"GINGER_SOFTWARE_mark\">py<\/span>&#8221; with this following code.<br \/>\n<code><br \/>\n48 i=0<br \/>\n49 for volume in volumes:<br \/>\n50<br \/>\n51 # \u00a0\u00a0\u00a0\u00a0description_parts = [self<span class=\"GINGER_SOFTWARE_mark\">.<\/span>_prefix] \/\/Comment this line<br \/>\n52 \u00a0\u00a0\u00a0\u00a0description_parts=<span class=\"GINGER_SOFTWARE_mark\">[<\/span>self<span class=\"GINGER_SOFTWARE_mark\">.<\/span>_prefix<span class=\"GINGER_SOFTWARE_mark\">[<\/span><span class=\"GINGER_SOFTWARE_mark\">i<\/span>]<span class=\"GINGER_SOFTWARE_mark\">.<\/span>instances<span class=\"GINGER_SOFTWARE_mark\">[<\/span>0]<span class=\"GINGER_SOFTWARE_mark\">.<\/span>tags<span class=\"GINGER_SOFTWARE_mark\">[<\/span>'Name']]<br \/>\n53 \u00a0\u00a0\u00a0\u00a0i=i+1<br \/>\n54 \u00a0\u00a0\u00a0\u00a0description_parts<span class=\"GINGER_SOFTWARE_mark\">.<\/span>append<span class=\"GINGER_SOFTWARE_mark\">(<\/span>volume<span class=\"GINGER_SOFTWARE_mark\">.<\/span>id)<br \/>\n55 \u00a0\u00a0\u00a0\u00a0if volume<span class=\"GINGER_SOFTWARE_mark\">.<\/span>attach_data<span class=\"GINGER_SOFTWARE_mark\">.<\/span>instance_id:<br \/>\n56 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0description_parts<span class=\"GINGER_SOFTWARE_mark\">.<\/span>append<span class=\"GINGER_SOFTWARE_mark\">(<\/span>volume<span class=\"GINGER_SOFTWARE_mark\">.<\/span>attach_data<span class=\"GINGER_SOFTWARE_mark\">.<\/span>instance_id)<br \/>\n57 \u00a0\u00a0\u00a0\u00a0if volume.attach_data.device:<br \/>\n58 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0description_parts.append(volume.attach_data.device)<br \/>\n59 \u00a0\u00a0\u00a0\u00a0description = ' '<span class=\"GINGER_SOFTWARE_mark\">.<\/span>join<span class=\"GINGER_SOFTWARE_mark\">(<\/span>description_parts)<br \/>\n60 \u00a0\u00a0\u00a0\u00a0log.info('Creating snapshot of %s: %s', volume<span class=\"GINGER_SOFTWARE_mark\">.<\/span>id, description)<br \/>\n61 \u00a0\u00a0\u00a0\u00a0<span class=\"GINGER_SOFTWARE_mark\">volume<\/span><span class=\"GINGER_SOFTWARE_mark\">.<\/span>create_snapshot<span class=\"GINGER_SOFTWARE_mark\">(<\/span>description)<br \/>\n62 \u00a0\u00a0\u00a0\u00a0return True<\/code><\/p>\n<p style=\"text-align: justify\">We added this line<\/p>\n<p style=\"text-align: justify\"><code>description_parts=<span class=\"GINGER_SOFTWARE_mark\">[<\/span>self<span class=\"GINGER_SOFTWARE_mark\">.<\/span>_prefix<span class=\"GINGER_SOFTWARE_mark\">[<\/span><span class=\"GINGER_SOFTWARE_mark\">i<\/span>]<span class=\"GINGER_SOFTWARE_mark\">.<\/span>instances<span class=\"GINGER_SOFTWARE_mark\">[<\/span>0]<span class=\"GINGER_SOFTWARE_mark\">.<\/span>tags<span class=\"GINGER_SOFTWARE_mark\">[<\/span>'Name']] <\/code><\/p>\n<p style=\"text-align: justify\">This is basically extracting the Tag Name associated with the Reservation Id extracted above.<\/p>\n<p style=\"text-align: justify\">Next part is to modify the <strong>remove_old_snapshots<span class=\"GINGER_SOFTWARE_mark\">(<\/span>)<\/strong> section.<\/p>\n<p style=\"text-align: justify\"><span class=\"GINGER_SOFTWARE_mark\">Below code is<\/span> used for removing snapshots with the extracted Tag Name.<br \/>\n<code><br \/>\n73 j=0<br \/>\n74 for snapshot in snapshots:<br \/>\n75 #\u00a0\u00a0\u00a0\u00a0if not snapshot.description.startswith(self._prefix):<br \/>\n76 \u00a0\u00a0\u00a0\u00a0 if not snapshot.description.startswith(self._prefix[j].instances[0].tags['Name']):<br \/>\n77\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 log.debug('Skipping %s as prefix does not match', snapshot<span class=\"GINGER_SOFTWARE_mark\">.<\/span>id)<br \/>\n78\u00a0\u00a0\u00a0\u00a0 continue<br \/>\n79\u00a0\u00a0\u00a0\u00a0 if not snapshot<span class=\"GINGER_SOFTWARE_mark\">.<\/span>status == 'completed':<br \/>\n80\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 log.debug('Skipping %s as it is not a complete snapshot', snapshot<span class=\"GINGER_SOFTWARE_mark\">.<\/span>id)<br \/>\n81\u00a0\u00a0\u00a0\u00a0 continue<br \/>\n82\u00a0\u00a0\u00a0\u00a0 j=j+1<br \/>\n<\/code><\/p>\n<p style=\"text-align: justify\">We are done with the modification. <span class=\"GINGER_SOFTWARE_mark\">Lets<\/span> Test it out.<\/p>\n<p style=\"text-align: justify\">This is my Instance with Tag Name &#8220;Testing Instance&#8221;.<\/p>\n<p style=\"text-align: justify\"><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/04\/Screenshot-from-2014-04-07-165702.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-12918\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/04\/Screenshot-from-2014-04-07-165702.png\" alt=\"\" width=\"600\" height=\"100\" \/><\/a><\/p>\n<p style=\"text-align: justify\"><span class=\"GINGER_SOFTWARE_mark\">Lets<\/span> run<br \/>\n<code> <strong>$backup-monkey --region us-west-2<\/strong> <\/code><\/p>\n<p style=\"text-align: justify\"><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/04\/Screenshot-from-2014-04-07-170608.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-12919\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/04\/Screenshot-from-2014-04-07-170608.png\" alt=\"\" width=\"600\" height=\"100\" \/><\/a><\/p>\n<p style=\"text-align: justify\">Now you can see below the difference between the two <span class=\"GINGER_SOFTWARE_mark\">snapshot<\/span>. One with &#8220;BACKUP_MONKEY&#8221; which was the previous one, other with &#8220;Testing Instance&#8221; name<\/p>\n<p style=\"text-align: justify\"><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/04\/back5.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-12920\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/04\/back5.png\" alt=\"\" width=\"600\" height=\"101\" \/><\/a><\/p>\n<\/div>\n<p style=\"text-align: justify\">\nReferences: <a href=\"https:\/\/github.com\/Answers4AWS\/backup-monkey\">backup-monkey source code<\/a><\/p>\n<p style=\"text-align: justify\">\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s &#8220;BACKUP_MONKEY&#8221; prefix and tag the snapshot with this prefix. As you can see in the Description, BACKUP_MONKEY prefix is used. So this create&#8217;s a redundancy while finding the exact [&hellip;]<\/p>\n","protected":false},"author":100,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[1],"tags":[573,1358],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/12904"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/100"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=12904"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/12904\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=12904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=12904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=12904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}