Created
February 7, 2017 16:33
-
-
Save studiotomi/231c321ba2a2abf41b7cba02c568f7a5 to your computer and use it in GitHub Desktop.
Back up postgres db to google cloud storage
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
#!/bin/bash | |
# Requirements: | |
# - gcloud/gsutil is installed on the box | |
# - gcloud is logged in as a user with write access to Google Cloud Storage | |
# - The file has execution rights so that it can be run in cron | |
# - The Google Cloud Storage bucket already exits | |
# Exit on any error | |
set -e | |
BUCKET='gs://some-bucket/' | |
JOB_TIMESTAMP=`date +%Y%m%d-%H%M` | |
DATABASE='the database name' | |
DIR='/home/postgres' | |
cd $DIR | |
/usr/bin/pg_dump $DATABASE > $JOB_TIMESTAMP-pad.sql | |
/bin/tar -cvzf $JOB_TIMESTAMP.tar.gz $JOB_TIMESTAMP-pad.sql | |
/usr/bin/gsutil cp $JOB_TIMESTAMP.tar.gz $BUCKET | |
rm -f $JOB_TIMESTAMP-pad.sql $JOB_TIMESTAMP.tar.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment