2024-07-11 21:18:02 +05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
2024-08-08 05:50:15 +05:00
|
|
|
echo -e "\033[31mThis script requires superuser rights\033[0m"
|
2024-07-11 21:18:02 +05:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-08-14 10:49:57 +05:00
|
|
|
trap 'echo -e "\033[31mpostgres-all.sh: Something went wrong\033[0m"; exit 1' ERR
|
2024-07-11 21:18:02 +05:00
|
|
|
set -e
|
|
|
|
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
2024-08-08 05:50:15 +05:00
|
|
|
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
|
2024-07-11 21:18:02 +05:00
|
|
|
bash postgres.sh "$dbname" "$owner"
|
|
|
|
done
|
|
|
|
|
2024-08-14 10:49:57 +05:00
|
|
|
trap - ERR
|
|
|
|
echo "All postgres databases backuped successfully"
|