Skip to content

Instantly share code, notes, and snippets.

@adamenger
Created August 16, 2017 01:51
Show Gist options
  • Save adamenger/f559143125aa135828f84319f3e13fb8 to your computer and use it in GitHub Desktop.
Save adamenger/f559143125aa135828f84319f3e13fb8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# date variables
year=$(date +"%Y")
month=$(date +"%m")
day=$(date +"%d")
for db in production staging
do
# give the archive a pretty name like name_datestamp
archive="$db"_$(date +"%Y.%m.%d.%H.%M.%S").pg
# Dump database
pg_dump \
-h database host \
-U user \
-C \
-Z 9 \
"$db"_production > $archive
# encrypt the archive with the ops key before uploading
gpg --output $archive.gpg --encrypt --recipient your_recipient $archive
# upload it to s3
aws s3 cp $archive.gpg s3://db-backups/$db/$year/$month/$day/$archive.gpg
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment