1
1
mirror of https://gitlab.archlinux.org/archlinux/infrastructure.git synced 2024-09-20 11:54:39 +02:00

borg-client: Propery postgres backup

This commit is contained in:
Sven-Hendrik Haase 2016-06-05 16:10:32 +02:00
parent 59924c98a4
commit e8c06b36ea
5 changed files with 34 additions and 3 deletions

View File

@ -8,4 +8,4 @@
- tools
- sshd
- ssh_keys
- { role: borg-client, backup_host: "borg@vostok.archlinux.org", backup_dir: "/backup/apollo" }
- { role: borg-client, backup_host: "borg@vostok.archlinux.org", backup_dir: "/backup/apollo", postgres_backup_dir: "/var/lib/postgres/backup" }

View File

@ -8,7 +8,7 @@
- tools
- sshd
- ssh_keys
- { role: borg-client, backup_host: "borg@vostok.archlinux.org", backup_dir: "/backup/orion" }
- { role: borg-client, backup_host: "borg@vostok.archlinux.org", backup_dir: "/backup/orion", postgres_backup_dir: None }
- { role: opendkim, dkim_selector: orion }
- { role: postfix}
- archusers

View File

@ -18,6 +18,19 @@
- name: install borg backup script
template: src=borg-backup.sh.j2 dest=/usr/local/bin/borg-backup.sh owner=root group=root mode=755
- name: install postgres backup script
template: src=backup-postgres.sh.j2 dest=/usr/local/bin/backup-postgres.sh owner=root group=root mode=755
when: postgres_backup_dir != None
- name: check whether postgres user exists
command: getent passwd postgres
register: check_postgres_user
ignore_errors: True
- name: make postgres backup directory
file: path=/var/lib/postgres/backup owner=postgres group=postgres state=directory
when: check_postgres_user|succeeded and postgres_backup_dir != None
- name: install systemd timers for backup
copy: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=644
with_items:

View File

@ -0,0 +1,18 @@
#!/bin/bash
#
# Script to backup all postgres databases individually
#
# Requires local login with `postgres` user and either trusted or peer auth.
#
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 {{ postgres_backup_dir }}";
sudo -u postgres pg_dump --serializable-deferrable -Fc "$db" > "{{ postgres_backup_dir }}/$db.dump"
done
echo "Dumping globals to {{ postgres_backup_dir }}"
sudo -u postgres pg_dumpall --globals-only > "{{ postgres_backup_dir }}/globals.sql.dump"

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# In case there is postgresql running, dump all of it somewhere.
systemctl status postgresql && pg_dumpall -f /root/postgres_dump.sql
systemctl status postgresql && /usr/local/bin/backup-postgres.sh
borg create -v --stats -C lz4 -e /proc \
-e /sys -e /dev -e /run -e /tmp -e /var/cache \