Create postgresql backups without intermediate files

This commit is contained in:
Ivan R. 2024-11-25 13:50:52 +05:00
parent 748cbed50d
commit d840efa1e0
Signed by: lumin
GPG key ID: E0937DC7CD6D3817
3 changed files with 7 additions and 20 deletions

View file

@ -1,2 +1,3 @@
FROM restic/restic:0.17.3
RUN apk add postgresql16-client
WORKDIR /data

View file

@ -5,23 +5,6 @@
dest: /root/.pgpass
mode: "0600"
owner: root
- name: Create postgresql backups volume
become: true
community.docker.docker_volume:
name: postgresql-backups
- name: Run postgresql backuper
become: true
community.docker.docker_container:
name: postgresql-backuper-1
image: git.comfycamp.space/lumin/postgres:16.4-bookworm
entrypoint: ["sleep"]
command: ["infinity"]
volumes:
- postgresql-backups:/backups
- /root/.pgpass:/root/.pgpass:ro
networks:
- name: postgresql
restart_policy: unless-stopped
- name: Run backup container
become: true
community.docker.docker_container:
@ -33,9 +16,12 @@
AWS_SECRET_ACCESS_KEY: "{{ s3_secret_access_key }}"
AWS_DEFAULT_REGION: "{{ s3_region }}"
RESTIC_PASSWORD: "{{ restic_password }}"
networks:
- name: postgresql
entrypoint: ["sleep"]
command: ["infinity"]
volumes:
- /root/.pgpass:/root/.pgpass:ro
- /mnt/hdd/archivebox-data:/data/archivebox:ro
- archivebox:/data/docker/archivebox:ro
- authentik-redis:/data/docker/authentik-redis:ro
@ -68,7 +54,6 @@
- peertube-redis:/data/docker/peertube-redis:ro
- /mnt/hdd/peertube:/data/peertube:ro
- phoenix:/data/docker/phoenix:ro
- postgresql-backups:/data/postgresql:ro
- prosody:/data/docker/prosody:ro
- synapse:/data/docker/synapse:ro
- vaultwarden:/data/docker/vaultwarden:ro

View file

@ -2,7 +2,8 @@
set -e
docker exec postgresql-backuper-1 pg_dumpall -U postgres -h postgresql --no-password -f /backups/postgresql.sql
docker exec restic-1 restic --repo s3:https://{{ s3_host }}/{{ s3_bucket }} -o s3.bucket-lookup=dns backup /data/postgresql
docker exec restic-1 restic --repo s3:https://{{ s3_host }}/{{ s3_bucket }} -o s3.bucket-lookup=dns \
backup --stdin-filename /data/postgresql.sql --stdin-from-command \
-- pg_dumpall -U postgres -h postgresql --no-password
docker exec restic-1 restic --repo s3:https://{{ s3_host }}/{{ s3_bucket }} -o s3.bucket-lookup=dns backup /data/immich
docker exec restic-1 restic --repo s3:https://{{ s3_host }}/{{ s3_bucket }} -o s3.bucket-lookup=dns forget --keep-daily 7 --keep-weekly 2