If you didn't know about my recent mishap, a few nights ago I managed to blow up the VPS that hosts this website. You can read more about it here. It was a complete disaster and by the time I caught the mistake, my analytics database was completely gone and my Wordpress database was badly fragmented.
The last backup I performed was back in November 2012, when I moved my blog from shared hosting to a VPS. Even after my blog redesign, I still hadn't made a new backup. I know better. Shame on me.
Fortunately, I was able to recover from this disaster, thanks to a combined effort from MarsEdit and Amazon S3. Here's how they saved my blog.
After a sleepless night and an unrelated trip to the emergency room, I came home and crashed for 8 hours. When I woke up, I decided I was not going to admit defeat. Writing about my passions is what keeps me sane and without a blog to which I can commit and share my thoughts, I would be at a loss. After a period of pensiveness, I remembered that MarsEdit offers a handy (and probably unintentional) feature of caching the meta data on posts like the title, excerpt, tags and body. I surmised that as long as I didn't manually refresh the data, the local cache should still store then 20-something posts I lost when my database got fragmented.
After I was coherent enough from the night before, I ran to my laptop and launched MarsEdit from the dock. Sure enough, it still had the local cache of stories that I could re-publish to the blog. I tried a publish action on one of the posts and it started to complain about how the post ID didn't match the live version and, as a result, the local version of the post just sat there. The solution was simple albeit a bit more work: copy and paste the body of the post into a new post through
wp-admin with the same title as the cached version. I counted the number of posts I was missing; 21 posts in all. It could have been worse, but with the frequency I was publishing over the past few months, I would have lost a lot of good content.
In addition to the raw content being needing to be salvaged, I also needed to recover the images associated with each post. Since redesigning my blog, the new layout is heavily dependent on featured images for displaying on the main page. Without them, you would just see a black box 384 pixels wide by 384 pixels tall. Not very swanky.
After I create each post's featured image, I discard the original image and the modified version. There's not much need to keep them around, since I can reuse them at any time after they're uploaded to the server and stored in the database. The same database that I blew up only hours before. With no backup. Fuck.
Luckily, I use something called a content distribution network for all my static content. CDNs are a popular choice for serious bloggers who want to achieve the best performance from their database and hosting server while making that content readily available. Amazon's S3 (simple storage service) is a popular choice and one I've personally chosen to serve all of my static content like images and PDF downloads. It takes a load off of my internal Wordpress database and it's less stress on the hosting server's resources overall. When I upload an image for a post, it storage the image as a source in the
wp-content/uploads directory. Within a few minutes, a copy of that file is transferred to my S3 account and that's where the content is served from instead of my Wordpress database and core directory. As a side note, I combine it with Amazon CloudFront for the lowest possible latency and highest rate of transfer since the distribution is global, rather than localized on my server.
Since all my content was stored offsite, it didn't matter how damaged my core files were that resided original in
wp-content/uploads. I still had my backup from the previous November and I would just hunt through the S3 bucket until I found the files that matched up. The entire process took me about 15 minutes, since I had a minimal amount of posts to gussy up.
I think the moral of the story here is to backup your files on a regular basis: both core Wordpress and the database it uses. Needless to say, both are essential to the proper execution of a Wordpress installation. However, if you're a dumbass like me and for whatever reason you don't back up your installation regularly, it's nice to know that there are alternatives to save the day. It's for this reason that I maintain that MarsEdit is simply the best blogging software for the Mac. Period. I will never use anything else because Daniel Jalkut continues to maintain the integrity of this application. With regard to Amazon S3, I knew a long time ago that should anything ever happen to my uploads in
wp-content, I would have a copy of those files offsite.
I guess it finally came in handy.