Simple ubuntu backup to S3

Mon 22 November 2010

image0 After browsing the web for ages to find a decent solution to backup my server to amazon s3 I finally came across one and I'm just throwing it up here.

Reqs:

So basically all I need it to do was backup my sites(filesystem and mysql databases) and some config for lighttpd.

Implementation:

The post I'm basing this off is here

  1. Install automysqlbackup using apt

    sudo apt-get install automysqlbackup

  2. Run automysqlbackup as root(just to give it a test)

    sudo automysqlbackup

  3. Double check the databases are being backed up you should see daily, weekly and monthly under /var/lib/automysqlbackup with the appropriate databases.

  4. Now use this script to backup all the specific folders you want.

#!/bin/sh
# Export some ENV variables so you don't have to type anything
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export PASSPHRASE=
# Your GPG key
GPG_KEY=;
# The source of your backup
SOURCE=/
# The destination
# Note that the bucket need not exist
# but does need to be unique amongst all
# Amazon S3 users. So, choose wisely.
DEST=s3+http://
# The duplicity command and options
duplicity
    --encrypt-key=${GPG_KEY}
    --sign-key=${GPG_KEY}
    --volsize=250
    --include=/var/www
    --include=/home
    --include=/etc/lighttpd
    --include=/var/lib/automysqlbackup
    --exclude=/**
    ${SOURCE} ${DEST}
# Reset the ENV variables. Don't need them sitting around
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export PASSPHRASE=
  1. Add your own specific access key stuff and give it a test
  2. Then add it to a cronjob

0 0 * * * /usr/sbin/automysqlbackup && /root/s3_backup

Category: Projects Tagged: amazon s3 ubuntu coding devops

comments


Page 1 of 1