Created
January 5, 2017 08:30
-
-
Save anderejd/9fa142a80e52d941e66dbc9d5e0d0476 to your computer and use it in GitHub Desktop.
Restore all PostgreSQL database backups from a directory using psql and pg_restore.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -vx | |
root=`dirname "$(readlink -f "$0")"` | |
src="${root}/sqlbackup/data" | |
echo $src | |
sudo -u postgres psql --file=$src/globals.txt postgres | |
for fullfile in ${src}/*.dump; do | |
filename=$(basename "$fullfile") | |
dbname="${filename%.*}" | |
#sudo -u postgres psql --command="DROP DATABASE \"${dbname}\";" | |
sudo -u postgres psql --command="CREATE DATABASE \"${dbname}\";" | |
sudo -u postgres pg_restore --username=postgres --dbname=$dbname --no-password --clean --schema public --verbose --jobs=8 "$fullfile" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment