Automatic offsite WordPress backups

Yesterday, I decided to set up a an automated backup solution for my site here.  Basically, it does an sqldump then sends the dump to another server over SCP.

First, I had to enable SSH login without a password in order for SCP to work in a cronjob.  I followed this howto and it worked perfectly.

Then, I created a backup script to be called by cron:

#!/bin/sh

cd /home/backups/collegegeek

FNAME=collegegeek-`date +%F`.sql

mysqldump –add-drop-table -uroot -pPASSWORDHERE collegegeek > $FNAME
bzip2 $FNAME
rm $FNAME
scp $FNAME.bz2 zach@192.168.1.82:backups/
echo “Nightly Backup Successful: $(date)” >> /home/backups/blogbackup.log

This will also leave a copy on the local server on the /home partition.  Note that /home is on a different physical drive than /var, so if the drive with the SQL database goes down, I should have a local copy as well.

This entry was posted in Linux, Tech, blog and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>