This commit is contained in:
Aine
2022-04-15 19:38:10 +03:00
parent d5f4c17146
commit a9d0cbc560
4 changed files with 33 additions and 63 deletions

View File

@ -1,6 +1,16 @@
---
- import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml"
when: 'matrix_backup_borg_enabled|bool and matrix_backup_borg_postgresql_enabled|bool and matrix_postgres_backup_postgres_data_path != ""'
- block:
- import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/detect_existing_postgres_version.yml"
- name: Fail if detected Postgres version is unsupported
fail:
msg: "You cannot use borg backup with such an old version ({{ matrix_postgres_detected_version }}) of Postgres. Consider upgrading - link to docs for upgrading Postgres: docs/maintenance-postgres.md#upgrading-postgresql"
when: "matrix_postgres_detected_version not in matrix_backup_borg_supported_postgres_versions"
- name: Set the correct borg backup version to use
set_fact:
matrix_backup_borg_version: "{{ matrix_postgres_detected_version }}"
when: matrix_backup_borg_postgresql_enabled|bool and matrix_backup_borg_version == ''
- name: Ensure borg paths exist
file:

View File

@ -1,42 +0,0 @@
---
# This utility aims to determine if there is some existing Postgres version in use or not.
# If there is, it also tries to detect the Docker image that corresponds to that version.
- name: Initialize Postgres version determination variables (default to empty)
set_fact:
matrix_backup_borg_postgresql_detection_pg_version_path: "{{ matrix_postgres_data_path }}/PG_VERSION"
matrix_backup_borg_postgresql_detected_existing: false
matrix_backup_borg_postgresql_detected_version: ""
matrix_backup_borg_version: ""
- name: Determine existing Postgres version (check PG_VERSION file)
stat:
path: "{{ matrix_backup_borg_postgresql_detection_pg_version_path }}"
register: result_pg_version_stat
- set_fact:
matrix_backup_borg_postgresql_detected_existing: true
when: "result_pg_version_stat.stat.exists"
- name: Determine existing Postgres version (read PG_VERSION file)
slurp:
src: "{{ matrix_backup_borg_postgresql_detection_pg_version_path }}"
register: result_pg_version
when: matrix_backup_borg_postgresql_detected_existing|bool
- name: Determine existing Postgres version (make sense of PG_VERSION file)
set_fact:
matrix_backup_borg_postgresql_detected_version: "{{ result_pg_version['content']|b64decode|replace('\n', '') }}"
when: matrix_backup_borg_postgresql_detected_existing|bool
- name: Determine corresponding Docker image version to detected version
set_fact:
matrix_backup_borg_version: "{{ matrix_backup_borg_postgresql_detected_version }}"
when: "matrix_backup_borg_postgresql_detected_version == '12' or matrix_backup_borg_postgresql_detected_version.startswith('12.') or matrix_backup_borg_postgresql_detected_version == '13' or matrix_backup_borg_postgresql_detected_version.startswith('13.') or matrix_backup_borg_postgresql_detected_version == '14' or matrix_backup_borg_postgresql_detected_version.startswith('14.')"
- name: Fail if existing Postgres version is not supported by borgmatic docker image
fail:
msg: >-
Your Postgres v{{ matrix_backup_borg_postgresql_detected_version }} is not supported.
when: "matrix_backup_borg_version == ''"