{"id":787,"date":"2016-09-01T04:56:30","date_gmt":"2016-08-31T23:56:30","guid":{"rendered":"http:\/\/52.24.147.87\/?p=787"},"modified":"2016-10-03T11:39:38","modified_gmt":"2016-10-03T06:39:38","slug":"the-six-steps-of-disaster-recovery","status":"publish","type":"post","link":"http:\/\/www.stonemillkids.com\/index.php\/2016\/09\/01\/the-six-steps-of-disaster-recovery\/","title":{"rendered":"Step By Step Disaster Recovery on AWS"},"content":{"rendered":"<p>Disaster Recovery has been a long neglected action on my part.\u00a0 As such, when a disaster did strike, it forced me to into creating a Disaster Recovery blog post.\u00a0 I am now a better, more knowledgeable, AWS admin because of the incident. However, I have not be actively backing up my server, and as such, I did lose a blog post or two.<\/p>\n<p>I was forced into disaster recovery because of self imposed actions.\u00a0 My AWS instance started acting up.\u00a0 I am not sure why,\u00a0 but it started to crash, regularly.\u00a0 So much so, that the CPU spiked, and I could not get back into the server.\u00a0 Obviously, if I cannot get in the server, I cannot fix it.\u00a0 So, I started poking around on the AWS management console until it terminated my instance, and all of my data was once again lost&#8230; and once again, it way my fault. My backups this time consisted of an AWS Snapshot just before the last major upgrade, a year ago, and a local WordPress backup from last month.\u00a0 I still have local copies of my git repository, and all of my other game assets.\u00a0 This means today&#8217;s activities need to include the following:<\/p>\n<h2>The Six Steps of Recovery<\/h2>\n<p>Of the original 12 steps, I feel I have completed five in other blog posts&#8230;\u00a0 All kidding aside, here is what I had to do to get the site back up and functional.<\/p>\n<ol>\n<li>Rebuild an AWS instance and point it to my old SnapShot.\u00a0 This is my first time doing this, so it will obviously take longer than I will really want.\u00a0 I also have to point the DNS to the new IP.<\/li>\n<li>Upgrading AWS, WordPress, and GitLab via yum<\/li>\n<li>Other items\n<ul>\n<li>after upgrading I did not know my old WordPress password, so I had to reset that.<\/li>\n<li>upgrading WordPress themes and plugins to the newer versions<\/li>\n<li>add missing content to the major pages that needed it<\/li>\n<\/ul>\n<\/li>\n<li>Evaluating what is missing from the blog posts, and adding the content a second time.\u00a0 I know my last backup did not contain images, so there is some rework to do there.\u00a0 While I was on vacation, I also changed the theme of my WordPress site.\u00a0 Much of that will need to be redone.\n<ul>\n<li>ask Google to reindex my site as the structure as changed.<\/li>\n<\/ul>\n<\/li>\n<li>Restore\/reconfigure GitLab<\/li>\n<li>Setup a new backup strategy that keeps me more up to date<\/li>\n<li>Write all of this down to aid in future disaster recovery.<\/li>\n<\/ol>\n<h2>Step 1: Pointing a new AWS instance to an Old SnapShot<\/h2>\n<p>The general idea here is that an AWS instance is analogous to an old school bare-bones server (memory, motherboard).\u00a0 The SnapShot is analogues to the image of the hard drive that needs to be restored.\u00a0 The way I found it works is first you bring up the new &#8220;computer&#8221; with a new &#8220;hard drive&#8221; and make sure it works.\u00a0 Then you shut down the computer and swap out to the old hard drive image.\u00a0 I think AWS either created an extra step, or I found an odd way of restoring backups, but it worked so that is how it is documented here. Before embarking on this endeavor, I did some research. In short:<\/p>\n<ol>\n<li>Create a compatible ES2 instance of your previous system<\/li>\n<li>Start the new EC2 instance, then shut it down.<\/li>\n<li>With is shut down, right-click and detach the Volume\n<ul>\n<li>you need to determine where the new HD is mounted (\/dev\/sda, etc.)<\/li>\n<li>you will need the instance ID to link the saved HD<\/li>\n<\/ul>\n<\/li>\n<li>From your previous \u00a0your Snapshot, right-click and create a new Volume<\/li>\n<li>Assign that Volume to the new instance ID with the same mount point as before<\/li>\n<li>Restart the new instance that now runs the old HD<\/li>\n<\/ol>\n<div>Of all of the articles I read, these two were the most helpful:<\/div>\n<p><a href=\"https:\/\/amimoto-ami.com\/2014\/10\/03\/create-snapshot-restore\/\"><u><span style=\"color: #0066cc;\">https:\/\/amimoto-ami.com\/2014\/10\/03\/create-snapshot-restore\/<\/span><\/u><\/a> <a href=\"http:\/\/blog.ravitezu.me\/error-starting-aws-ec2-instancehttp:\/\/blog.ravitezu.me\/error-starting-aws-ec2-instance\"><u><span style=\"color: #0066cc;\">http:\/\/blog.ravitezu.me\/error-starting-aws-ec2-instancehttp:\/\/blog.ravitezu.me\/error-starting-aws-ec2-instance<\/span><\/u><\/a><\/p>\n<h3>Here are some issues that I ran into:<\/h3>\n<p><em>Issue 1<strong>:\u00a0<\/strong>Make sure you use the same security groups.\u00a0 I have more than one profile and my default is not my WordPress EC2 instance.\u00a0 This means my local public and private keys were a mismatch and I could not log in until I corrected that. <\/em><\/p>\n<p><em><strong>Issue 2:<\/strong>\u00a0If you try to connect to the new system via SSH, etc, the IP address will be different than it was before.\u00a0 DO NOT CHANGE THIS OR THE Route 53 CONFIGURATIONS!\u00a0 Instead, use the Elastic IP address feature to\u00a0set the new IP to\u00a0report to the outside world as\u00a0the old one.\u00a0 \u00a0I spent about 30 minutes trying to log into WordPress, but the system kept getting mixed up between old and new IP address.<\/em><\/p>\n<p style=\"padding-left: 30px;\"><em>If, you did somehow change IP addresses on the server and do not have the Elastic IP configured, you can read how to repair the WordPress database on my old post <a href=\"http:\/\/52.24.147.87\/index.php\/2015\/06\/08\/hello-world-2\/\"><u><span style=\"color: #0066cc;\">here<\/span><\/u><\/a>.<\/em><\/p>\n<p>One those were fixed, I was able to see an old version of the server.<\/p>\n<h2>Step 2: Upgrading the AWS Server via Package Management<\/h2>\n<p>I love this step. To upgrade wordpress, GitLab, and the entire AWS web server, simply log into the Linux server and type:<\/p>\n<pre>#sudo yum update<\/pre>\n<p>I would like to say that it has never failed me, but there was that one time where I had to manually patch a GitLab file.\u00a0 I wrote a whole blog post about it, but that was lost in the crash.\u00a0 Luckily, GitLab was very responsive to the issue and had already pushed out a new build. To summarize, the old post, if you have an issue with GitLab, search their page:<\/p>\n<p><a href=\"https:\/\/gitlab.com\/gitlab-org\/release-tools\/issues\"><u><span style=\"color: #0066cc;\">https:\/\/gitlab.com\/gitlab-org\/release-tools\/issues<\/span><\/u><\/a><\/p>\n<h2>Step 3: Getting WordPress Operational Again<\/h2>\n<h3>Step 3a: Resetting the WordPress password<\/h3>\n<p>This is an optional step for those that remember what their password was a year ago.\u00a0 However, I did not.\u00a0 This means that I needed to reset the WordPress password of my blogging account gscott.\u00a0 While there are web-based tools such as phpMyAdmin, I do not try to expose more admin tools to the web than I need this means I needed instructions for resetting the password via MySQL directly.\u00a0 After some googling, I found this article to be the most helpful:<\/p>\n<p><a href=\"https:\/\/codex.wordpress.org\/Resetting_Your_Password\">https:\/\/codex.wordpress.org\/Resetting_Your_Password<\/a><\/p>\n<h3>Step 3b: Upgrading WordPress Themes and Plugins<\/h3>\n<p>Once the base system was up and functional, I needed to upload the latest theme and import\/export tools.\u00a0 Here are the basic instructions:<\/p>\n<h4><span id=\"Adding_New_Themes_Manually_.28FTP.29\" class=\"mw-headline\">Adding New Themes Manually (FTP)<\/span><\/h4>\n<ol>\n<li>Download the Theme archive and extract the files it contains. You may need to preserve the directory structure in the archive when extracting these files. Follow the guidelines provided by your Theme author.<\/li>\n<li>Using an <a title=\"FTP Clients\" href=\"https:\/\/codex.wordpress.org\/FTP_Clients\"><u><span style=\"color: #0066cc;\">FTP client<\/span><\/u><\/a> to access your host web server, create a directory to save your Theme in the <tt>wp-content\/themes<\/tt> directory provided by WordPress. For example, a Theme named <b>Test<\/b> should be in <tt>wp-content\/themes\/test<\/tt>. Your Theme may provide this directory as part of the archive.<\/li>\n<\/ol>\n<h4>Here is the full content of the link:<\/h4>\n<p><a href=\"https:\/\/codex.wordpress.org\/Using_Themes#Selecting_the_Active_Theme\"><u><span style=\"color: #0066cc;\">https:\/\/codex.wordpress.org\/Using_Themes#Selecting_the_Active_Theme<\/span><\/u><\/a><\/p>\n<h4>Here is what I did:<\/h4>\n<p>I recommend giving the directory two folders.\u00a0 One for the old theme and one for the new one.<\/p>\n<div>After I got the new theme to my site, I simply extracted it to a new theme folder:<\/div>\n<pre># unzip customizr.3.4.22.zip -d \/var\/www\/html\/wp-content\/themes\/customizr_3_4_22\r\nArchive:\u00a0 \/usr\/share\/wordpress\/wp-content\/themes\/customizr.3.4.22.zip\r\n\u00a0\u00a0 creating: customizr_3_4_22\/customizr\/\r\n\u00a0 inflating: customizr_3_4_22\/customizr\/comments.php\r\n\u00a0 inflating: customizr_3_4_22\/customizr\/footer.php\r\n...\r\n\u00a0 inflating: customizr_3_4_22\/customizr\/style.css\r\n# ls\r\ncustomizr\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 customizr_3_4_22\u00a0\u00a0\u00a0\u00a0\u00a0 index.php\u00a0\u00a0\u00a0\u00a0\u00a0 twentyfourteen\r\ncustomizr.3.3.26.zip\u00a0 customizr.3.4.22.zip\u00a0 twentyfifteen\u00a0 twentythirteen<\/pre>\n<p>Doing so will give you both versions of the theme to choose from:<\/p>\n<p><a href=\"http:\/\/52.24.147.87\/wp-content\/uploads\/2016\/08\/Customizr.png\"><img loading=\"lazy\" class=\"alignnone size-medium wp-image-793\" src=\"http:\/\/52.24.147.87\/wp-content\/uploads\/2016\/08\/Customizr-300x156.png\" alt=\"Customizr\" width=\"300\" height=\"156\" srcset=\"http:\/\/www.stonemillkids.com\/wp-content\/uploads\/2016\/08\/Customizr-300x156.png 300w, http:\/\/www.stonemillkids.com\/wp-content\/uploads\/2016\/08\/Customizr.png 357w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>It should be noted, I had to change my sidebars and other widgets back in the new version, but overall the process took less than 10 minutes.<\/p>\n<p>Similar to above, the import\/export plugin also needed to be updated.\u00a0 It was placed in the <span style=\"font-family: Courier New;\">wp-content\/plugins<\/span> directory.<\/p>\n<pre># mv wordpress-importer\/ bob\r\n# unzip wordpress-importer.0.6.3.zip\r\nArchive:\u00a0wordpress-importer.0.6.3.zip\r\nwordpress-importer.0.6.3 packaged\r\n\u00a0\u00a0 creating: wordpress-importer\/\r\n\u00a0 inflating: wordpress-importer\/readme.txt\r\n\u00a0\u00a0 creating: wordpress-importer\/languages\/\r\n\u00a0 inflating: wordpress-importer\/languages\/wordpress-importer.pot\r\n\u00a0 inflating: wordpress-importer\/parsers.php\r\n\u00a0 inflating: wordpress-importer\/wordpress-importer.php\r\n# ls\r\nakismet\u00a0 bob\u00a0 hello.php\u00a0 index.php\u00a0 wordpress-importer<\/pre>\n<p>Again, WordPress was great about installing side by side.\u00a0 Once I have shown that the importer functions correctly, I will detele the &#8220;bob&#8221; directory.<\/p>\n<h3>Step 3c: Restoring and Replacing Old Content<\/h3>\n<p>The Tools menu in WordPress offers an import\/export feature.\u00a0 After I imported my old blogs, I had to go back over each one and review the content.\u00a0 Some links were broken, other images were missing.\u00a0 I also had to redo the new style that I rolled out for better search results.\u00a0 Overall it was not too bad due to an entire site crash, but it took some time.<\/p>\n<h3>Step 4: Restoring GitLab<\/h3>\n<p>The GitLab server\u00a0is still up, but only has test repositories.\u00a0 I created a blog post of how to sync local repositories back to the GitLab server.\u00a0\u00a0 That part went off without a hitch, until I tried to restore my <a href=\"http:\/\/www.stonemillkids.com\/index.php\/2015\/06\/28\/gitlab-changing-the-projects-default-labels\/\">default labels <\/a>and reconfigure the server after the upgrade.<\/p>\n<p>While doing this, I also did a &#8220;sudo yum update&#8221; &#8211; which updates all of my packages.\u00a0 most items worked well, however GitLab failed.\u00a0 It looks like I did one too many things at the same time (again).<\/p>\n<p>When GitLab tries to start, but cannot, it creates a weird &#8220;Oops&#8221; page.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-899\" src=\"http:\/\/www.stonemillkids.com\/wp-content\/uploads\/2016\/09\/gitlab_502_error-287x300.png\" alt=\"GitLab not starting - 100% CPU Usage from unicorn\" width=\"287\" height=\"300\" srcset=\"http:\/\/www.stonemillkids.com\/wp-content\/uploads\/2016\/09\/gitlab_502_error-287x300.png 287w, http:\/\/www.stonemillkids.com\/wp-content\/uploads\/2016\/09\/gitlab_502_error-144x150.png 144w, http:\/\/www.stonemillkids.com\/wp-content\/uploads\/2016\/09\/gitlab_502_error.png 289w\" sizes=\"(max-width: 287px) 100vw, 287px\" \/><\/p>\n<p>After 8hrs of googling, I came up with a solution!\u00a0 It was really simple actually.\u00a0 You see, I had copied my original file via Ctrl-C + Ctrl-V.\u00a0 Gitlab could not interpret it for some reason and unicorn was taking up 100% of my CPU.\u00a0 To correct the problem, I simply manually retyped the file inside my favorite Linux editor.\u00a0\u00a0I guessed what I needed to do because if typed &#8220;gitlab-ctrl tail&#8221; which gave me a complete log of everything going on.\u00a0 I found that every time I started, I was getting an error in issues_labels.rb on the first line that I changed&#8230; which was disovered by taking the default file, then changing one just my colors, then just my lables.\u00a0 &#8211; It was bascily an error bubble sort on the file with at restart of GitLab every iteration.\u00a0 My four goto commands were:<\/p>\n<pre>\u00a0# sudo vi \/opt\/gitlab\/embedded\/service\/gitlab-rails\/lib\/gitlab\/issues_labels.rb\r\n\u00a0# sudo gitlab-ctl restart\r\n\u00a0# top\r\n\u00a0# cat \/var\/log\/gitlab\/unicorn\/unicorn_stderr.log<\/pre>\n<p>I also had a separate terminal running<\/p>\n<pre># gitlab-ctl tail<\/pre>\n<p>Each time I saw an error, I would change the file on that location and restart.\u00a0 It was slow progress, but eventually GitLab was able to restart without errors.\u00a0 As such, I am posting my <a href=\"http:\/\/www.stonemillkids.com\/wp-content\/uploads\/2016\/09\/issues_labels.rb\">issues_labels.rb<\/a>.<\/p>\n<h2>\u00a0Step 4: Finding Out What is Missing<\/h2>\n<h3>Step 5a: Reading all my old Blogs and Taking Notes<\/h3>\n<p>On my site, there were tons of missing images.\u00a0 The backup only saves text.\u00a0 Images are (I believe) stored in MySQL, so they were not backed up.\u00a0 As such, I had to import all of the old images again.<\/p>\n<p>There were also pages that I renamed over time. They showed up as &#8220;duplicates&#8221; &#8211; meaning the same page, with two different titles.\u00a0 I had to compare them side-by-side and manually merge them.\u00a0 Not fun, but doable because I generally took the later post.<\/p>\n<p>The one big issues I saw was the import <em>DID NOT\u00a0<\/em>\u00a0 Import pages with the same name.\u00a0 This means that if I updated a page, but it had the same name, I would not get the content.\u00a0 If I was not pressed for time, I would have deleted all of the pages and re-imported them.\u00a0 Since I was not very active blogging between posts, I simply read the pages that were there and made corrections for grammar, clarity and content.\u00a0 Not the safest thing to do, but it was all I was willing to stomach after all of the other issues I had dealt with.<\/p>\n<h3>Step 5b: Asking Google to Reindex the Site<\/h3>\n<p>Now that the site is back to where is was before, or at least a reasonable facsimile of it, I need to let Google know so it can reined the site.\u00a0 If my backup was identical to the site before, I would not see this as an issue.\u00a0 However, I lost and had to recreate data, so I expect some things to be different.<\/p>\n<p><a href=\"https:\/\/support.google.com\/webmasters\/answer\/6065812?hl=en&amp;ref_topic=4617736\"><u><span style=\"color: #0066cc;\">https:\/\/support.google.com\/webmasters\/answer\/6065812?hl=en&amp;ref_topic=4617736<\/span><\/u><\/a><\/p>\n<p><a href=\"https:\/\/www.google.com\/webmasters\/tools\/submit-url?continue=\/addurl\"><u><span style=\"color: #0066cc;\">https:\/\/www.google.com\/webmasters\/tools\/submit-url?continue=\/addurl<\/span><\/u><\/a><\/p>\n<h2>Step 6: My New Backup Strategy<\/h2>\n<p>Looking online, there does not seem to be a cost effective (automated)\u00a0backup strategy for a single server.\u00a0\u00a0Right now, my bill runs about $9\/mico instance I use and about $0.5 (50 cents) for storing my backups.\u00a0 As such, I simply going to manually make the backups as I need them.\u00a0 Now that I know how to\u00a0backup and restore the SnapShots, I feel a lot more comfortable with the cloud storage I am using.<\/p>\n<p>My next logical step would be to also AWS to backup my local PC, but I am currently happy with Microsoft&#8217;s One Drive and the AWS hosted GitLab server that I run.<\/p>\n<p>In short, we will keep this Status Quo for now&#8230; but I will be creating a snapshot right after I finish the post.<\/p>\n<h2>Step 7: Write Everything Down<\/h2>\n<p>The good part about blogging about what happens, is it creates a natural log of how to fix it.\u00a0 The only issue I have run into is that when the site crashes, so does the blog.\u00a0 Luckally, my local\u00a0XML backups from WordPress have aways given me enough content to get back to a functional server fairly quickly.<\/p>\n<p>My next logical step here would be to\u00a0create a single, easy to\u00a0find page, that describes\u00a0the\u00a0steps I need to take so I do not have to search through the\u00a0site&#8217;s entire XML file.\u00a0 I&#8217;ll add that one to\u00a0my backlog on Trello.<\/p>\n<h2>Now that we are Done<\/h2>\n<p>If you want to delete the old snapshots or AMI instances that use them, AWS has a couple of good articles.\u00a0 I would, however, suggest creating a new snapshot of the newly working system before deleting anything.\u00a0 Also keep in mind that AWS does incremental updates, meaning the 1st backup is the entire drive and each additional snapshot only has the differences.\u00a0 Anyway, here are links to the AWS documentation:<\/p>\n<p><a href=\"http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/ebs-deleting-snapshot.html\"><u><span style=\"color: #0066cc;\">http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/ebs-deleting-snapshot.html<\/span><\/u><\/a><\/p>\n<p><a href=\"http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/deregister-ami.html\"><u><span style=\"color: #0066cc;\">http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/deregister-ami.html<\/span><\/u><\/a><\/p>\n<h2>(Un)documented Step 8: Backup Your Current Code &#8211; i.e My\u00a0Next Post<\/h2>\n<p>Now that we are up and running, I need to make sure my current copies of the code get them back on GitLab.\u00a0 While this is probably unnecessary for those that backup more regularly, I had to spend some time <a href=\"http:\/\/www.stonemillkids.com\/index.php\/2016\/10\/03\/synchronizing-gitlab-and-your-pc\/\">syncing my GitLab <\/a>server with my local repositories.<\/p>\n<h2><b>Now Please Create a AWS Snapshot<\/b><\/h2>\n<p>If you have had to do <strong>ANY <\/strong>manual effort to get to where you are now &#8211;\u00a0now is the time to create a snapshot.\u00a0 Forgetting, or postponing it may in fact bring you back to this page sooner than you would like.<\/p>\n<h1><b>Bookmark Stonemillkids.com <\/b><\/h1>\n<p>You can at least bookmark this page so your next recovery will be much easier.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Disaster Recovery has been a long neglected action on my part.\u00a0 As such, when a disaster did strike, it forced me to into creating a Disaster Recovery blog post.\u00a0 I am now a better, more knowledgeable, AWS admin because of the incident. However, I have not be actively backing up my server, and as such, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":706,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18,14,4,17],"tags":[25,24,29,30,26,31,27,33,28,32],"_links":{"self":[{"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/posts\/787"}],"collection":[{"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/comments?post=787"}],"version-history":[{"count":11,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/posts\/787\/revisions"}],"predecessor-version":[{"id":903,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/posts\/787\/revisions\/903"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/media\/706"}],"wp:attachment":[{"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/media?parent=787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/categories?post=787"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/tags?post=787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}