Skip to content

Instantly share code, notes, and snippets.

@sandiprb
Created July 28, 2020 20:25
Show Gist options
  • Save sandiprb/8bce374546965948495e42872f7893e1 to your computer and use it in GitHub Desktop.
Save sandiprb/8bce374546965948495e42872f7893e1 to your computer and use it in GitHub Desktop.
Shell file to back up Postgres db & copy to s3 bucket
DB_NAME=$1
DB_USER=$2
DB_PASS=$3
BUCKET_NAME='bucket-name'
TIMESTAMP=$(date +%F_%T | tr ':' '-')
DB_FILE="$TIMESTAMP.sql"
PGPASSWORD=$DB_PASS pg_dump -Fc --no-acl -h localhost -U $DB_USER $DB_NAME > $DB_FILE
# copy to s3
aws s3 cp $DB_FILE s3://$BUCKET_NAME
rm "$DB_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment