MonScoDocEssai/config/psql_restore_databases.sh

29 lines
658 B
Bash
Raw Normal View History

2020-09-26 16:19:37 +02:00
#!/bin/bash
# aux script called by restore_scodoc_data.sh as "postgres" user
# DO NOT CALL DIRECTLY
PG_DUMPFILE=$1
# Check locale of installation. If invalid, reinitialize all system
is_latin1=$(psql -l | grep postgres | grep iso88591 | wc -l)
2020-12-19 19:22:22 +01:00
if [ "$is_latin1" -gt 1 ]
2020-09-26 16:19:37 +02:00
then
echo "Recreating postgres cluster using UTF-8"
pg_dropcluster --stop 9.1 main
pg_createcluster --locale en_US.UTF-8 --start 9.1 main
fi
# Drop all current ScoDoc databases, if any:
for f in $(psql -l --no-align --field-separator . | grep SCO | cut -f 1 -d.); do
2020-12-19 19:22:22 +01:00
echo dropping "$f"
dropdb "$f"
2020-09-26 16:19:37 +02:00
done
echo "Restoring postgres data..."
psql -f "$PG_DUMPFILE" postgres