Last active
July 28, 2016 02:56
-
-
Save riyadhalnur/81b041200e2562513740 to your computer and use it in GitHub Desktop.
Take a snapshot of your RethinkDB using shell script and upload to S3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Remember to install the Python client drivers for RethinkDB to use dump | |
# http://www.rethinkdb.com/docs/install-drivers/python/ | |
DB="" # name of the database to back up | |
APP="" # file name prefix for dump archive | |
TIMESTAMP=`date +%F-%H%M` | |
RETHINKDUMP_PATH="/usr/bin/rethinkdb" | |
BACKUPS_DIR="/home/me/backups/$APP" | |
BACKUP_NAME="$APP-$TIMESTAMP" | |
S3_KEY="" | |
S3_SECRET="" | |
S3_BUCKET="" | |
AWS_PATH="/backups" | |
export LC_ALL=C | |
mkdir -p $BACKUPS_DIR | |
$RETHINKDUMP_PATH dump -e $DB -f $BACKUPS_DIR/$BACKUP_NAME.tar.gz | |
function uploadS3 { | |
date=$(date +"%a, %d %b %Y %T %z") | |
acl="x-amz-acl:public-read" | |
content_type='application/x-compressed-tar' | |
string="PUT\n\n$content_type\n$date\n$acl\n/$S3_BUCKET$AWS_PATH/$BACKUP_NAME.tar.gz" | |
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3_SECRET}" -binary | base64) | |
curl -X PUT -T "$BACKUPS_DIR/$BACKUP_NAME.tar.gz" \ | |
-H "Host: $S3_BUCKET.s3.amazonaws.com" \ | |
-H "Date: $date" \ | |
-H "Content-Type: $content_type" \ | |
-H "$acl" \ | |
-H "Authorization: AWS ${S3_KEY}:$signature" \ | |
"https://$S3_BUCKET.s3.amazonaws.com$AWS_PATH/$BACKUP_NAME.tar.gz" | |
} | |
uploadS3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment