Skip to content

Instantly share code, notes, and snippets.

@bennylope
Last active August 20, 2020 13:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bennylope/81ec4b4eb8d9a8b79055475da6735e4a to your computer and use it in GitHub Desktop.
Save bennylope/81ec4b4eb8d9a8b79055475da6735e4a to your computer and use it in GitHub Desktop.
Create a named database and restore from the lastest downloaded file
#!/usr/bin/env bash
LATEST_DB="$HOME/Downloads/$(ls -t ~/Downloads | head -1)"
BACKUP_PATH=${2-$LATEST_DB}
DB=$1
echo "Creating database name $DB from $BACKUP_PATH"
psql -c "CREATE DATABASE $DB;"
echo "Now restoring database $DB from $BACKUP_PATH"
pg_restore -O -x -d $DB $BACKUP_PATH #"${@:2}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment