Skip to content

Instantly share code, notes, and snippets.

@syabro
Last active January 31, 2023 13:34
Show Gist options
  • Save syabro/5073c37cc3df1a694705 to your computer and use it in GitHub Desktop.
Save syabro/5073c37cc3df1a694705 to your computer and use it in GitHub Desktop.
Load remote db to local one
#!/bin/bash
echo "Dumping $1 to /tmp/$1.pgdump..."
ssh user@host.com "pg_dump -U www-data -Fc -O $1" > /tmp/$1.pgdump
echo "Destroying current DB...";
psql template1 -c "drop database if exists localdb;" > /dev/null
echo "Creating DB...";
psql template1 -c "create database localdb" > /dev/null
echo "Restoring dump from /tmp/$1.pgdump..."
pg_restore --dbname=localdb --no-owner --no-acl --jobs=16 /tmp/$1.pgdump
rm -rf /tmp/$1.pgdump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment