Posts tagged ‘wordpress’

WordPress Complete Backup Solution

Backing up your data is very recommendable (if you don’t do it start now!) and can save you a few headaches. This posts explains how to backup your WordPress installation. You need to take care of 2 things:

  • The WordPress database
  • The WordPress files (plugins, themes, etc.).

For backing up the database I recommend the wp-db-backup plugin, which can be configured to send a daily backup of your database to your mail account.

If for any reason you lose your WordPress data, you can retrieve the backup from your mail and restore it with the following command:

mysql --default_character_set=utf8 -h hostname -u username -p database < mybackup.sql

You can obtain the host, username and database name from wp-config.php. The encoding is important. If you don’t specify it your restored posts can look pretty messy.

Following the previous steps your posts and configurations are protected and chances of losing them are very low. The next step is to backup the WordPress files (plugins, themes, config files, etc.). To perform this task I recommend rsync. This excellent tool is included on Unix-based systems (Linux, Mac, etc.). There are binaries for Windows also. Rsync performs folder synchronization (bot remotely and locally). One of its main advantages is that it does incremental backups (i.e. it only transfers the changed files). I use rsync to synchronize my remote WordPress installation with a local folder. This way, every time something changes in the server, these changes are transferred to my local computer. The rsync syntax is as follows:

rsync -avvb --delete --backup-dir=/Users/jorge/rsync/backup_$(date +%y%m%d%H%M) username@somebox.bluehost.com:/home4/username/public_html /Users/username/bluehostbackup/

It’s a good idea to schedule a cron job to run that command daily (or hourly if you change things quite often).

And that’s it. Making use of wp-db-backup and rsync you get an easy and fast backup solution that can save you a lot of trouble.