Skip to content

Instantly share code, notes, and snippets.

@lucascaton
Created July 25, 2014 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucascaton/8563a16fba425d8d38a4 to your computer and use it in GitHub Desktop.
Save lucascaton/8563a16fba425d8d38a4 to your computer and use it in GitHub Desktop.
PostgreSQL database dump generator
#! /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