Skip to content

Instantly share code, notes, and snippets.

@jmrobles
Created July 6, 2020 17:08
Show Gist options
  • Save jmrobles/9fd0b760d97bd3131b8bdbec629ff66f to your computer and use it in GitHub Desktop.
Save jmrobles/9fd0b760d97bd3131b8bdbec629ff66f to your computer and use it in GitHub Desktop.
Backup Postgres DB Script
#!/bin/bash
export DUMP_FILE=/backup_`date +%Y%m%d_%H%M%S`.pgdump
PGPASSWORD=$POSTGRES_PASSWORD pg_dump -d $POSTGRES_DB -U $POSTGRES_USER -h $POSTGRES_HOST -f $DUMP_FILE
bzip2 $DUMP_FILE
mcrypt ${DUMP_FILE}.bz2 -k $DB_BACKUP_PASSWORD
aws s3 cp ${DUMP_FILE}.bz2.nc $S3_BACKUP_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment