Nov 022010
 

For reasons I won’t bore you with, I had a need to start all over again with my web server. The only valuable item on there was my blog. So I looked into how to make a complete backup as painless as possible. There are several things to backup though, not just your database of posts, replies etc.

  1. themes wp-content/themes
  2. plugins wp-content/plugins
  3. all your media content (photos, mp3, videos) wp-content/uploads

(If I tell the truth though, I downloaded the whole WordPress folder to my local PC, as well as the gzipped database backup. I don’t trust computers an inch, having worked with them for >30 years.)

Those are doubtless the things most people are likely to forget about or miss altogether. I have quite a lot of photos in my blog and if I hadn’t backed up the /wp-content folder, the photography section would have become utterly worthless. Since a lot of time and effort went into it, I backed it up.

Backing Up
Having not done much SQL work before, the database part was the most scary. So let’s start with that…

The good news for the actual backup is that there are plugins that will do this for you. I used WordPress Database Backup. And on my installation (WP 3.01) it worked fine. The only sight niggle is that one or two special characters got substituted, but that’s a price I’m willing to pay for not having to recreate or simply dispose of 50+ content-rich pages. It might even have been down to me for not choosing the correct character set when I created the new MySQL database (who knows/cares?).

So this plugin will allow you either to store the backup file in a sub-folder on your server, or to download it to your PC. It can also schedule automatic backups to be emailed to you as well. 😀

So, in addition to database backup, I downloaded the entire file structure of my WordPress blog in the hope that I would avoid losing anything vital.

Server Rebuild and New WP Installation
I followed the WordPress Installation documentation, which is really good. No need to reinvent the wheel by duplicating that here. The only niggle I had was that my new installation (Ubuntu 10.04 server and Virtualmin) wouldn’t allow WordPress to create an .htaccess file in the WordPress folder, so I had to do that myself before permalinks would work. But I’m getting ahead of myself. You’re dying to hear what happened with the database restore aren’t you? :doctor:

Database Restore
Having rebuilt WordPress, it was time to restore the database. :skeleton: I uploaded the gzipped backup file into a sub-folder of the WordPress directory. Using SSH, I navigated to that folder and unzipped it with
gunzip backupfile.sql.gz

This unzipped the file to backupfile.sql Next came the hocus pocus MySQL bit
From within the same folder I keyed…
mysql -h localhost -u DB-username -p New-DatabaseName < backupfile.sql

Where localhost is MySQL host name, DB-username is the username you set for your new WordPress MySQL user, New-DatabaseName is the name of your new WordPress database and backupfile.sql is your unzipped backup of your old database.

It then asks for the password for your WordPress database user. Type that in and your backup database contents will be dumped into the new empty database. Hallelujah O:-) it works.

But still couldn’t see any content in the blog apart from on the main page and in the admin control panel. There were two reasons for this…

  1. I hadn’t yet set up permalinks – and all my old blog entries were permalinked. WordPress itself told me that an .htaccess file was needed to set up permalinks properly and that the new system wasn’t allowing it to create this override file 8-). That was easily solved by uploading the .htaccess file from the old installation, after checking the directives in it were the same as the ones WP was telling me to use
  2. I hadn’t uploaded any themes and the database was telling WP to use Suffusion themes that weren’t yet on the server. Easily solved by uploading the suffusion folder into wp-content/themes For some reason it changed my background colour back to the default settings, but I can live with having to change that back again.

After that, the basic blog worked fine, but no media and no plugins. So it was necessary to upload all the media files back into wp-content/uploads (134 Megabytes in my case – hurrah for broadband).

So having uploaded all the media, the photos appeared fine, but the audio and video didn’t. That’s because they use plugins to play them. What remained to be done was to upload selected plugins from the wp-content/plugins backup folder. After reactivating the appropriate plugins, everything worked as it should. You can’t possibly know how much of a relief that is. (Athough I did have an XML backup copy as well.)

There’s one thing I’ve forgotten to do, so I’ll go and do that in a minute. That’s to increase the upload limit on php so I can upload larger files to the blog.

I’ve documented this so it might help someone else and in case I need to refer to it again myself. :rotfl:

  2 Responses to “How To Backup and Restore WordPress 3.01 Blog”

  1. Thank you for a detailed description, it was interesting to read about your experience :-). Why did you prefer to make a new WordPress installation from scratch? I’d rather simply copy the entire WordPress folder from the old webserver to the new one. Also, for any database manipulations, I normally use phpmyadmin, which not only makes backup and restore tasks easy, but also lets you do other useful things such as run SQL requests, e.g. to delete all spam comments.
    -Roman

  2. Hi Roman,

    If simply copying the folders over works, that would obviously be the easiest way. I’m not sure that it does though, so preferred to do a clean install. Not only that, but there were some changes made in the server configuration, which was partly the reason for the “clean start” on the server in the first place. Alsom my old WP was “upgraded” 3.01 from 2.9.0 then 2.9.2 so I preferred, with the new server, to have a completely fresh new install in case there was any left over “debris” from previous versions.

    I didn’t have phpmyadmin installed. Anyway, it’s only two or three database commands, not rocket science. Even if you’re using admin tools it’s still useful to have an idea of what lies underneath them.

    I’ve learnt several programming languages over the last 30 years, including BASIC, REXX, PERL so a few command line commands is not so intimidating. (Commodore Pet 8k was the first computer I was ever let loose on at the age of about 10). 😎

Leave a Reply to alexeames Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)