diff --git a/README.md b/README.md index 53f7d63..1c5afbe 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Liste des éléments exclus de la sauvegarde. ### borgmatic_repositories -Liste des dépôts Borg sur lesquels envoyer la sauvegarde. +Dictionnaire contenant le `label` et le `path` des dépôts vers lesquels envoyer la sauvegarde. *Valeur par défaut: aucune* diff --git a/defaults/main.yml b/defaults/main.yml index 1dcea10..e1f5a8f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -12,14 +12,22 @@ borgmatic_checks: frequency: 4 weeks - name: extract frequency: 2 weeks + borgmatic_healthchecks: "" borgmatic_exclude_patterns: [] + borgmatic_repositories: [] +# Exemple: +# - label: default +# path: ssh://user@backupserver/./sourcehostname.borg + borgmatic_source_directories: [] + borgmatic_retention: daily: 7 monthly: 0 weekly: 4 + borgmatic_name: "{{ inventory_hostname }}_{now}" borgmatic_compression: none borgmatic_passphrase: "" diff --git a/handlers/main.yml b/handlers/main.yml index c3fb423..5218062 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -3,8 +3,16 @@ - name: Créer le dépôt ansible.builtin.command: - cmd: borgmatic init --encryption repokey-blake2 + cmd: borg init -e repokey-blake2 {{ item.path }} become: true + loop: "{{ borgmatic_repositories }}" + register: borg_init + failed_when: + - "'A repository already exists' not in borg_init.stderr" + - borg_init.rc != 0 + changed_when: + - "'A repository already exists' not in borg_init.stderr" + - borg_init.rc == 0 - name: Activer la planification ansible.builtin.systemd: diff --git a/tasks/configuration.yml b/tasks/configuration.yml index 51d1246..5e8e6f4 100644 --- a/tasks/configuration.yml +++ b/tasks/configuration.yml @@ -26,7 +26,7 @@ marker: "# {mark} ANSIBLE MANAGED BLOCK for role_borgmatic" block: | {% for repository in borgmatic_repositories %} - Host {{ repository | ansible.builtin.urlsplit('hostname') }} + Host {{ repository.path | ansible.builtin.urlsplit('hostname') }} IdentityFile /etc/borgmatic/id_ed25519 IdentitiesOnly yes {% endfor %} diff --git a/templates/config.yaml.j2 b/templates/config.yaml.j2 index 7646025..f10c8d6 100644 --- a/templates/config.yaml.j2 +++ b/templates/config.yaml.j2 @@ -1,24 +1,41 @@ --- +repositories: +{% for repository in borgmatic_repositories %} + - label: {{ repository.label }} + path: {{ repository.path }} +{% endfor %} + +exclude_patterns: +{% for pattern in borgmatic_exclude_patterns %} + - {{ pattern }} +{% endfor %} + +source_directories: +{% for directory in borgmatic_source_directories %} + - {{ directory }} +{% endfor %} + +archive_name_format: {{ borgmatic_name }} +compression: {{ borgmatic_compression }} +encryption_passphrase: {{ borgmatic_passphrase }} + consistency: - checks: {{ borgmatic_checks }} + checks: +{% for check in borgmatic_checks %} + - name: {{ check.name }} + frequency: {{ check.frequency }} +{% endfor %} hooks: healthchecks: ping_url: {{ borgmatic_healthchecks }} send_logs: false - -location: - exclude_patterns: {{ borgmatic_exclude_patterns }} - repositories: {{ borgmatic_repositories }} - source_directories: {{ borgmatic_source_directories }} + states: + - finish + - fail retention: keep_daily: {{ borgmatic_retention.daily }} keep_monthly: {{ borgmatic_retention.monthly }} keep_weekly: {{ borgmatic_retention.weekly }} - -storage: - archive_name_format: {{ borgmatic_name }} - compression: {{ borgmatic_compression }} - encryption_passphrase: {{ borgmatic_passphrase }}