Archive for April, 2004

WordPress Backup Shell Script

Thursday, April 29th, 2004

For those seeking to backup their WordPress installations on a nightly basis, I have decided to publish the following shell script.

Below, any instance of a tilde [~] indicates /home/[username]/. Referencing to user root is key to this. You could change it to /home/[username]/ if you so chose.

#!/bin/csh -f

# Determine current date
setenv CURDATE date +%Y%m%d

# Backup all WP databases to compressed, dated file in home directory
mysqldump -q -e -hlocalhost -u[user] -p[pass] [database] | gzip - > ~/${CURDATE}_db-backup.sql.gz

# Backup WP files to compressed, dated file in home directory
cd ~/path/to/wp-files/
tar cf - . | gzip - > ~/${CURDATE}_files.tar.gz

Any data in [brackets] should be filled in, sans brackets.

This should sit in userroot, chmod’d to 755 to be executable.

You will get errors for all files in wp-uploads on the second TAR run for the backups. If you don’t want backups of your WP files but are more concerned about the backup of the database, remove everything from the last comment on down.

I personally get an email sent to me to verify that there were no errors in the running of the script. I also use FTP Voyager’s scheduler to do a Move Down on the backups to a local machine. When I can get a RAID box running at home, I’ll be dumping it to that, since I trust RAID more than a single-point-of-failure HD machine. :)