Thanks to bad directions from the worst hosting company ever, plus my own carelessness, I deleted The Cookblog’s MySQL database yesterday. After exporting the database, deleting it, and recreating it, my attempts to import all of the tables back in met with failure due to an error. Further study showed that the export contained an error, so my copy was essentially useless. After a few choice words, I had no choice but to set about retrieving my lost posts (naturally, I hadn’t backed them up). I’m sure this has happened and will happen to others, so here’s how I went about recovering my posts with the help of Google and WordPress.
1. First, you’ll want to find the copies of your pages that Google knows about. To do this, simply do a Google search for “site:yoursitename.com”
2. For each post, get Google’s copy by clicking the “Cached” link below the search result. It’s helpful to have a browser that supports tabs for this, since there will probably be a lot of these pages to open, especially if you have a lot of posts.
3. Clicking the “Cached” link will take you to a page that states the date Google last saved it. It may or may not include images. Since Google won’t keep these copies around forever, it’s best to go through this process as soon as possible.
4. If you want to save the images for some reason (I still had my files intact in my FTP and they were backed up anyway), you can right-click and “Save As” to capture them. Otherwise, you’ll want to view the source code of the page. If you use WordPress, you should be able to find the title of your post, the date it was posted and the content of the post. Select the code starting with the title and ending with the close paragraph tag. Copy it and paste it into a TXT file. Repeat steps 2, 3 and 4 for each post.
5. Once you have all of the posts you can get off Google in the TXT file, open up the WordPress’s Write Post interface. Copy and paste in the title of the post, then switch the input field from “Visual” to “Code”. Paste in the code of your post, starting with the paragraph tag that opens the post and ending with the end paragraph tag that closes the post. This will keep your links and images intact without having to re-enter them.
6. Between the title and post content in the source code is the date that you actually published the post. You can use WordPress’s Post Timestamp option to publish the post with the initial date.
As long as Google has seen your pages and made its own copy, you should be able to recover almost all of your lost content. It only took me about an hour to retrieve and republish the 50 or so posts I’d made over the past few months. It also persuaded me to use the Manage–>Export function to save a copy of my entire blog so that if I ever delete it again, I’ll be able to reinstall WordPress, import my saved file, and revert immediately to its previously saved state. That’s a far easier and more complete way to recover a blog, but the above method is better than nothing. Anyone else have tips/horror stories?