Backing up WordPress
One of the more important jobs in running a WordPress site (or any site for that matter) is backing up.
There are two parts to this – the files and the database.
Not all files need to be backed up, as in the event of catastrophic failure, the core WordPress files can be restored using the standard installation. However the contents of the wp-contents folder are critical, as this is where the images, plugins etc are kept. Granted, plugins also can be restored using available files from the Web but restoring them from a backup can save a lot of time and effort.
I experimented with several plugins to do my backing up, but had to abandon all as they were unreliable, unworkable or very resource hungry. I had to find an alternative method, as the idea of connecting to several sites, and doing an FTP download plus doing a PhpMySQLAdmin dump each and every day was a non-runner.
I decided that Cron was my solution.
I set up a couple of small files – one to compress the contents of wp-content and the other to do a mysqldump.
/bin/tar –czf /usr/local/hosts/webspace/httpdocs/backups/backup-‘date +%d.%m.%y’ .tar.gz /usr/local/hosts/webspace/httpdocs/www/wp-content
/usr/bin/mysqldump –host=dbserver –user=dbusername –password=dbpassword databasename –quick > /usr/local/hosts/webspace/httpdocs/backups/backupdb-‘date +%d.%m.%y’ .sql
(need I point out that the paths, names and passwords are not the actual ones used?!)
I saved both files on the server and then set up a Cron Tab to run each file.
This worked perfectly on two of the sites I was testing on, but the third refused to work properly. The ‘mysqldump’ function threw up an empty file each time, despite the code being identical in structure across all three sites.
It took a while to find the problem, but I eventually solved it. It didn’t accept the password for the database as the password started with an ampersand ‘&’. I tried various methods, such as escaping the ampersand and inserting quotes around the password but each time it failed. In the end, I took the simple route – I set up an additional user for the database and gave that user a slightly simpler password. It worked!
I now have a series of sites set up and all are running smoothly. Because of the flexibility of Cron I could set the backups to run anywhere from once a minute to once a year. However I have chosen a more sensible option. The databases are backed up every night and the files are backed up every week. That should be sufficient?
My next job is to refine the Files backup to ignore all cached files, as they are very bulky and aren’t necessary for a restore anyway.
Backing up WordPress — No Comments
HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>