Migrate Synapse database to postgres container.

This commit is contained in:
Viyurz 2024-04-01 11:02:09 +02:00
parent e3c7c4f38a
commit 1514031f1e
Signed by: Viyurz
SSH key fingerprint: SHA256:IskOHTmhHSJIvAt04N6aaxd5SZCVWW1Guf9tEcxIMj8
6 changed files with 15 additions and 45 deletions

View file

@ -122,7 +122,6 @@ users:
searxng: 977 searxng: 977
searxng_redis: 999 searxng_redis: 999
synapse: 991 synapse: 991
synapse_postgres: 70
syncthing: 1001 syncthing: 1001
syncthing_discosrv: 1002 syncthing_discosrv: 1002
syncthing_relaysrv: 1003 syncthing_relaysrv: 1003
@ -142,7 +141,6 @@ volumes:
mailserver_tls_certificate_key_file: "/etc/letsencrypt/live/mail.{{ domain }}/privkey.pem" mailserver_tls_certificate_key_file: "/etc/letsencrypt/live/mail.{{ domain }}/privkey.pem"
postgres_datadir: /mnt/postgresdata postgres_datadir: /mnt/postgresdata
synapse_datadir: /mnt/synapsedata synapse_datadir: /mnt/synapsedata
synapse_postgres_datadir: /mnt/synapsepgdata
syncthing_datadir: "{{ cifs_mounts['syncthing']['path'] }}" syncthing_datadir: "{{ cifs_mounts['syncthing']['path'] }}"
uptime_kuma_datadir: /mnt/uptimekumadata uptime_kuma_datadir: /mnt/uptimekumadata
vaultwarden_datadir: /mnt/vwdata vaultwarden_datadir: /mnt/vwdata

View file

@ -1,22 +1,15 @@
- name: Backup PostgreSQL database - name: "Backup PostgreSQL synapse database & {{ volumes['synapse_datadir'] }} directory"
community.docker.docker_container_exec: shell: >
container: synapse-postgres docker exec postgres
docker_host: "{{ docker_host }}" pg_dump -c {{ role_name }} |
command: | borg create
pg_dump -c --compression lzma
-d synapse "{{ borg_repodir }}::{{ role_name }}-{now:%Y-%m-%d_%H-%M-%S}"
-U synapse "{{ volumes['synapse_datadir'] }}"
-f /var/lib/postgresql/data/synapse-dump.sql -
--stdin-name dump_{{ role_name }}.sql
- name: Create borg backup
command:
cmd: |
borg create
--compression=lzma
"{{ borg_repodir }}::{{ role_name }}-{now:%Y-%m-%d_%H-%M-%S}"
{{ volumes['synapse_datadir'] }}/media_store
{{ volumes['synapse_postgres_datadir'] }}/synapse-dump.sql
environment: environment:
DOCKER_HOST: "{{ docker_host }}"
BORG_PASSCOMMAND: "cat {{ borg_passphrase_file }}" BORG_PASSCOMMAND: "cat {{ borg_passphrase_file }}"
become: true become: true

View file

@ -36,15 +36,6 @@
mode: '770' mode: '770'
become: true become: true
- name: "Create directory {{ volumes['synapse_postgres_datadir'] }} with correct permissions"
file:
path: "{{ volumes['synapse_postgres_datadir'] }}"
state: directory
owner: "{{ users['synapse_postgres'] + uid_shift }}"
group: "{{ users['synapse_postgres'] + uid_shift }}"
mode: '700'
become: true
- name: Pull project services - name: Pull project services
community.docker.docker_compose: community.docker.docker_compose:
project_src: "{{ project_dir }}" project_src: "{{ project_dir }}"

View file

@ -1,17 +1,4 @@
services: services:
postgres:
container_name: synapse-postgres
image: docker.io/library/postgres:alpine
restart: always
user: {{ users['synapse_postgres'] }}:{{ users['synapse_postgres'] }}
environment:
LANG: C
POSTGRES_INITDB_ARGS: "--locale=C --encoding=UTF8"
POSTGRES_USER: synapse
POSTGRES_PASSWORD: {{ synapse_secrets['postgres_password'] }}
volumes:
- {{ volumes['synapse_postgres_datadir'] }}:/var/lib/postgresql/data
synapse: synapse:
container_name: synapse container_name: synapse
image: docker.io/matrixdotorg/synapse:latest image: docker.io/matrixdotorg/synapse:latest

View file

@ -33,10 +33,10 @@ max_avatar_size: 2M
database: database:
name: psycopg2 name: psycopg2
args: args:
user: synapse user: '{{ synapse_secrets["postgres_user"] }}'
password: {{ synapse_secrets['postgres_password'] }} password: '{{ synapse_secrets["postgres_password"] }}'
dbname: synapse dbname: synapse
host: synapse-postgres host: 'postgres.{{ domain }}'
cp_min: 5 cp_min: 5
cp_max: 10 cp_max: 10

View file

@ -39,6 +39,7 @@ searxng_secrets:
synapse_secrets: synapse_secrets:
smtp_user: smtp_user:
smtp_pass: smtp_pass:
postgres_user:
postgres_password: postgres_password:
turn_shared_secret: "{{ coturn_secrets['static_auth_secret'] }}" turn_shared_secret: "{{ coturn_secrets['static_auth_secret'] }}"
macaroon_secret_key: macaroon_secret_key: