Last active
September 5, 2015 11:35
-
-
Save hohl/319e3649c2a5e121cbcf to your computer and use it in GitHub Desktop.
Bash script which dumps a Postgres DB and uploads it via SFTP
This file contains 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 | |
# Purpose: Dumps a PostgreSQL database and uploads it via SFTP to another host. | |
# Author: Michael Hohl <[email protected]> | |
# ----------------------------------------------------------------------------- | |
display_usage() { | |
echo "Usage: $0 <dbname> <user@stfp-target>" | |
} | |
if [ $# -ne 2 ]; then | |
display_usage | |
exit 1 | |
fi | |
today=`date +%Y-%m-%d_%H-%M` | |
pg_dump $1 | gzip > $1_$today.sql.gz | |
scp $1_$today.sql.gz $2 | |
rm $1_$today.sql.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment