Skip to content

Instantly share code, notes, and snippets.

@faisalmahmud
Last active January 29, 2020 16:48
Show Gist options
  • Save faisalmahmud/0be5292a6c411a1cfd8184f111e9e6a8 to your computer and use it in GitHub Desktop.
Save faisalmahmud/0be5292a6c411a1cfd8184f111e9e6a8 to your computer and use it in GitHub Desktop.
Postgres commands that makes it easy to take a local DB snapshot and restore it
DATE_WITH_TIME=`date "+%Y%m%d-%H%M%S"`
pg_dump -Fc -U $1 -h localhost -p 5432 $1 --no-owner --no-acl -f "pgdump-$1-$DATE_WITH_TIME.bak"
pg_restore -Fc -c -U $1 -h localhost -d $1 -O --no-acl --no-owner -v $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment