This role is usable on its own and it's not tied to Matrix, so extracting it out into an independent role that we install via ansible-galaxy makes sense. This also fixes the confusion from the other day, where `matrix_postgres_*` had to be renamed to `devture_postgres_*` (unless it was about `matrix_postgres_backup_*`). We now can safely say that ALL `matrix_postgres_*` variables need to be renamed. Fixes https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/2305development
parent
a365e54f4d
commit
4eed49f931
@ -1,45 +0,0 @@
|
||||
---
|
||||
# Project source code URL: https://github.com/prodrigestivill/docker-postgres-backup-local
|
||||
|
||||
matrix_postgres_backup_enabled: false
|
||||
|
||||
matrix_postgres_backup_connection_hostname: ''
|
||||
matrix_postgres_backup_connection_port: 5432
|
||||
matrix_postgres_backup_connection_username: "matrix"
|
||||
matrix_postgres_backup_connection_password: ""
|
||||
|
||||
matrix_postgres_backup_extra_opts: "-Z9 --schema=public --blobs"
|
||||
matrix_postgres_backup_schedule: "@daily"
|
||||
matrix_postgres_backup_keep_days: 7
|
||||
matrix_postgres_backup_keep_weeks: 4
|
||||
matrix_postgres_backup_keep_months: 12
|
||||
matrix_postgres_backup_healthcheck_port: "8080"
|
||||
matrix_postgres_backup_databases: []
|
||||
matrix_postgres_backup_path: "{{ matrix_base_data_path }}/postgres-backup"
|
||||
|
||||
# Specifies where the Postgres data is.
|
||||
# We use this to autodetect the Postgres version during playbook runtime (by parsing the `PG_VERSION` file contained there).
|
||||
# You can leave this empty to prevent auto-detection.
|
||||
matrix_postgres_backup_postgres_data_path: ""
|
||||
|
||||
matrix_postgres_backup_architecture: amd64
|
||||
|
||||
# matrix_postgres_backup_docker_image_distro controls whether we use Alpine-based images (`-alpine`) or the normal Debian-based images.
|
||||
# Alpine-based Postgres images are smaller and we usually prefer them, but they don't work on ARM32 (tested on a Raspberry Pi 3 running Raspbian 10.7).
|
||||
# On ARM32, `-alpine` images fail with the following error:
|
||||
# > LOG: startup process (PID 37) was terminated by signal 11: Segmentation fault
|
||||
matrix_postgres_backup_docker_image_distro: "{{ 'alpine' if matrix_postgres_backup_architecture in ['amd64', 'arm64'] else 'debian' }}"
|
||||
|
||||
matrix_postgres_backup_docker_image_v9: "{{ matrix_container_global_registry_prefix }}prodrigestivill/postgres-backup-local:9.6-{{ matrix_postgres_backup_docker_image_distro }}-2aa03d1"
|
||||
matrix_postgres_backup_docker_image_v10: "{{ matrix_container_global_registry_prefix }}prodrigestivill/postgres-backup-local:10-{{ matrix_postgres_backup_docker_image_distro }}-2cf00a5"
|
||||
matrix_postgres_backup_docker_image_v11: "{{ matrix_container_global_registry_prefix }}prodrigestivill/postgres-backup-local:11-{{ matrix_postgres_backup_docker_image_distro }}-2cf00a5"
|
||||
matrix_postgres_backup_docker_image_v12: "{{ matrix_container_global_registry_prefix }}prodrigestivill/postgres-backup-local:12-{{ matrix_postgres_backup_docker_image_distro }}-2cf00a5"
|
||||
matrix_postgres_backup_docker_image_v13: "{{ matrix_container_global_registry_prefix }}prodrigestivill/postgres-backup-local:13-{{ matrix_postgres_backup_docker_image_distro }}-2cf00a5"
|
||||
matrix_postgres_backup_docker_image_v14: "{{ matrix_container_global_registry_prefix }}prodrigestivill/postgres-backup-local:14-{{ matrix_postgres_backup_docker_image_distro }}-2cf00a5"
|
||||
matrix_postgres_backup_docker_image_v15: "{{ matrix_container_global_registry_prefix }}prodrigestivill/postgres-backup-local:15-{{ matrix_postgres_backup_docker_image_distro }}-2cf00a5"
|
||||
matrix_postgres_backup_docker_image_latest: "{{ matrix_postgres_backup_docker_image_v15 }}"
|
||||
|
||||
# This variable is assigned at runtime. Overriding its value has no effect.
|
||||
matrix_postgres_backup_docker_image_to_use: '{{ matrix_postgres_backup_docker_image_latest }}'
|
||||
|
||||
matrix_postgres_backup_docker_image_force_pull: "{{ matrix_postgres_backup_docker_image_to_use.endswith(':latest') }}"
|
@ -1,20 +0,0 @@
|
||||
---
|
||||
|
||||
- block:
|
||||
- when: matrix_postgres_backup_enabled | bool
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/validate_config.yml"
|
||||
|
||||
- when: matrix_postgres_backup_enabled | bool
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_install.yml"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-postgres-backup
|
||||
- install-all
|
||||
- install-postgres-backup
|
||||
|
||||
- block:
|
||||
- when: not matrix_postgres_backup_enabled | bool
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_uninstall.yml"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-postgres-backup
|
@ -1,51 +0,0 @@
|
||||
---
|
||||
|
||||
|
||||
- ansible.builtin.include_role:
|
||||
name: galaxy/com.devture.ansible.role.postgres
|
||||
tasks_from: detect_existing_postgres_version
|
||||
when: 'matrix_postgres_backup_postgres_data_path != ""'
|
||||
|
||||
# If we have found an existing version (installed from before), we use its corresponding Docker image.
|
||||
# If not, we install using the latest Postgres.
|
||||
#
|
||||
# Upgrading is supposed to be performed separately and explicitly (see `upgrade_postgres.yml`).
|
||||
- ansible.builtin.set_fact:
|
||||
matrix_postgres_backup_docker_image_to_use: "{{ matrix_postgres_backup_docker_image_latest if matrix_postgres_backup_detected_version_corresponding_docker_image | default('') == '' else matrix_postgres_backup_detected_version_corresponding_docker_image }}"
|
||||
|
||||
- name: Ensure postgres backup Docker image is pulled
|
||||
community.docker.docker_image:
|
||||
name: "{{ matrix_postgres_backup_docker_image_to_use }}"
|
||||
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
|
||||
force_source: "{{ matrix_postgres_backup_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
|
||||
force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_postgres_backup_docker_image_force_pull }}"
|
||||
register: result
|
||||
retries: "{{ devture_playbook_help_container_retries_count }}"
|
||||
delay: "{{ devture_playbook_help_container_retries_delay }}"
|
||||
until: result is not failed
|
||||
|
||||
- name: Ensure Postgres backup paths exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
mode: 0700
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
with_items:
|
||||
- "{{ matrix_postgres_backup_path }}"
|
||||
|
||||
- name: Ensure Postgres environment variables file created
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/{{ item }}.j2"
|
||||
dest: "{{ matrix_postgres_backup_path }}/{{ item }}"
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
mode: 0640
|
||||
with_items:
|
||||
- "env-postgres-backup"
|
||||
|
||||
- name: Ensure matrix-postgres-backup.service installed
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/systemd/matrix-postgres-backup.service.j2"
|
||||
dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-postgres-backup.service"
|
||||
mode: 0644
|
@ -1,39 +0,0 @@
|
||||
---
|
||||
|
||||
- name: Check existence of matrix-postgres-backup service
|
||||
ansible.builtin.stat:
|
||||
path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-postgres-backup.service"
|
||||
register: matrix_postgres_backup_service_stat
|
||||
|
||||
|
||||
- when: matrix_postgres_backup_service_stat.stat.exists | bool
|
||||
block:
|
||||
- name: Ensure matrix-postgres-backup is stopped
|
||||
ansible.builtin.service:
|
||||
name: matrix-postgres-backup
|
||||
state: stopped
|
||||
enabled: false
|
||||
daemon_reload: true
|
||||
|
||||
- name: Ensure matrix-postgres-backup.service doesn't exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-postgres-backup.service"
|
||||
state: absent
|
||||
|
||||
- name: Check existence of matrix-postgres-backup backup path
|
||||
ansible.builtin.stat:
|
||||
path: "{{ matrix_postgres_backup_path }}"
|
||||
register: matrix_postgres_backup_path_stat
|
||||
|
||||
# We just want to notify the user. Deleting data is too destructive.
|
||||
- name: Inject warning if matrix-postgres backup data remains
|
||||
ansible.builtin.set_fact:
|
||||
devture_playbook_runtime_messages_list: |
|
||||
{{
|
||||
devture_playbook_runtime_messages_list | default([])
|
||||
+
|
||||
[
|
||||
"NOTE: You are not using the local backup service to backup the PostgreSQL database, but some old data remains from before in `{{ matrix_postgres_backup_path }}`. Feel free to delete it."
|
||||
]
|
||||
}}
|
||||
when: matrix_postgres_backup_path_stat.stat.exists | bool
|
@ -1,27 +0,0 @@
|
||||
---
|
||||
|
||||
- name: Fail if required postgres-backup settings not defined
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
You need to define a required configuration setting (`{{ item }}`).
|
||||
when: "vars[item] == ''"
|
||||
with_items:
|
||||
- "matrix_postgres_backup_connection_hostname"
|
||||
- "matrix_postgres_backup_connection_username"
|
||||
- "matrix_postgres_backup_connection_password"
|
||||
- "matrix_postgres_backup_connection_port"
|
||||
- "matrix_postgres_backup_schedule"
|
||||
- "matrix_postgres_backup_keep_days"
|
||||
- "matrix_postgres_backup_keep_weeks"
|
||||
- "matrix_postgres_backup_keep_months"
|
||||
- "matrix_postgres_backup_path"
|
||||
- "matrix_postgres_backup_databases"
|
||||
|
||||
- name: (Deprecation) Catch and report renamed settings
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
Your configuration contains a variable, which now has a different name.
|
||||
Please change your configuration to rename the variable (`{{ item.old }}` -> `{{ item.new }}`).
|
||||
when: "item.old in vars"
|
||||
with_items:
|
||||
- {'old': 'matrix_postgres_backup_docker_image_suffix', 'new': 'matrix_postgres_backup_docker_image_distro'}
|
@ -1,12 +0,0 @@
|
||||
#jinja2: lstrip_blocks: "True"
|
||||
POSTGRES_USER={{ matrix_postgres_backup_connection_username }}
|
||||
POSTGRES_PASSWORD={{ matrix_postgres_backup_connection_password }}
|
||||
POSTGRES_HOST={{ matrix_postgres_backup_connection_hostname }}
|
||||
POSTGRES_DB={{ matrix_postgres_backup_databases|join(', ') }}
|
||||
POSTGRES_EXTRA_OPTS={{ matrix_postgres_backup_extra_opts }}
|
||||
SCHEDULE={{ matrix_postgres_backup_schedule }}
|
||||
BACKUP_KEEP_DAYS={{ matrix_postgres_backup_keep_days }}
|
||||
BACKUP_KEEP_WEEKS={{ matrix_postgres_backup_keep_weeks }}
|
||||
BACKUP_KEEP_MONTHS={{ matrix_postgres_backup_keep_months }}
|
||||
HEALTHCHECK_PORT={{ matrix_postgres_backup_healthcheck_port }}
|
||||
POSTGRES_PORT={{ matrix_postgres_backup_connection_port }}
|
@ -1,31 +0,0 @@
|
||||
#jinja2: lstrip_blocks: "True"
|
||||
[Unit]
|
||||
Description=Automatic Backup of Matrix Postgres server
|
||||
After=docker.service
|
||||
Requires=docker.service
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}"
|
||||
ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} stop matrix-postgres-backup
|
||||
ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-postgres-backup 2>/dev/null || true'
|
||||
|
||||
ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name matrix-postgres-backup \
|
||||
--log-driver=none \
|
||||
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
|
||||
--cap-drop=ALL \
|
||||
--read-only \
|
||||
--network={{ matrix_docker_network }} \
|
||||
--env-file={{ matrix_postgres_backup_path }}/env-postgres-backup \
|
||||
--mount type=bind,src={{ matrix_postgres_backup_path }},dst=/backups \
|
||||
{{ matrix_postgres_backup_docker_image_to_use }}
|
||||
|
||||
ExecStop=-{{ devture_systemd_docker_base_host_command_docker }} stop matrix-postgres-backup
|
||||
ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-postgres-backup 2>/dev/null || true'
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
SyslogIdentifier=matrix-postgres-backup
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in new issue