22 lines
654 B
Plaintext
22 lines
654 B
Plaintext
|
#!/bin/bash
|
||
|
|
||
|
DUMP_DIR="/var/backups/dumps/"
|
||
|
|
||
|
mkdir -p "$DUMP_DIR"
|
||
|
chmod go-rwx "$DUMP_DIR"
|
||
|
|
||
|
if [ -x /usr/bin/psql ]; then
|
||
|
#
|
||
|
su - postgres -c "pg_dumpall --roles-only " | bzip2 > $DUMP_DIR/roles-psql.sql.bz2
|
||
|
|
||
|
#
|
||
|
DATABASES=$(su - postgres -c "psql -t -c \"SELECT datname FROM pg_database AS dbs INNER JOIN pg_authid AS roles ON dbs.datdba=roles.oid WHERE rolname<>'postgres' ;\"")
|
||
|
echo "Databases: $DATABASES"
|
||
|
for DATABASE in $DATABASES ; do
|
||
|
echo "Dumping database: $DATABASE"
|
||
|
su - postgres -c "pg_dump $DATABASE" | bzip2 - > $DUMP_DIR/$DATABASE-psql.sql.bz2
|
||
|
done
|
||
|
else
|
||
|
echo "DMBS Postgresql not detected."
|
||
|
fi
|