matrix-backup-borg: integrate postgres backups, add extended borgmatic configuration

This commit is contained in:
Aine
2022-04-14 18:06:54 +03:00
parent 2df993977a
commit d5f4c17146
6 changed files with 121 additions and 16 deletions

View File

@ -1,4 +1,7 @@
---
- 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 != ""'
- name: Ensure borg paths exist
file:
path: "{{ item.path }}"
@ -11,9 +14,9 @@
- {path: "{{ matrix_backup_borg_docker_src_files_path }}", when: true}
when: "item.when|bool"
- name: Ensure borg config is created
template:
src: "{{ role_path }}/templates/config.yaml.j2"
- name: Ensure borgmatic config is created
copy:
content: "{{ matrix_backup_borg_configuration|to_nice_yaml(indent=2, width=999999) }}"
dest: "{{ matrix_backup_borg_config_path }}/config.yaml"
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}"

View File

@ -0,0 +1,42 @@
---
# 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 == ''"