Last active
February 16, 2017 06:30
-
-
Save henocdz/31475ad30d4d3ee6d5fd to your computer and use it in GitHub Desktop.
Script for automatic backup of Postgresql DB
This file contains hidden or 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
| 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