Skip to content

Instantly share code, notes, and snippets.

@henocdz
Last active February 16, 2017 06:30
Show Gist options
  • Select an option

  • Save henocdz/31475ad30d4d3ee6d5fd to your computer and use it in GitHub Desktop.

Select an option

Save henocdz/31475ad30d4d3ee6d5fd to your computer and use it in GitHub Desktop.
Script for automatic backup of Postgresql DB
DB_USERNAME=''
DB_NAME=''
DB_PASSWORD=''
DB_HOST=''
DATE=`date +%Y%m%d`
TIME=`date +%H%M`
BACKUP_DIR='/some/path/to/dbackups/'
FILENAME="$DATE-$TIME.sql.gz"
PGDUMP=`which pg_dump`
export PGPASSWORD=$DB_PASSWORD
$PGDUMP -U $DB_USERNAME $DB_NAME | gzip > $BACKUP_DIR$FILENAME
cd $BACKUP_DIR
# Using this amazing tool by Petter Rasmussen: https://github.com/prasmussen/gdrive
# We can uplaod our backup to some Google Drive account
# Thanks Petter! :)
exec drive upload -f $FILENAME -p SOME_DRIVE_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment