Friday, 2005-08-19

Gmail backups

You can back up your Wordpress blog to gmail: here’s a post that explains how.

I’ve been doing this since October last year, here are some gotchas related to that.

This is my setup.

  • Blosxom blog
  • shell account on the blog server
  • gmail address
  • bash shell scripting nous

I run the following script from cron:

#!/bin/sh

HOME=/home/gustaf
DIR=$HOME/backup
DATE=`date +"%Y-%m-%d"`
# set filename extension to something other than ".tar.gz"
FILE=blog-$DATE.bak
MUTT=/usr/bin/mutt
# save crontab 
crontab -l > $HOME/save/crontab
# create backup file
tar czf $DIR/$FILE --exclude public_html/files/big  \
blosxom-data blosxom-plugins public_html bin save
# mail the file
echo ""| mutt -a $DIR/$FILE -s "backup $DATE" <my email>+backup@gmail.com

# prune old files
find $DIR -type f -name "blog-????-??-??.*" -atime +30 -exec rm {} \;

This zips up my blog and plugins, the bin directory, all CSS and .htaccess files, the crontab and my blogroll, and all smaller pics in a tar file. This is then sent to gmail. mutt makes it easy to send attachments from the command line.

The process leaves a bunch of files in the backup directory. All files older than 30 days are pruned.

As of today, the backup file is 1.3M 6.6M. According to the comments to the post referenced above, the gmail limit is 10M. You can add a check if your file gets bigger.

Make sure you can check the mail to the account you’re sending from, if the mail to gmail bounces you want to know about it.

Update 2007-09-11: I renamed the file extension as Gmail has started blocking files with the tar.gz extension. I also added a call to find to prune old files.