Skip to content

Instantly share code, notes, and snippets.

@lucascaton
Created Jul 25, 2014
Embed
What would you like to do?
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