Skip to content

Instantly share code, notes, and snippets.

@cantonic
Created July 18, 2016 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cantonic/3834432c5c8e10ffabd0537d09d94b05 to your computer and use it in GitHub Desktop.
Save cantonic/3834432c5c8e10ffabd0537d09d94b05 to your computer and use it in GitHub Desktop.
Backup multiple dokku postgres instances and upload them to a bucket in S3
#!/bin/bash
S3KEY="CHANGE_ME"
S3SECRET="CHANGE_ME"
bucket='CHANGE_ME'
region='CHANGE_ME'
declare -a apps=("app1" "app2")
echo "Starting to backup - $(date)"
function putS3
{
path=$1
file=$2
aws_path=$3
date=$(date +"%a, %d %b %Y %T %z")
acl="x-amz-acl:private"
string="PUT\n\n$content_type\n$date\n$acl\n/$bucket$aws_path$file"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" $
curl -X PUT -T "$path/$file" \
-H "Host: $bucket.s3.amazonaws.com" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "$acl" \
-H "Authorization: AWS ${S3KEY}:$signature" \
"https://$bucket.$region.amazonaws.com$aws_path$file"
}
d=$(date +"%d-%m-%Y")
for app in "${apps[@]}"
do
echo "Backing up ${app}"
file_name="${app}-${d}.dump"
echo $(dokku postgres:export $app > $file_name)
echo "Uploading to S3"
putS3 "." $file_name "/${d}/"
done
echo "Backup Completed - $(date)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment