Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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