Skip to content

Instantly share code, notes, and snippets.

@rnschmidt
Forked from bennylope/create_db_restore.sh
Created August 20, 2020 13:12
Show Gist options
  • Save rnschmidt/567cdd98fa5e577e4c99bfcd8dc2ef1c to your computer and use it in GitHub Desktop.
Save rnschmidt/567cdd98fa5e577e4c99bfcd8dc2ef1c 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