Blogging is a great way to prepare content for the Internet without spending a lot of time worrying about the details of website administration and content formatting. But it’s easier to put content in a blog than it is to get it out of the blog for backup purposes. WordPress has a way to export the postings and comments into an XML file for local storage, but since you have to remember to do it periodically, you’re likely to lose a few postings if something goes awry on the server and you haven’t done a backup for a while. And the XML export doesn’t save the images you may have uploaded to your web host because those are not stored in the same database as the posts and comments.
I started looking around for a WordPress backup solution and was unable to find anything that looked like a good fit. WordPress posts and comments are not located on your GoDaddy web host. They are on a separate host/database that GoDaddy sets up when you install WordPress as an application. I download my website’s changed files to my local PC using a scheduled WS-FTP session. I generally use FileZilla for FTP and would like to use it instead of WS-FTP, but it doesn’t have a way to automate periodic downloads so I’m forced to use WS-FTP for my backups. WS-FTP isn’t free, but until FileZilla supports recurring automated scheduling of uploads/downloads, it’s the only way I know to do this. The FTP backup takes care of downloading my blog images and other website files but not the actual blog postings or comments.
GoDaddy has a web interface to set up cron jobs and I was pretty sure I could back up my blog’s database to the same WordPress directory that stores my blog’s theme and php files using a script to dump the database. A database dump could put a copy of the postings and comments in SQL format in a location where my WS-FTP job could find it and download it on a regular basis.
I figured others would like to know how to do this, so I’ve written up a short ‘how to’ here.
I will assume you have are using GoDaddy’s Linux hosting and have an SSH login and know your way around a Linux system. If not, you’ll need some help from a Linux expert who can understand the instructions below.
First of all, you can use a single command to perform the WordPress database backup manually, to make sure it’s working. Here is an example of mine which I store in a file called “wpbackup” located in the wordpress directory (please note, this command should all be on a single line):
mysqldump --add-drop-table -h mysqlhostname -u mysqlusername -pmysqlpassword mysqldatabasename | gzip -c > $HOME/html/wordpress/yourblogbackup.sql.gz
If you can’t remember the mysql hostname, username, password, and databasename because GoDaddy generates them for you automatically when you install WordPress as an application, you can find them all in the /wordpress/wp-config.php file. Please note that there is no space between the -p and the password. All other spaces are required. The mysqldump command takes all the data from your wordpress blog database and puts it in a SQL format that allows you to re-import it should the need arise. The “| gzip -c” compresses the database since SQL is made of plain text and it compresses pretty well, probably 4:1 or better. If you don’t want to use it, you can leave it out.
You will need to confirm that this is working properly. Just make sure it’s executable and type in “./wpbackup” to run it. Then you can do a “gzip -d” on the yourblogbackup.sql.gz file to turn it back into sql statements so you can browse the contents of the output file. Once you’re sure it’s working, then you are ready to set up the cron job. It is possible set up a cron job manually by editing the crontab file in your home directory, but GoDaddy has a web interface that allows you to set up and manage cron jobs without having to know how to edit the crontab file directly. You can see the result in the crontab file by looking at it in your home directory after you set it up if you’re curious.
Just go to the Hosting Control Center -> Content -> Cron Manager
Set up the job to make the wpbackup script execute on a regular basis. It should be done frequently enough to insure that your FTP download is getting a recent backup of the database.
With the cron job executing on a regular basis, and a scheduled FTP download of your website, the most recent content from your blog will get backed up so that should misfortune strike, you’ll be able to restore it to its original condition. The two commands to do that are:
gzip -d yourblogbackup.sql.gz
mysql -h mysqlhostserver -u mysqlusername -pmysqlpassword mysqldatabasename < yourblogbackup.sql
(please note, the mysql command should be all on one line)
If you found a better or easier way to backup your WordPress blog, please leave a comment with a link to your solution.