Skip to content

Instantly share code, notes, and snippets.

@ilfuriano
Created September 13, 2017 18:07
Show Gist options
  • Save ilfuriano/7b163ea22e2ed94d4967256bead5c1f7 to your computer and use it in GitHub Desktop.
Save ilfuriano/7b163ea22e2ed94d4967256bead5c1f7 to your computer and use it in GitHub Desktop.
Backup Postgres DB to Google Drive
#!/bin/bash
now=`date +%Y%m%d-%H%M%S`
day_ago=7
db_name="DB_NAME"
base_path="BASE_PATH"
dump_fpath="$base_path/backup_db-$now.sql.gz"
sudo -u postgres pg_dump $db_name | gzip -9 > $dump_fpath
find $base_path -maxdepth 1 -type f -name "backup_db*.tar" -mtime +$day_ago -delete
# https://github.com/prasmussen/gdrive
gdrive sync upload $base_path GDRIVE_FOLDER_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment