Backing up my WordPress Blog on my Mac

Long time readers will know that I just started this blog.

Since I installed this on my Mac Mini, I decided I needed a way to back up the SQL data. If this Mac fails, this blog is toast. Most of what follows applies to any Linux machine.

I wrote a pretty simple script to run the backup. If you want to do something similar, use Terminal on the host Mac (or you can login remotely, but that’s another story). Go to a directory where you keep scripts (maybe “/usr/sbin” – you can do that by typing cd /usr/sbin).

Then create a file named something like blogbackup.sh (to do that, type vi blogbackup.sh).

Then, since you’re in the editor vi, you’ll need to press “a” then paste the following, replacing password with your SQL password, and backup with your secondary hard drive (or replacing /Volumes/backup with a different location on your primary drive, but that defeats half the purpose . . .).

 #!/bin/sh
mysqldump --add-drop-table -ppassword wordpress | bzip2 -c > blog.bak.sql.bz2
cp blog.bak.sql.bz2 /Volumes/backup/blog.bak.sql.bz2

To save in vi, press ESC then :w then :q.

Set the permissions to be sure this will execute:

chmod 777 blogbackup.sh

chmod +x blogbackup.sh

(I confess to not being a chmod expert, so those commands might be overlapping.)

To test out the script, type: 

 ./blogbackup.sh

From there, you should set up a recurring crontab to take care of the job. I set mine up as the superuser so that it would run without interruption. To do that, you’ll need root access – that’s a whole different story. But once you have it, here’s what you do:

crontab -e

brings up the list of cron jobs. To add a new one, paste in a line like this:

10 2 * * * /usr/sbin/blogbackup.sh

That basically says at 2:10 AM, run that script everyday. Save and quit with :w then :q.

No Responses to “Backing up my WordPress Blog on my Mac”

No feedback yet.

Leave a Reply

Name Email Website URI