Created
November 20, 2015 20:00
-
-
Save zenchild/ee6bc1cc68936f1749dc to your computer and use it in GitHub Desktop.
Save database functions
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
# vi: syntax=sh | |
backupDatabase() { | |
local db=$1 | |
if [ -z $db ]; then | |
echo "You must pass a database name" | |
return 1 | |
fi | |
if [ ! -z $2 ]; then | |
pg_dump -U postgres -f "${TOAST}/db/${db}"-$(date +"%Y-%m-%dT%H:%M:%SZ")-"${2}".dump "${db}" | |
else | |
pg_dump -U postgres -f "${TOAST}/db/${db}"-$(date +"%Y-%m-%dT%H:%M:%SZ").dump "${db}" | |
fi | |
} | |
backupToastDev() { | |
if [ ! -z $1 ]; then | |
backupDatabase toast_dev | |
else | |
backupDatabase toast_dev "${1}" | |
fi | |
} | |
restoreDatabase() { | |
local db=$1 | |
local file=$2 | |
if [ -z $db ]; then | |
echo "You must pass a database name" | |
return 1 | |
fi | |
if [ -z $file ] || [ ! -f "${file}" ]; then | |
echo "You must pass a valid file name." | |
return 1 | |
fi | |
dropdb -U postgres "${db}"; createdb -U postgres -O toast "${db}" | |
psql -U postgres "${db}" < "${file}" | |
} | |
restoreToastDev() { | |
restoreDatabase toast_dev "${1}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment