export-dumps.sh
625 Bytes
#!/bin/bash
set -ex
touch /tmp/pgpass
chmod 0600 /tmp/pgpass
echo "*:*:*:*:CHANGEME" > /tmp/pgpass
export PGPASSFILE=/tmp/pgpass
_pgdump() {
pg_dump -w -h ${POSTGRESQL_HOST} -U postgres "$1"
}
ls /workspace
for item in "$@"; do
target="${item%%:*}"
remote="${item#*:}"
case "$target" in
(*.sql.gz)
database="$(basename "$target" .sql.gz)"
_pgdump "$database" | gzip -9v > "/workspace/exports/$database.sql.gz"
;;
(*.sql)
database="$(basename "$target" .sql)"
_pgdump "$database" > "/workspace/exports/$database.sql"
;;
(*)
_pgdump "$item" > "/workspace/exports/$item.sql"
;;
esac
done