{"id":4876,"date":"2016-10-10T09:18:37","date_gmt":"2016-10-10T14:18:37","guid":{"rendered":"https:\/\/www.poweradmin.com\/blog\/?p=4876"},"modified":"2016-10-08T09:50:10","modified_gmt":"2016-10-08T14:50:10","slug":"reducing-downtime-while-backing-up-aws-ec2-instances","status":"publish","type":"post","link":"https:\/\/www.poweradmin.com\/blog\/reducing-downtime-while-backing-up-aws-ec2-instances\/","title":{"rendered":"Reducing Downtime While Backing Up AWS EC2 Instances"},"content":{"rendered":"<p><span style=\"font-family: verdana, geneva, sans-serif;\"><a href=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2016\/10\/backup-drives.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-4878 alignleft\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2016\/10\/backup-drives.jpg\" alt=\"Hard disk drive\" width=\"191\" height=\"259\" srcset=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2016\/10\/backup-drives.jpg 284w, https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2016\/10\/backup-drives-221x300.jpg 221w\" sizes=\"auto, (max-width: 191px) 100vw, 191px\"><\/a>We\u2019re big fans of AWS and use several of its services. \u00a0One service we use is EC2 \u2013 it costs much less than having a dedicated server and still gives you full control of the server.<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">One issue is being sure we can bring the server back up in case it crashes, or the instance is somehow corrupted (I\u2019ve read and heard about this anecdotally enough to believe it must happen on rare occasion). \u00a0That means we need backups.<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">Backing up an EC2 instance is really just backing up the full drives in the instance. \u00a0There are two ways to do this:<\/span><\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">1. Create an AMI of the server. \u00a0This requires the EC2 instance to be stopped and will copy all drives and the EC2 instance configuration into a single entity, making it easy to spin up another identical server.<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">2. Backup the individual volumes of the EC2 instance. \u00a0We use this method because down time is much shorter.<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">Taking a snapshot of a volume is the way you back it up. \u00a0They are differential snapshots, which means only data changed since the last snapshot was run needs to be copied. \u00a0So the very first snapshot takes the longest as the most data (full drive) will need to be copied.<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">Snapshots are done asynchronously, and are low priority. \u00a0They can take a while. \u00a0If you\u2019re looking to reduce downtime, you should be aware of a couple of points:<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">1. It\u2019s safe to backup a volume that is in use. \u00a0However, you\u2019ll end up with whatever the state of the disk was at the instant the snapshot starts. \u00a0That means it\u2019s safest to either have the disks unmounted from the operating system (so the disk is in a consistant state), or if that\u2019s not possible (the boot drive is being backed up), stop the instance.<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">2. I\u2019ve not been able to find any documentation that describes exactly\u00a0<em>when<\/em> the snapshot starts. \u00a0You can \u2018create a snapshot\u2019, but it appears that really just creates a snapshot request that will get handled at some point soon.<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">#2 is the kicker. \u00a0You don\u2019t know when the snapshot has started. \u00a0Because of that, we wait until the status is \u201cpending\u201d and something other than \u201c0%\u201d \u2013 meaning a status of 1% complete means the snapshot\u00a0has definitely started.<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">With that in mind, this procedure (coded using any of the AWS AMIs or done manually) will give you the shortest possible downtime while creating a backup of your server:<a href=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2016\/10\/backup-complete.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4879 alignright\" src=\"https:\/\/www.poweradmin.com\/blog\/wp-content\/uploads\/2016\/10\/backup-complete.png\" alt=\"backup-complete\" width=\"300\" height=\"295\"><\/a><\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">1. Stop EC2 instance<\/span><\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">2. Start a snapshot of each volume in the instance<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">3. For each snapshot, wait until the status is more than 0% complete<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">4. Start the EC2 instance<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">You can start the EC2 instance as soon as all\u00a0snapshots have made progress. \u00a0This is completely safe. \u00a0 So the beauty and time savings is in not having to wait for the snapshots to finish.<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">Using this method, we find we can backup a server with two 150 GB drives in 12-15 minutes. \u00a0If we waited for the snapshots to complete, it could be an hour or more.<\/span><\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">If you backup once a week, with 15 minutes of downtime for the backup, that\u2019s 99.85% uptime, or\u00a0about \u201cthree\u00a0nines\u201d.<\/span><\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u2019re big fans of AWS and use several of its services. \u00a0One service we use is EC2 \u2013 it costs much less than having a dedicated server and still gives you full control of the server. \u00a0 One issue is being sure we can bring the server back up in case it crashes, or the [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":4878,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6,9],"tags":[],"class_list":["post-4876","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general-it","category-tech","category-technical"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/4876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/comments?post=4876"}],"version-history":[{"count":5,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/4876\/revisions"}],"predecessor-version":[{"id":4887,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/posts\/4876\/revisions\/4887"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/media\/4878"}],"wp:attachment":[{"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/media?parent=4876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/categories?post=4876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poweradmin.com\/blog\/wp-json\/wp\/v2\/tags?post=4876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}