- I did this as root:
$ sudo su
, although it may not be necessary. - Download AWS command line tools:
$ curl https://raw.github.com/timkay/aws/master/aws -o aws
- Install:
- Automatically:
$ perl --install aws
- Manually:
$ mv aws /usr/local/bin/ && chmod +x /usr/local/bin/aws
- Automatically:
- Put your AWS credentials in ~/.awssecret with the Access Key ID on the first line and the Secret Access Key on the second line:
$ vi ~/.awssecret
. For example:1B5JYHPQCXW13GWKHAG2 2GAHKWG3+1wxcqyhpj5b1Ggqc0TIxj21DKkidjfz
- Test AWS:
$ aws ls
should show existing buckets.$ aws mkdir bucket
to make a new bucket. - Create a backup script at:
$ vi ~/s3backup.sh
, you may need to adjust paths and flags:#!/bin/bash TIMESTAMP=`date +%Y-%m-%d` DATABASE_NAME=database BUCKET_NAME=bucket /usr/bin/pg_dump --user=postgres --host=localhost ${DATABASE_NAME} > /tmp/${DATABASE_NAME}_${TIMESTAMP}.sql /usr/bin/aws put ${BUCKET_NAME}/${DATABASE_NAME}_${TIMESTAMP}.sql /tmp/${DATABASE_NAME}_${TIMESTAMP}.sql /bin/rm /tmp/${DATABASE_NAME}_${TIMESTAMP}.sql
- Make executable:
$ chmod +x ~/s3backup.sh
. Test by running~/s3backup.sh
. - Setup crontab:
$ crontab -e
with contents to run a weekly backup:0 0 * * 0 /root/s3backup.sh
-
-
Save jackbit/2be8720e54bdfd0ff401 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment