Skip to content

Instantly share code, notes, and snippets.

@mohitmun
Created December 20, 2019 05:59
Show Gist options
  • Save mohitmun/ecaada4ac51b386cd0e3d52dc2193e4f to your computer and use it in GitHub Desktop.
Save mohitmun/ecaada4ac51b386cd0e3d52dc2193e4f to your computer and use it in GitHub Desktop.
pg backup and upload to s3
#!/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