Commit e8c06b36 authored by Sven-Hendrik Haase's avatar Sven-Hendrik Haase
Browse files

borg-client: Propery postgres backup

parent 59924c98
......@@ -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" }
......@@ -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
......
......@@ -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:
......
#!/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"
#!/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 \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment