How to: Backup and Restore your WordPress Blog

In the past few weeks, I’ve tested a few disaster recovery procedures for [GAS], and I thought that sharing those with the blogosphere could be of value to a lot of bloggers out there. If you’re among those who’ve been religiously backing up their WordPress blog since day one, let me ask you a question: Have you ever tried restoring a backup of your data on a non-production box? After a data-loss disaster, this procedure could make a huge difference between losing everything you’ve worked on since your blog went online, or being up and running in under an hour.

Before getting in the backup and restoration section of this tutorial, follow these simple instructions on how to install WordPress locally on windows. Getting WordPress to run on your computer can be done in less than 5 minutes. No joke.When you are done, follow this simple procedure to get your production template up and running:

  1. Log in to your web server via FTP and dump your entire <Siteroot>\WP-Content folder onto your local drive. This will copy all your themes and plug-ins, and will bring the pictures you need on your computer.
  2. Copy the newly created, local backup of your online WP-Content folder on top of the one located in your local WordPress installation.
  3. Login to your test WordPress server’s dashboard, navigate to the presentation -> Themes section, and activate your theme.
  4. Load your blog’s front page and admire the result.

You now have an exact copy of your blog running on your computer. You may want to de-activate a few plugins and remove a few scripts from your sidebar or footer before going further, but that’s up to you.

When you’re happy on how your blog looks, you’ll want to backup and restore your blog content to your local installation. There are two ways to do this. The complicated way using MYPHPAdmin and the easy way using WordPress’s new WXR (WordPress eXtended RSS) export feature. If you’re running any version of WordPress before WordPress 2.1, you have two choices:

I did not test this plug-in, so I can’t attest to whether or not it works well, but knowing how professional Techosailor is, I’m sure it does. You guys might want to report back in the comments if you try it out. Please note that this is only for people who are running any version of WordPress older than 2.1.

Also, if you use the complicated method and run your blog locally, you’ll need to add these values to your WP-Config.php file after restoring the data back:

define(‘WP_HOME’, ‘localhost\<blog directory>’);
define(‘WP_SITEURL’, ‘localhost\<blog directory>’);

Where <blog directory> is, insert whatever directory your blog is running under. In my case, it was under “localhost\wordpress”.

If you don’t, every time you load your local front page, you will get redirected to your live site, and obviously, you don’t want that.

Please note that using the MYPHPAdmin method might be preferable if your WordPress database contains custom fields which are not exportable via WXR.

 For those who are using WordPress 2.1+, here’s what you need to do:

  1. Log in to your live blog’s admin panel and navigate to the Manage -> Export section.
  2. If you want to backup every post, comments and category, just select “all” in the “restrict author” drop-down box. If you only want to export posts from one author, select his name. Then, press the “Download Export File” button and save the file onto your disk.
  3. Log in to your local WordPress admin section, navigate to Manage->Import and select the “WordPress” option down on the page.
  4. Click on the “browse” button, select your WXR file and click “upload file and import”. While the process is running, WordPress will ask if you want to create each author’s user name or merge all posts to the admin account. For the sake of simplicity, you may want to assign the posts to your user name if you are simply testing the procedure. If you want to migrate your blog to a new host, you’ll want to have the process recreate the users.

If the procedure fails, it may be that you’ve got a huge WXR file. In this case, edit (or create it if it’s not there) an .htaccess file inside the root of your WordPress installation and add this line:

php_value memory_limit 32M

This should allow the process to handle the file with no problems. 

Now that you’ve finished importing all data, load up your front page and browse your blog locally just like you would do online.

If you find yourself getting stuck during the tutorial, please post your questions in the comments area below.  I’ll do my best to answer them as they’re coming.