Skip to content

Instantly share code, notes, and snippets.

@jcamblan
Created February 16, 2022 09:16
Show Gist options
  • Save jcamblan/74b5c9145587a8c45b7093ccd93fd12a to your computer and use it in GitHub Desktop.
Save jcamblan/74b5c9145587a8c45b7093ccd93fd12a to your computer and use it in GitHub Desktop.
pg_restore given dump on given scalingo stack
#!/usr/bin/env bash
set -e # stop on first error
STACK=$1
DUMP=$2
if [[ $# -eq 0 ]] ; then
echo 'Usage: `sh pg_restore_scalingo.sh {STACK_NAME} {DUMP.PSQL}`'
exit 0
fi
scalingo --app $STACK db-tunnel SCALINGO_POSTGRESQL_URL &
tunnel_pid=$!
while ! nc -z localhost 10000; do
sleep 1
done
db_url=$(scalingo --app "${STACK}" env | grep -v DATABASE_URL | grep SCALINGO_POSTGRESQL_URL | cut -d '=' -f2-)
local_db_url=$(echo "${db_url}" | gsed -e 's/@[^/]\+/@127.0.0.1:10000/')
pg_restore --clean --if-exists --no-owner --no-privileges --no-comments --dbname $local_db_url ${DUMP}
kill $tunnel_pid
wait
echo 🚀
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment