Simple ubuntu backup to S3
Posted on Sat 14 January 2012 in Tech
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. So basically all I need it to do was backup my sites(filesystem and mysql databases) and some config for lighttpd.
The post I'm basing this off is here.
- Install automysqlbackup using apt
sudo apt-get install automysqlbackup
- Run automysqlbackup as root(just to give it a test)
sudo automysqlbackup
-
Double check the databases are being backed up you should see daily, weekly and monthly under /var/lib/automysqlbackup with the appropriate databases.
-
Now use this script to backup all the specific folders you want.
# 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=
-
Add your own specific access key stuff and give it a test
-
Then add it to a cronjob
0 0 * * * /usr/sbin/automysqlbackup && /root/s3_backup