WordPress automated backup

I finally sat down and wrote a little script to automatically backup my wordpress site and database. My site is hosted by pcextreme.nl, a nice Dutch startup providing hosting services that are perfect for a small site like mine. Part of the package they have is shell access via ssh, which makes this very straightforward. I use two scripts that do all the work:


mysqldump -u user -ppassword \
     -h host db --single-transaction \
     | gzip -9 > ~/wordpress.sql.gz

This script is stored in my home dir on the web server. The –single-transaction is needed to get rid of an error I ran into. I run it remotely using a second script backupsite.sh:

date >> $BACKUPDIR/sitebackup.log
ssh user@host sh ~/dumpdb.sh
rsync -i -v -a --delete \
     user@host:~ $BACKUPDIR \
     >> $BACKUPDIR/sitebackup.log

This first backups the db remotely and then rsyncs everything I have on the server to a local directory. This local directory in turn is backed up by Time Machine, which provides me with nice snapshots of my site. For this to work without interaction, I have of course set up ssh authentication using my public key. I keep a little log in sitebackup.log to keep an eye on whether this all continues to work.

Anyway, nice opportunity to show of the wp-syntax plugin that I finally got around to installing in wordpress and which was actually the whole point of this blog post.

2 Replies to “WordPress automated backup”

Leave a Reply