development
Aine 3 years ago
parent d5f4c17146
commit a9d0cbc560
No known key found for this signature in database
GPG Key ID: 34969C908CCA2804

@ -5,9 +5,10 @@ matrix_backup_borg_base_path: "{{ matrix_base_data_path }}/backup-borg"
matrix_backup_borg_config_path: "{{ matrix_backup_borg_base_path }}/config" matrix_backup_borg_config_path: "{{ matrix_backup_borg_base_path }}/config"
matrix_backup_borg_container_image_self_build: false matrix_backup_borg_container_image_self_build: false
matrix_backup_borg_docker_repo: "https://github.com/borgmatic-collective/docker-borgmatic" matrix_backup_borg_docker_repo: "https://gitlab.com/etke.cc/borgmatic"
matrix_backup_borg_docker_src_files_path: "{{ matrix_backup_borg_base_path }}/docker-src" matrix_backup_borg_docker_src_files_path: "{{ matrix_backup_borg_base_path }}/docker-src"
# version determined automatically, based on postgres server version (if enabled), otherwise latest is used
matrix_backup_borg_version: "" matrix_backup_borg_version: ""
matrix_backup_borg_docker_image: "{{ matrix_backup_borg_docker_image_name_prefix }}etke.cc/borgmatic:{{ matrix_backup_borg_version }}" matrix_backup_borg_docker_image: "{{ matrix_backup_borg_docker_image_name_prefix }}etke.cc/borgmatic:{{ matrix_backup_borg_version }}"
matrix_backup_borg_docker_image_name_prefix: "{{ 'localhost/' if matrix_backup_borg_container_image_self_build else 'registry.gitlab.com/' }}" matrix_backup_borg_docker_image_name_prefix: "{{ 'localhost/' if matrix_backup_borg_container_image_self_build else 'registry.gitlab.com/' }}"
@ -30,6 +31,7 @@ matrix_backup_borg_location_source_directories: []
# postgres db backup # postgres db backup
matrix_backup_borg_postgresql_enabled: true matrix_backup_borg_postgresql_enabled: true
matrix_backup_borg_supported_postgres_versions: ['12', '13', '14']
matrix_backup_borg_postgresql_databases: [] matrix_backup_borg_postgresql_databases: []
matrix_backup_borg_postgresql_databases_hostname: "matrix-postgres" matrix_backup_borg_postgresql_databases_hostname: "matrix-postgres"
matrix_backup_borg_postgresql_databases_username: "matrix" matrix_backup_borg_postgresql_databases_username: "matrix"
@ -55,7 +57,7 @@ matrix_backup_borg_storage_ssh_command: ssh -o "StrictHostKeyChecking accept-new
matrix_backup_borg_storage_compression: lz4 matrix_backup_borg_storage_compression: lz4
# archive name format # archive name format
matrix_backup_borg_storage_archive_name_format: "matrix-{now:%Y-%m-%d-%H%M%S}" matrix_backup_borg_storage_archive_name_format: matrix-{now:%Y-%m-%d-%H%M%S}
# repository passphrase # repository passphrase
matrix_backup_borg_storage_encryption_passphrase: "" matrix_backup_borg_storage_encryption_passphrase: ""
@ -68,7 +70,7 @@ matrix_backup_borg_retention_keep_monthly: 12
matrix_backup_borg_retention_keep_yearly: 2 matrix_backup_borg_retention_keep_yearly: 2
# retention prefix # retention prefix
matrix_backup_borg_retention_prefix: "matrix-" matrix_backup_borg_retention_prefix: matrix-
# Default borgmatic configuration template which covers the generic use case. # Default borgmatic configuration template which covers the generic use case.
# You can customize it by controlling the various variables inside it. # You can customize it by controlling the various variables inside it.

@ -1,6 +1,16 @@
--- ---
- import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml" - block:
when: 'matrix_backup_borg_enabled|bool and matrix_backup_borg_postgresql_enabled|bool and matrix_postgres_backup_postgres_data_path != ""' - 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 - name: Ensure borg paths exist
file: 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 == ''"

@ -7,18 +7,18 @@ location:
exclude_patterns: {{ matrix_backup_borg_location_exclude_patterns|to_json }} exclude_patterns: {{ matrix_backup_borg_location_exclude_patterns|to_json }}
storage: storage:
compression: {{ matrix_backup_borg_storage_compression }} compression: {{ matrix_backup_borg_storage_compression|to_json }}
ssh_command: {{ matrix_backup_borg_storage_ssh_command }} ssh_command: {{ matrix_backup_borg_storage_ssh_command|to_json }}
archive_name_format: '{{ matrix_backup_borg_storage_archive_name_format }}' archive_name_format: {{ matrix_backup_borg_storage_archive_name_format|to_json }}
encryption_passphrase: {{ matrix_backup_borg_storage_encryption_passphrase }} encryption_passphrase: {{ matrix_backup_borg_storage_encryption_passphrase|to_json }}
retention: retention:
keep_hourly: {{ matrix_backup_borg_retention_keep_hourly }} keep_hourly: {{ matrix_backup_borg_retention_keep_hourly|to_json }}
keep_daily: {{ matrix_backup_borg_retention_keep_daily }} keep_daily: {{ matrix_backup_borg_retention_keep_daily|to_json }}
keep_weekly: {{ matrix_backup_borg_retention_keep_weekly }} keep_weekly: {{ matrix_backup_borg_retention_keep_weekly|to_json }}
keep_monthly: {{ matrix_backup_borg_retention_keep_monthly }} keep_monthly: {{ matrix_backup_borg_retention_keep_monthly|to_json }}
keep_yearly: {{ matrix_backup_borg_retention_keep_yearly }} keep_yearly: {{ matrix_backup_borg_retention_keep_yearly|to_json }}
prefix: '{{ matrix_backup_borg_retention_prefix }}' prefix: {{ matrix_backup_borg_retention_prefix|to_json }}
consistency: consistency:
checks: checks:
@ -26,14 +26,14 @@ consistency:
- archives - archives
hooks: hooks:
{% if matrix_backup_borg_postgresql_enabled %} {% if matrix_backup_borg_postgresql_enabled and matrix_backup_borg_postgresql_databases|length > 0 %}
postgresql_databases: postgresql_databases:
{% for database in matrix_backup_borg_postgresql_databases %} {% for database in matrix_backup_borg_postgresql_databases %}
- name: {{ database }} - name: {{ database|to_json }}
hostname: {{ matrix_backup_borg_postgresql_databases_hostname }} hostname: {{ matrix_backup_borg_postgresql_databases_hostname|to_json }}
username: {{ matrix_backup_borg_postgresql_databases_username }} username: {{ matrix_backup_borg_postgresql_databases_username|to_json }}
password: {{ matrix_backup_borg_postgresql_databases_password }} password: {{ matrix_backup_borg_postgresql_databases_password|to_json }}
port: {{ matrix_backup_borg_postgresql_databases_port }} port: {{ matrix_backup_borg_postgresql_databases_port|to_json }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
after_backup: after_backup:

Loading…
Cancel
Save