Created
December 20, 2019 05:59
-
-
Save mohitmun/ecaada4ac51b386cd0e3d52dc2193e4f to your computer and use it in GitHub Desktop.
pg backup and upload to s3
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 | |
set -Eeo pipefail | |
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ | |
exit_with_failure(){ | |
echo "Script failed" | |
echo "\"${last_command}\" command filed with exit code $?." | |
} | |
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG | |
trap exit_with_failure ERR | |
PGPASSWORD=1234 pg_dump -c -h localhost db -U user | gzip > $HOME/latestDbBackup.gz | |
aws --profile <s3Profile> s3 sync $HOME//latestDbBackup.gz s3://<bucket>/db-backup/ | |
echo "Backup and Sync completed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment