Created
August 16, 2017 01:51
-
-
Save adamenger/f559143125aa135828f84319f3e13fb8 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# 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