1
1
mirror of https://gitlab.archlinux.org/archlinux/infrastructure.git synced 2025-01-18 08:06:16 +01:00
infrastructure/roles/borg_client/templates/backup-postgres.sh.j2
Evangelos Foutras 743dd1faeb
borg_client: refactor database related vars/tasks
Move backup-related variable defaults from the database roles into the
borg_client role. Also check group membership to guard installation of
database backup helper scripts.
2024-03-30 19:08:37 +02:00

20 lines
666 B
Django/Jinja

#!/bin/bash
#
# Script to backup all postgres databases individually
#
# Requires local login with `postgres` user and either trusted or peer auth.
set -e
DBLIST=($(sudo -u postgres psql -d postgres -qt -c 'SELECT datname from pg_database'))
for db in "${DBLIST[@]}"; do
if [[ $db =~ template[01] ]]; then
continue;
fi
echo "Dumping $db to {{ backup_postgres_dir }}";
sudo -u postgres pg_dump --serializable-deferrable -Fc "$db" > "{{ backup_postgres_dir }}/$db.dump"
done
echo "Dumping globals to {{ backup_postgres_dir }}"
sudo -u postgres pg_dumpall --globals-only > "{{ backup_postgres_dir }}/globals.sql.dump"