Skip to content

Instantly share code, notes, and snippets.

@hohl
Last active September 5, 2015 11:35
Show Gist options
  • Save hohl/319e3649c2a5e121cbcf to your computer and use it in GitHub Desktop.
Save hohl/319e3649c2a5e121cbcf to your computer and use it in GitHub Desktop.
Bash script which dumps a Postgres DB and uploads it via SFTP
#!/bin/bash
# Purpose: Dumps a PostgreSQL database and uploads it via SFTP to another host.
# Author: Michael Hohl <me@michaelhohl.net>
# -----------------------------------------------------------------------------
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