import-dumps.sh
542 Bytes
#!/bin/bash
set -ex
touch /tmp/pgpass
chmod 0600 /tmp/pgpass
echo "*:*:*:*:CHANGEME" > /tmp/pgpass
export PGPASSFILE=/tmp/pgpass
_import() {
psql -w -h ${POSTGRESQL_HOST} -U postgres "$1"
}
ls -alR /workspace
for file in /workspace/imports/*; do
[[ -e $file ]] || continue
case "$file" in
(*.sql.gz)
database="$(basename "$file" .sql.gz)"
zcat "$file" | _import "$database"
;;
(*.sql)
database="$(basename "$file" .sql)"
cat "$file" | _import "$database"
;;
(*)
echo "Ignoring file: $file"
;;
esac
done