Simplify postgresql backups
I decided to replace custom backup scheduler with cron. It is fine for now, maybe later I will merge pg_dumpall with restic to prevent my SSD from dying faster.
This commit is contained in:
parent
2d734b7aed
commit
0d0731a8e4
3 changed files with 22 additions and 11 deletions
|
@ -13,14 +13,12 @@
|
||||||
become: true
|
become: true
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: postgresql-backuper-1
|
name: postgresql-backuper-1
|
||||||
image: git.comfycamp.space/lumin/postgresql-backuper:v0.0.3
|
image: git.comfycamp.space/lumin/postgres:16.4-bookworm
|
||||||
|
entrypoint: ["sleep"]
|
||||||
|
command: ["infinity"]
|
||||||
volumes:
|
volumes:
|
||||||
- postgresql-backups:/backups
|
- postgresql-backups:/backups
|
||||||
- /root/.pgpass:/root/.pgpass:ro
|
- /root/.pgpass:/root/.pgpass:ro
|
||||||
env:
|
|
||||||
CUSTOM_ARGS: "-U postgres -h postgresql --no-password"
|
|
||||||
BACKUPS_DIR: /backups
|
|
||||||
BACKUP_INTERVAL: 24h
|
|
||||||
networks:
|
networks:
|
||||||
- name: postgresql
|
- name: postgresql
|
||||||
restart_policy: unless-stopped
|
restart_policy: unless-stopped
|
||||||
|
@ -74,11 +72,17 @@
|
||||||
- prosody:/data/docker/prosody:ro
|
- prosody:/data/docker/prosody:ro
|
||||||
- synapse:/data/docker/synapse:ro
|
- synapse:/data/docker/synapse:ro
|
||||||
- vaultwarden:/data/docker/vaultwarden:ro
|
- vaultwarden:/data/docker/vaultwarden:ro
|
||||||
- name: Configure postgresql cron job
|
- name: Copy backup script
|
||||||
|
become: true
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: backup.sh.j2
|
||||||
|
dest: /root/backup.sh
|
||||||
|
mode: "0700"
|
||||||
|
owner: root
|
||||||
|
- name: Configure backup job
|
||||||
become: true
|
become: true
|
||||||
ansible.builtin.cron:
|
ansible.builtin.cron:
|
||||||
name: restic-postgresql
|
name: backups
|
||||||
minute: "35"
|
minute: "35"
|
||||||
hour: "*/24"
|
hour: "0"
|
||||||
job: "docker exec restic-1 restic --repo s3:https://{{ s3_host }}/{{ s3_buckets }} -o s3.bucket-lookup=dns backup /data/postgresql"
|
job: /root/backup.sh
|
||||||
user: root
|
|
||||||
|
|
7
roles/backups/templates/backup.sh.j2
Normal file
7
roles/backups/templates/backup.sh.j2
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
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 forget --keep-daily 7 --keep-weekly 2
|
|
@ -1,3 +1,3 @@
|
||||||
s3_region: ru-1
|
s3_region: ru-1
|
||||||
s3_host: s3.ru-1.storage.selcloud.ru
|
s3_host: s3.ru-1.storage.selcloud.ru
|
||||||
s3_buckets: cc-backups
|
s3_bucket: cc-backups
|
||||||
|
|
Loading…
Reference in a new issue