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.
- themes
wp-content/themes
- plugins
wp-content/plugins
- 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…
- 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
- 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: