aboutsummaryrefslogtreecommitdiff
path: root/builds/daily/postgres-backups.yaml
blob: e67f93f496af9614abc1b5831caba07c6116b546 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# this build backs up our postgres databases and stores
# the backups on a local server in j3s's house
image: alpine/edge
secrets:
  # backups@matrix.cyberia.club
  - 83a7f301-1e06-4fbb-9ab7-43ca3c018a4b
  # backups@192.168.1.246
  - 1a613565-a216-4f37-97c6-2ad41b6fb508
triggers:
  - action: email
    condition: failure
    to: ops <ops@cyberia.club>
tasks:
  - prep: |
      echo "StrictHostKeyChecking=no" >> ~/.ssh/config
  - pgdump: |
      ssh backups@matrix.cyberia.club \
      'pg_dump -h localhost -U synapse_user synapse | gzip' > pgbackup.gz
  - rotate-backup: |
      ssh -i ~/.ssh/1a613565-a216-4f37-97c6-2ad41b6fb508 backups@192.168.1.246 \
      mv /tank/backups/postgres/matrix-pgbackup.gz \
         /tank/backups/postgres/matrix-pgbackup.gz.old
  - copy-backup: |
      scp -i ~/.ssh/1a613565-a216-4f37-97c6-2ad41b6fb508 \
      pgbackup.gz backups@192.168.1.246:/tank/backups/postgres/matrix-pgbackup.gz
  - prom: |
      ssh backups@matrix.cyberia.club \
        echo pg_backup_completion_time $(date +%s) \
        > /var/lib/prometheus/textfile_collector/pg_backup.prom.$$ \
        && mv /var/lib/prometheus/textfile_collector/pg_backup.prom.$$ \
          /var/lib/prometheus/textfile_collector/pg_backup.prom