#!/bin/bash if [ "$(id -u)" != "0" ]; then echo -e "\033[31mThis script requires superuser rights\033[0m" exit 0 fi trap 'echo -e "\033[31mpostgres-all.sh: Something went wrong\033[0m"; exit 1' ERR set -e export DEBIAN_FRONTEND=noninteractive docker exec -i postgres psql -U $POSTGRES_USER -d $POSTGRES_DB -t -A -F',' <<-EOSQL | SELECT d.datname, a.rolname FROM pg_database d JOIN pg_roles a ON d.datdba = a.oid WHERE d.datistemplate = false; EOSQL while IFS=, read -r dbname owner; do bash postgres.sh "$dbname" "$owner" done trap - ERR echo "All postgres databases backuped successfully"