Created
July 25, 2014 06:40
-
-
Save lucascaton/8563a16fba425d8d38a4 to your computer and use it in GitHub Desktop.
PostgreSQL database dump generator
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 | |
# ┌──────────────────────────────────────┐ | |
# │ PostgreSQL database dump generator | | |
# | Created by Lucas Caton on 2010-08-14 | | |
# | Updated by Lucas Caton on 2014-07-25 | | |
# └──────────────────────────────────────┘ | |
usage() { | |
echo "usage: $0 <project_name> <db_name>" | |
exit | |
} | |
[ -n "$1" ] || usage | |
[ -n "$2" ] || usage | |
echo ------------------------------------ | |
echo Generating dump... | |
echo ------------------------------------ | |
mkdir -p ~/backups/$1 | |
cd ~/backups/$1 | |
FILE_NAME="$(date "+%F")"_$1_dump | |
touch $FILE_NAME.sql | |
PGPASSWORD="secret" pg_dump $2 -h localhost -U postgres --column-inserts --no-owner > $FILE_NAME.sql | |
tar -czvf $FILE_NAME.tgz $FILE_NAME.sql | |
rm $FILE_NAME.sql | |
echo ------------------------------------ | |
echo Dump genereted! | |
echo ------------------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment