Compare commits

..

No commits in common. "restoreFirst" and "master" have entirely different histories.

10 changed files with 46 additions and 143 deletions

View File

@ -70,12 +70,6 @@ Phrase de passe de chiffrement de la sauvegarde.
*<span style="text-decoration: underline">Valeur par défaut:</span> aucune*
### borgmatic_restore_first
Booléen permettant de restaurer une sauvegarde au déploiement du rôle.
*<span style="text-decoration: underline">Valeur par défaut:</span> `false`*
## Exemples
### host_vars/host1.ykn.local

View File

@ -29,11 +29,5 @@ borgmatic_retention:
weekly: 4
borgmatic_name: "{{ inventory_hostname }}_{now}"
borgmatic_compression: lz4
borgmatic_compression: none
borgmatic_passphrase: ""
borgmatic_actions: {}
borgmatic_mariadb_enabled: false
borgmatic_postgresql_enabled: false
borgmatic_restore_first: false

View File

@ -3,7 +3,7 @@
- name: Créer le dépôt
ansible.builtin.command:
cmd: borgmatic init --encryption repokey
cmd: borg init -e repokey-blake2 {{ item.path }}
become: true
loop: "{{ borgmatic_repositories }}"
register: borg_init
@ -18,14 +18,14 @@
ansible.builtin.systemd:
daemon_reload: true
enabled: true
state: started
state: stopped
name: borgmatic.timer
become: true
- name: S'assurer que le service est désactivé
- name: Activer et démarrer le service
ansible.builtin.systemd:
daemon_reload: true
enabled: false
state: stopped
state: started
name: borgmatic.service
become: true

View File

@ -1,36 +1,23 @@
---
# tasks file for borgmatic
- name: Créer la paire de clés
community.crypto.openssh_keypair:
path: /etc/borgmatic/id_ed25519
type: ed25519
- name: Déployer la clef privée
ansible.builtin.copy:
content: "{{ borgmatic_keys.private }}"
dest: /etc/borgmatic/id_ed25519
owner: root
group: root
mode: u=rw,g=,o=
become: true
- name: Récupérer le contenu de la clé publique
ansible.builtin.slurp:
src: /etc/borgmatic/id_ed25519.pub
- name: Déployer la clef publique
ansible.builtin.copy:
content: "{{ borgmatic_keys.public }}"
dest: /etc/borgmatic/id_ed25519.pub
owner: root
group: root
mode: u=rw,g=r,o=r
become: true
register: key
- name: Créer le dépôt
ansible.builtin.file:
path: "{{ borgmatic_server.repo_path }}/{{ inventory_hostname }}"
state: directory
owner: "{{ borgmatic_server.user }}"
group: "{{ borgmatic_server.group }}"
mode: u=rwX,g=rX,o=
become: true
delegate_to: "{{ borgmatic_server.host }}"
- name: Ajouter la clef publique
ansible.posix.authorized_key:
user: "{{ borgmatic_server.user }}"
state: present
key: "{{ key['content'] | b64decode }}"
key_options: 'command="cd {{ borgmatic_server.repo_path }}/{{ inventory_hostname }};borg serve --restrict-to-path {{ borgmatic_server.repo_path }}/{{ inventory_hostname }}",restrict'
become: true
delegate_to: "{{ borgmatic_server.host }}"
- name: Déployer la configuration de SSH
ansible.builtin.blockinfile:
@ -40,11 +27,6 @@
block: |
{% for repository in borgmatic_repositories %}
Host {{ repository.path | ansible.builtin.urlsplit('hostname') }}
Compression yes
Protocol 2
PreferredAuthentications=publickey
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
IdentityFile /etc/borgmatic/id_ed25519
IdentitiesOnly yes
{% endfor %}
@ -57,7 +39,6 @@
owner: root
group: root
mode: u=rw,g=,o=
validate: borgmatic config validate --config %s
become: true
notify: Créer le dépôt
@ -69,7 +50,7 @@
group: root
mode: u=rw,g=r,o=r
become: true
notify: S'assurer que le service est désactivé
notify: Activer et démarrer le service
- name: Déployer le service et la planification
ansible.builtin.template:

View File

@ -1,46 +1,27 @@
---
# tasks file for borgmatic
- name: Installer les prérequis
- name: Installer python3-pip
ansible.builtin.apt:
name: python3-pip
state: latest
name:
- pipx
- build-essential
- libacl1-dev
- libacl1
- libb2-dev
- liblz4-dev
- libssl-dev
- libxxhash-dev
- libzstd-dev
- pkg-config
- python3
- python3-dev
- python3-pkgconfig
become: true
- name: Installer les paquets
community.general.pipx:
- name: Installer borgbackup
ansible.builtin.apt:
name: borgbackup
state: latest
name: "{{ item }}"
install_deps: true
include_injected: true
default_release: "{{ borgmatic_distribution_release }}-backports"
become: true
environment:
PIPX_HOME: /opt/pipx
PIPX_BIN_DIR: /usr/local/bin
loop:
- borgbackup
- borgmatic
- name: S'assurer que les paquets sont inclus dans le path
ansible.builtin.command:
cmd: pipx ensurepath
- name: Installer le paquet avec pip
ansible.builtin.pip:
name: borgmatic
state: latest
become: true
- name: Créer l'exemple de configuration
ansible.builtin.command:
cmd: borgmatic config generate
cmd: generate-borgmatic-config
creates: /etc/borgmatic/config.yaml
become: true

View File

@ -6,6 +6,3 @@
- name: Importer les tâches de configuration
ansible.builtin.import_tasks: configuration.yml
- name: Importer les tâches de restauration
ansible.builtin.import_tasks: restore.yml

View File

@ -1,10 +0,0 @@
---
# tasks file for borgmatic
- name: Restaurer la sauvegarde la plus récente la sauvegarde la plus récente
ansible.builtin.command:
cmd: borgmatic extract --archive latest --path {{ directory }}
chdir: "{{ directory }}"
removes: "{{ directory }}"
when: borgmatic_restore_first
loop: "{{ borgmatic_source_directories }}"

View File

@ -1,5 +1,3 @@
# {{ ansible_managed }}
[Unit]
Description=borgmatic backup
Wants=network-online.target

View File

@ -1,5 +1,3 @@
# {{ ansible_managed }}
[Unit]
Description=Run borgmatic backup

View File

@ -1,5 +1,4 @@
---
# {{ ansible_managed }}
repositories:
{% for repository in borgmatic_repositories %}
@ -7,65 +6,36 @@ repositories:
path: {{ repository.path }}
{% endfor %}
{% if borgmatic_exclude_patterns | length > 0 %}
exclude_patterns:
{% for pattern in borgmatic_exclude_patterns %}
- {{ pattern }}
{% endfor %}
{% endif %}
{% if borgmatic_source_directories | length > 0%}
source_directories:
{% for directory in borgmatic_source_directories %}
- {{ directory }}
{% endfor %}
{% endif %}
archive_name_format: {{ borgmatic_name }}
compression: {{ borgmatic_compression }}
encryption_passphrase: {{ borgmatic_passphrase }}
checks:
consistency:
checks:
{% for check in borgmatic_checks %}
- name: {{ check.name }}
frequency: {{ check.frequency }}
- name: {{ check.name }}
frequency: {{ check.frequency }}
{% endfor %}
healthchecks:
ping_url: {{ borgmatic_healthchecks }}
send_logs: false
# states:
# - finish
# - fail
hooks:
healthchecks:
ping_url: {{ borgmatic_healthchecks }}
send_logs: false
states:
- finish
- fail
{% if borgmatic_retention | length > 0 %}
{% for param, value in borgmatic_retention.items() %}
keep_{{ param }}: {{ value }}
{% endfor %}
{% endif %}
{% if borgmatic_actions | length > 0 %}
{% for param, values in borgmatic_actions.items() %}
{{ param }}:
{% for value in values %}
- {{ value }}
{% endfor %}
{% endfor %}
{% endif %}
{% if borgmatic_mariadb_enabled %}
mariadb_databases:
- name: all
format: sql
add_drop_database: true
{% endif %}
{% if borgmatic_postgresql_enabled %}
postgresql_databases:
- name: all
username: postgres
format: plain
pg_dump_command: sudo -u postgres pg_dump
pg_restore_command: sudo -u postgres pg_restore
psql_command: sudo -u postgres psql
{% endif %}
retention:
keep_daily: {{ borgmatic_retention.daily }}
keep_monthly: {{ borgmatic_retention.monthly }}
keep_weekly: {{ borgmatic_retention.weekly }}