How to: Backup and Restore your WordPress Blog


Advertisements

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.





79 Responses to How to: Backup and Restore your WordPress Blog

  1. Excellent topic, Kiltak. I have had to move my blog(s) to three different servers now and have had both successes and partial failures restoring my WordPress blogs.

    One problem I had was possibly due to the tarring and compression of the sql database. Many characters such as doublespaces or quotation marks became corrupted. When restored, these characters were replaced with a small square character.

    I almost panicked at the thought of having to manually replace all those characters until I found the search and replace plugin for wordpress here:
    http://wordpress.org/extend/plugins/search-and-re

    Otherwise my restorations of my blogs have been quite successful.

    • Yeah, I know what you mean. Some of these problem are associated with how the WordPress team switched the supported character set from Latin1 to UTF-8.. So if you've been running your blog for a while, your data was formated using Latin1 encoding initially.. when your WordPress blog got updated to version 2.2, the format changed to UTF-8.

      Most people didn't notice though, and their blog looked the same even after this. The problem came when they decided to restore some backed up data….. that's where they started to see some garbled characters into their content, just like you did.

      There is a wordpress plugin to fix this issue… but I didn't try it myself..

      http://g30rg3x.com/utf8-database-converter/

      Use at your own risk folks :)

  2. Excellent topic, Kiltak. I have had to move my blog(s) to three different servers now and have had both successes and partial failures restoring my WordPress blogs.

    One problem I had was possibly due to the tarring and compression of the sql database. Many characters such as doublespaces or quotation marks became corrupted. When restored, these characters were replaced with a small square character.

    I almost panicked at the thought of having to manually replace all those characters until I found the search and replace plugin for wordpress here:
    http://wordpress.org/extend/plugins/search-and-re

    Otherwise my restorations of my blogs have been quite successful.

    • Yeah, I know what you mean. Some of these problem are associated with how the WordPress team switched the supported character set from Latin1 to UTF-8.. So if you've been running your blog for a while, your data was formated using Latin1 encoding initially.. when your WordPress blog got updated to version 2.2, the format changed to UTF-8.

      Most people didn't notice though, and their blog looked the same even after this. The problem came when they decided to restore some backed up data….. that's where they started to see some garbled characters into their content, just like you did.

      There is a wordpress plugin to fix this issue… but I didn't try it myself..

      http://g30rg3x.com/utf8-database-converter/

      Use at your own risk folks :)

  3. I have an easier method. There's a plug-in called "WordPress Database Backup" that is available on the net @ http://www.ilfilosofo.com/blog/wp-db-backup/

    It provides a very nice way to back-up your SQL database! It will not only back-up your main WP tables, but you can configure it to back-up *any table that is with-in your WP database. The biggest plus, in my mind, is that you can also have it do *scheduled back-ups of your database. For instance, I have the system send a copy of the database as an e-mail attachment to my gmail address.

    I'm not sure about re-importing, that might have to be done via phpMyAdmin as there's no tab for that int he back-up interface.

    • Yeah, the WP database plugin is nice… but you have to import the data back using phpMyAdmin. While doing this is fairly easy for technical people, it might scare the average, non-technical user.

      Thanks for the comment adam!

  4. I have an easier method. There's a plug-in called "WordPress Database Backup" that is available on the net @ http://www.ilfilosofo.com/blog/wp-db-backup/

    It provides a very nice way to back-up your SQL database! It will not only back-up your main WP tables, but you can configure it to back-up *any table that is with-in your WP database. The biggest plus, in my mind, is that you can also have it do *scheduled back-ups of your database. For instance, I have the system send a copy of the database as an e-mail attachment to my gmail address.

    I'm not sure about re-importing, that might have to be done via phpMyAdmin as there's no tab for that int he back-up interface.

    • Yeah, the WP database plugin is nice… but you have to import the data back using phpMyAdmin. While doing this is fairly easy for technical people, it might scare the average, non-technical user.

      Thanks for the comment adam!

  5. Pingback: Holy Jumping Wordpress Themes Batman!

  6. Good man! I prefer download the whole folder of /contents and keep in my hard drive. Sometimes scare to use plug in for backup. :)

    • Hey Jeremy, backuping the content of your wordpress folder doesn'T back up your data… your data (the posts themselves) are stored into a mysql database. Do back these up, you have to use one of the methods enumerated in the article.

  7. Good man! I prefer download the whole folder of /contents and keep in my hard drive. Sometimes scare to use plug in for backup. :)

    • Hey Jeremy, backuping the content of your wordpress folder doesn’T back up your data… your data (the posts themselves) are stored into a mysql database. Do back these up, you have to use one of the methods enumerated in the article.

  8. "Log in to your web server via FTP and dump your entire WP-Content folder"

    Where it is? I opened my cpanel but I don't have I clue how to log in and dump it. Thank you

  9. “Log in to your web server via FTP and dump your entire WP-Content folder”

    Where it is? I opened my cpanel but I don’t have I clue how to log in and dump it. Thank you

  10. To Matej

    –> in your cpanel go to file then click file manager. then you will see all file in your own file folder, click public html .. you will see your wordpress file such as wp-admin, wp-content, and wp-includes. I think the best way is to use ftp program such as cuteftp… drag all you wp-content to your local hard disk.

    Hope this help

  11. To Matej
    –> in your cpanel go to file then click file manager. then you will see all file in your own file folder, click public html .. you will see your wordpress file such as wp-admin, wp-content, and wp-includes. I think the best way is to use ftp program such as cuteftp… drag all you wp-content to your local hard disk.
    Hope this help

  12. I followed the steps and it gives me the following error:

    Fatal error: Call to undefined function wp_ozh_wsa() in C:xampphtdocswordpresswp-content hemesmandigo-14header.php on line 341

  13. I followed the steps and it gives me the following error:

    Fatal error: Call to undefined function wp_ozh_wsa() in C:xampphtdocswordpresswp-contentthemesmandigo-14header.php on line 341

  14. I followed the steps and it gives me the following error:

    Fatal error: Call to undefined function wp_ozh_wsa() in C:xampphtdocswordpresswp-contentthemesmandigo-14header.php on line 341

  15. This works fine except – for me the category and page id's have changed. This is a problem since I use the id's in menus and php if statements to control what is displayed on a page.

    I guess I will try using phpmyadmin and see it that works better.

  16. This works fine except – for me the category and page id’s have changed. This is a problem since I use the id’s in menus and php if statements to control what is displayed on a page.

    I guess I will try using phpmyadmin and see it that works better.

  17. Hi all,

    I have tried like Adam to use the "WordPress Database Backup" component. I have almost succeed in this, I would like to share my experience here (And ask some question too :) )

    I want to make an exact copy of my live WordPress 2.5.6 Blog, on my PC (Win Xp + Xampp).

    –Database–

    With the pugling, I ran a database backup and save the resulting .sql file locally on my pc.

    I edit then the SQL export and change the entries with the live site url to the local target url:

    http: http://www.blog.com >> http:localhostxampp
    estore

    I create a database through phpadmin, named wp_restore, in UTF8_unicode_ci format.

    I launched an Import of the modified SQL file : all is ok.

    –Files–

    I copy the whole blog files and folders locally on the xampp
    estore folder.

    I modify then wp-config.php file to match the local values:

    define('DB_NAME', 'wp_restore');

    define('DB_USER', 'joomla');

    define('DB_PASSWORD', 'joomla');

    define('DB_HOST', 'localhost');

    define('DB_CHARSET', 'utf8');

    I access then the local site on

    http:localhostxampp
    estore and I got the exact woring copy of my live site.

    but…

    I can not access the WordPress admin area, I got this error :

    Warning: Cannot modify header information – headers already sent by (output started at C:Xampphtdocsxamppvinschateauxlogrestorewp-config.php:1) in C:Xampphtdocsxamppvinschateauxlogrestorewp-includespluggable.php on line 770

    I guess I'm not far from it, and I wonder if someone has done the same kind of process and find out the same issue ? Any idea where I got it wrong ?

    Thanks

  18. Hi all,

    I have tried like Adam to use the "WordPress Database Backup" component. I have almost succeed in this, I would like to share my experience here (And ask some question too :) )

    I want to make an exact copy of my live WordPress 2.5.6 Blog, on my PC (Win Xp + Xampp).

    –Database–

    With the pugling, I ran a database backup and save the resulting .sql file locally on my pc.

    I edit then the SQL export and change the entries with the live site url to the local target url:

    http: http://www.blog.com >> http:localhostxampprestore

    I create a database through phpadmin, named wp_restore, in UTF8_unicode_ci format.

    I launched an Import of the modified SQL file : all is ok.

    –Files–

    I copy the whole blog files and folders locally on the xampprestore folder.

    I modify then wp-config.php file to match the local values:

    define('DB_NAME', 'wp_restore');

    define('DB_USER', 'joomla');

    define('DB_PASSWORD', 'joomla');

    define('DB_HOST', 'localhost');

    define('DB_CHARSET', 'utf8');

    I access then the local site on

    http:localhostxampprestore and I got the exact woring copy of my live site.

    but…

    I can not access the WordPress admin area, I got this error :

    Warning: Cannot modify header information – headers already sent by (output started at C:Xampphtdocsxamppvinschateauxblogrestorewp-config.php:1) in C:Xampphtdocsxamppvinschateauxblogrestorewp-includespluggable.php on line 770

    I guess I'm not far from it, and I wonder if someone has done the same kind of process and find out the same issue ? Any idea where I got it wrong ?

    Thanks

  19. Hi again,

    I just found out why my admin access was broken. I have spoted an invisible character just at the begining of the wp-config.php file, before the <?php tag.
    @#@@#@~@#@~@# !

    I have since tried out several time my process, it’s working fine, I get a working copy of my live sites.

    Hope this may help…

  20. Hi again,

    I just found out why my admin access was broken. I have spoted an invisible character just at the begining of the wp-config.php file, before the <?php tag.

    @#@@#@~@#@~@# !

    I have since tried out several time my process, it's working fine, I get a working copy of my live sites.

    Hope this may help…

  21. I am trying to set up a local copy of my blog. I’ve got the basics set up ok but want to import the posts etc. I’ve created and saved a WXR export file using the “live” blog Dashboard. When I try to import to localhost, again using Dashboard, I get an invalid file error. “Live” site uses 2.6 Localhost uses 2.7. I’m intending moving to a new server using 2.7

    I’ve just noticed that the export file created is only 3KB which I think can’t be right

  22. I am trying to set up a local copy of my blog. I've got the basics set up ok but want to import the posts etc. I've created and saved a WXR export file using the "live" blog Dashboard. When I try to import to localhost, again using Dashboard, I get an invalid file error. "Live" site uses 2.6 Localhost uses 2.7. I'm intending moving to a new server using 2.7

    I've just noticed that the export file created is only 3KB which I think can't be right

  23. Install Technosailor’s WXR export plugin link not working it seems he has removed the plugin from download directory.

    Can any one provide me that?

  24. Install Technosailor’s WXR export plugin link not working it seems he has removed the plugin from download directory.

    Can any one provide me that?

  25. Pingback: How to Backup a Wordpress Blog

  26. Thanks for these excellent instructions! I can't believe how useless WordPress's own "Codex" is. That little line about having to manually enter the localhost/blog-directory in wp-config.php, for instance. No mention of that. Or if there is, it was buried far enough so I didn't see it. I could NOT figure out why my damn local install kept flipping me off to my web site.

    I wound up deleting the whole local install and starting over. Only this time I avoided WordPress and just googled for instructions. Which brought me here. Thanks heavens.

    One thing: when I try to import the blog contents ("wxr", but has a .xml extension) I get an error message about not being able to write to wp-contents/uploads. I have to make the directory, and set permissions wide open (777). Then it works. On the web site itself, that means going back in to change back to something reasonable, like 755. Is there some more elegant way to handle this, or is this just the way it's going to be on a linux machine? (I run Ubuntu.)

  27. Thanks for these excellent instructions! I can’t believe how useless WordPress’s own “Codex” is. That little line about having to manually enter the localhost/blog-directory in wp-config.php, for instance. No mention of that. Or if there is, it was buried far enough so I didn’t see it. I could NOT figure out why my damn local install kept flipping me off to my web site.

    I wound up deleting the whole local install and starting over. Only this time I avoided WordPress and just googled for instructions. Which brought me here. Thanks heavens.

    One thing: when I try to import the blog contents (“wxr”, but has a .xml extension) I get an error message about not being able to write to wp-contents/uploads. I have to make the directory, and set permissions wide open (777). Then it works. On the web site itself, that means going back in to change back to something reasonable, like 755. Is there some more elegant way to handle this, or is this just the way it’s going to be on a linux machine? (I run Ubuntu.)

  28. Postscript: I don't seem to have a solid connection to the database. It can't find imported posts, but neither can it find new ones! I tried writing a new post, called "testing". The permalink was http://localhost/wp/2009/03/testing. As the newest post. it's accessible on the index page, but clicking on the title, which should take you to the post's permalink page, says "/ wp/2009/03/testing/ not found on this server." It looks like there's a space just before the "wp" but there's none in the path I entered in wp-config.php.

    I tried looking at "wp_posts" in the database using phpmyadmin, but I can't make head or tail of it. It's probably another line that needs to be in wp-config.php? ??

  29. Postscript: I don’t seem to have a solid connection to the database. It can’t find imported posts, but neither can it find new ones! I tried writing a new post, called “testing”. The permalink was http://localhost/wp/2009/03/testing. As the newest post. it’s accessible on the index page, but clicking on the title, which should take you to the post’s permalink page, says “/ wp/2009/03/testing/ not found on this server.” It looks like there’s a space just before the “wp” but there’s none in the path I entered in wp-config.php.

    I tried looking at “wp_posts” in the database using phpmyadmin, but I can’t make head or tail of it. It’s probably another line that needs to be in wp-config.php? ??

  30. Thanks for a great info. I wish I made a back-up of wp-blog. My hosting provider, suspended my account without any reason. I bought mine in digital point, lately I was informed that 90% of the sellers are scammers, so be very picky when you buy.

    Thanks again sharing this info. I'll definitely backup my data often.

  31. Thanks for a great info. I wish I made a back-up of wp-blog. My hosting provider, suspended my account without any reason. I bought mine in digital point, lately I was informed that 90% of the sellers are scammers, so be very picky when you buy.

    Thanks again sharing this info. I’ll definitely backup my data often.

  32. Thats a really useful article. My wordpress also got stuck a couple of times and I could'nt properly restore the content during re-installations. This helped me out better. Thanks for the support.

  33. Thats a really useful article. My wordpress also got stuck a couple of times and I could’nt properly restore the content during re-installations. This helped me out better. Thanks for the support.

  34. Guys I am really in bad shape here. I need to restore a wordpress blog, and will hire an IT guy to do it. But I am not sure I have the files. I remember doing a backup in July that is compressed to 70 megs, and after I unzip the RAR it ends up 85 megs. Is it possible that this is most of my blog? It was mostly text and pic for three years or so. Or am I dreaming? The file is called "blog backup" and after I expand it it has folders like blog, logs, phpmyadmin, tmp, wordpress, and yahoo_site_admin. I would be very, very grateful if you would tell me that this might do the trick so my IT guy can get most of my blog back. But be straight with me- is this just a dream? And yes, next time I will backup more often!!!!!!! ~Joe

  35. Guys I am really in bad shape here. I need to restore a wordpress blog, and will hire an IT guy to do it. But I am not sure I have the files. I remember doing a backup in July that is compressed to 70 megs, and after I unzip the RAR it ends up 85 megs. Is it possible that this is most of my blog? It was mostly text and pic for three years or so. Or am I dreaming? The file is called “blog backup” and after I expand it it has folders like blog, logs, phpmyadmin, tmp, wordpress, and yahoo_site_admin. I would be very, very grateful if you would tell me that this might do the trick so my IT guy can get most of my blog back. But be straight with me- is this just a dream? And yes, next time I will backup more often!!!!!!! ~Joe

    • Yes and no.. I'd also use the wordpress database backup plugin on top of this method.. just in case.

      And you need to do another backup of your wordpress theme, plugin folder, and upload folder, else even though you'll have all your content, you'll lose your blog layout and all pictures that were inserted in posts.

  36. So I'm a newbie with no desire to become a geek (seky though y'all may be). So tell me: will this technique at this URL allow me to restore my WP blog?:

    • Yes and no.. I’d also use the wordpress database backup plugin on top of this method.. just in case.

      And you need to do another backup of your wordpress theme, plugin folder, and upload folder, else even though you’ll have all your content, you’ll lose your blog layout and all pictures that were inserted in posts.

  37. Hi,

    I keep getting the following error when trying to export:

    Fatal error: Maximum execution time of 30 seconds exceeded in /~/~/~/wp-includes/plugin.php on line 385

    Anyone know of a fix for it?

  38. Hi,

    I keep getting the following error when trying to export:

    Fatal error: Maximum execution time of 30 seconds exceeded in /~/~/~/wp-includes/plugin.php on line 385

    Anyone know of a fix for it?

  39. Great post!

    I do have a question though.

    I have a few local blogs running using wordpress mu. I now want to add a local copy of a live blog.

    I can´t overwrtite my wp_content folder with my live one as wpmu only has 1 wp_content folder for all blogs (as far as I can see).

    Can you tell me how to backup & restore this blog locally with wpmu?

  40. Great post!
    I do have a question though.
    I have a few local blogs running using wordpress mu. I now want to add a local copy of a live blog.
    I can´t overwrtite my wp_content folder with my live one as wpmu only has 1 wp_content folder for all blogs (as far as I can see).

    Can you tell me how to backup & restore this blog locally with wpmu?

  41. my web site was closed , I made a backup and i ahve a rss file that I want to see it's contents !

    how can I do that ?

    thanks

  42. my web site was closed , I made a backup and i ahve a rss file that I want to see it’s contents !
    how can I do that ?

    thanks

  43. Hi Friends

    I am new to wordpress
    I have taken backup of my live site and restored it locally.
    when i tried to login from localhost its getting redirected to live site
    As suggested by the above article i have added these code of lines at bottom in wp-config.php

    define(‘WP_HOME’, ‘localhostMysite’);
    define(‘WP_SITEURL’, ‘localhostMysite’);

    and i am getting this

    Fatal error: Undefined constant '‘localhostMysite’' in C:wampwwwMysitewp-config.php on line 94

    I am using

    wordpress-3.2.1.
    Wamp Server.

    I guess, I'm not far of it. Hav anyone come across the same situation.
    i have done exactly as the above article suggested.

    Plz help me
    Thanks in advance

  44. hey! I'm going to ask a really stupid question! I'm fairly new to blogging and wordpress – I've been blogging my novel "In That Other Dimension" for a few months now. But why would you need to back up the blog? Is it possible that the blog can be lost by wordpress (if so, would backing up then restoring restore all your follows and followers) or is this used mainly for if you want to leave wordpress and move to a different blogsite?
    Cheers, Matty