{"id":19268,"date":"2015-04-24T02:36:31","date_gmt":"2015-04-23T21:06:31","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=19268"},"modified":"2015-04-24T02:37:50","modified_gmt":"2015-04-23T21:07:50","slug":"ec2-backup-manager-python-scripts","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/ec2-backup-manager-python-scripts\/","title":{"rendered":"EC2 Backup Manager : Python Scripts"},"content":{"rendered":"<h1 style=\"text-align: justify;\">EC2 Backup Manager : Python Scripts<\/h1>\n<p style=\"text-align: justify;\">One of the most important requirements in any projects is regular backups. On one of our projects we were using Netflix&#8217;s backup monkey and graffiti monkey combined to take snapshots of all the volumes in the account. But this deviated slightly from our requirement, we only required the backups of Production instances which were not Autoscaled (Autoscaled instances are anyway independent of the instance\/disk, so no backups needed).<\/p>\n<p style=\"text-align: justify;\">We (me (<a title=\"Hitesh Bhatia\" href=\"https:\/\/github.com\/hiteshBhatia\" target=\"_blank\">@hiteshBhatia<\/a>) and my colleague Aakash Garg <a title=\"Akash Garg\" href=\"https:\/\/github.com\/aakash21\" target=\"_blank\">@aakash21<\/a>) wrote couple <a title=\"Backup Manager\" href=\"https:\/\/github.com\/hiteshBhatia\/aws-boto-scripts\/tree\/master\/backup-manager\" target=\"_blank\">Python scripts\u00a0(publicly\u00a0available on Github)<\/a>\u00a0which are more suited to our needs and might help others too. These scripts are part of a\u00a0\u00a0public repo (on Github) which compromises of\u00a0scripts which are helpful for managing an\u00a0AWS account.<\/p>\n<p style=\"text-align: justify;\">This custom backup-manager of ours includes two scripts, one for the creation of images and other for deletion of old images. Both of the\u00a0script are based on tags which are applied to the instances.<\/p>\n<p style=\"text-align: justify;\">Following scripts only manage backups of instances that have been marked with tag {&#8220;AutomaticBackup&#8221;:&#8221;True&#8221;}.<\/p>\n<p style=\"text-align: justify;\">1. <a title=\"Create Images Based On Tags\" href=\"https:\/\/github.com\/hiteshBhatia\/aws-boto-scripts\/blob\/master\/backup-manager\/createImagesBasedOnTags.py\" target=\"_blank\"><strong>createImagesBasedOnTags.py<\/strong><\/a> &#8211; This script creates the backup of those instances which are marked with the\u00a0tag &#8220;AutomaticBackup&#8221; with value &#8220;True&#8221; {&#8220;AutomaticBackup&#8221;:&#8221;True&#8221;}. The script also tags the resultant backups (ami) with the instance_id tag, which also helps in searching of ami associated with the instance.<\/p>\n<p style=\"text-align: justify;\">The script also uses one more tag named &#8220;Frequency&#8221;. \u00a0It defines the frequency of backups you require in a day, default value is 1. If you are running this script twice a day use &#8220;Frequency&#8221; tag with value 2. The script would not take backups more than the Frequency in a day. I.e If Frequency is 2 and you run this script 4 times a day. It will only create backup twice because the value of Frequency tag is 2.<\/p>\n<p style=\"text-align: justify;\">2. <a title=\"Delete Backups Based OnTags\" href=\"https:\/\/github.com\/hiteshBhatia\/aws-boto-scripts\/blob\/master\/backup-manager\/deleteBackupsBasedOnTags-backupManager.py\" target=\"_blank\"><strong>deleteBackupsBasedOnTags-backupManager.py<\/strong><\/a> &#8211; It reads the instance tag RetentionCount (in days) and deletes the older images. If no tag is specified by default it retains the backups of last 30 days and deletes the older images.<\/p>\n<p style=\"text-align: justify;\">So now if you create a new instance and require its regular backups managed, just add the tag &#8220;AutomaticBackup&#8221; with value true and its backups will managed. So to start managing backups, tag your instances, schedule the script with cron scheduler and its done. And do not forget that Tags are case sensitive.<\/p>\n<p style=\"text-align: justify;\">PS : These scripts are part of &#8220;<a title=\"aws-boto-scripts\" href=\"https:\/\/github.com\/hiteshBhatia\/aws-boto-scripts\" target=\"_blank\">aws-boto-scripts<\/a>&#8220;, which is a repo of\u00a0Python scripts written with boto for managing an\u00a0AWS account.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>EC2 Backup Manager : Python Scripts One of the most important requirements in any projects is regular backups. On one of our projects we were using Netflix&#8217;s backup monkey and graffiti monkey combined to take snapshots of all the volumes in the account. But this deviated slightly from our requirement, we only required the backups [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[1174],"tags":[1172,248,1611,1768,1358],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/19268"}],"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\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=19268"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/19268\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=19268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=19268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=19268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}