diff --git a/inventory/group_vars/all/restic.yml b/inventory/group_vars/all/restic.yml index dda6556..98d9f07 100644 --- a/inventory/group_vars/all/restic.yml +++ b/inventory/group_vars/all/restic.yml @@ -12,3 +12,4 @@ restic_aws_secret_access_key: !vault | 38376163613837626435373134393630316235313032353738643537303162643538353966613833 34333735663939396433 restic_s3_url: "s3:http://backup.mateu.be:3900/backup" +restic_summary_log: "/var/log/restic/summary.json" diff --git a/roles/munin_client/files/restic_backup b/roles/munin_client/files/restic_backup new file mode 100644 index 0000000..c04ae08 --- /dev/null +++ b/roles/munin_client/files/restic_backup @@ -0,0 +1,49 @@ +#!/bin/bash + +case $1 in + config) + cat << 'EOF' +multigraph restic_file_processed +graph_title Files/dirs processed by restic +graph_vlabel Number of files/dirs processed by restic +graph_args --base 1000 -l 0 +graph_category restic +files_new.label files_new +files_changed.label files_changed +files_unmodified.label files_unmodified +dirs_new.label dirs_new +dirs_changed.label dirs_changed +dirs_unmodified.label dirs_unmodified +EOF + cat << 'EOF' +multigraph restic_data_added +graph_title Data added to repo by restic +graph_vlabel Data added in bytes +graph_args --base 1024 -l 0 +graph_category restic +data_added.label raw_data_added +data_added_packed.label compressed_data_added +EOF + cat << 'EOF' +multigraph restic_backup_duration +graph_title Restic backup duration +graph_vlabel Duration of restic backup (seconds) +graph_args --base 1000 -l 0 +graph_category restic +total_duration.label total_duration +EOF + exit 0;; +esac + +echo "multigraph restic_file_processed" +echo "files_new.value $(cat ${RESTIC_SUMMARY_LOG} | jq -r .files_new)" +echo "files_changed.value $(cat ${RESTIC_SUMMARY_LOG} | jq -r .files_changed)" +echo "files_unmodified.value $(cat ${RESTIC_SUMMARY_LOG} | jq -r .files_unmodified)" +echo "dirs_new.value $(cat ${RESTIC_SUMMARY_LOG} | jq -r .dirs_new)" +echo "dirs_changed.value $(cat ${RESTIC_SUMMARY_LOG} | jq -r .dirs_changed)" +echo "dirs_unmodified.value $(cat ${RESTIC_SUMMARY_LOG} | jq -r .dirs_unmodified)" +echo "multigraph restic_data_added" +echo "data_added.value $(cat ${RESTIC_SUMMARY_LOG} | jq -r .data_added)" +echo "data_added_packed.value $(cat ${RESTIC_SUMMARY_LOG} | jq -r .data_added_packed)" +echo "multigraph restic_backup_duration" +echo "total_duration.value $(cat ${RESTIC_SUMMARY_LOG} | jq -r .total_duration)" diff --git a/roles/munin_client/tasks/main.yml b/roles/munin_client/tasks/main.yml index 4ae9178..af61997 100644 --- a/roles/munin_client/tasks/main.yml +++ b/roles/munin_client/tasks/main.yml @@ -135,3 +135,8 @@ - name: Execute specific garage commands ansible.builtin.include_tasks: garage.yml when: "'garageservers' in group_names" + +# Specific restic commands +- name: Execute specific restic commands + ansible.builtin.include_tasks: restic.yml + when: "'resticservers' in group_names" diff --git a/roles/munin_client/tasks/restic.yml b/roles/munin_client/tasks/restic.yml new file mode 100644 index 0000000..ef83e58 --- /dev/null +++ b/roles/munin_client/tasks/restic.yml @@ -0,0 +1,28 @@ +--- + +- name: Ensure some packages are installed + ansible.builtin.package: + name: + - jq + state: present + update_cache: true + +- name: Put restic plugin configuration + ansible.builtin.template: + src: restic.j2 + dest: /etc/munin/plugin-conf.d/restic + owner: root + group: root + mode: "0o640" + notify: + - Restart munin-node + +- name: Put restic scripts + ansible.builtin.copy: + src: files/restic_backup + dest: /etc/munin/plugins/restic_backup + owner: root + group: root + mode: "0o755" + notify: + - Restart munin-node diff --git a/roles/munin_client/templates/restic.j2 b/roles/munin_client/templates/restic.j2 new file mode 100644 index 0000000..62b8a21 --- /dev/null +++ b/roles/munin_client/templates/restic.j2 @@ -0,0 +1,3 @@ +[restic_backup] +env.RESTIC_SUMMARY_LOG {{ restic_summary_log }} + diff --git a/roles/restic/templates/resticbackup.sh.j2 b/roles/restic/templates/resticbackup.sh.j2 index bb85d49..24eafb9 100644 --- a/roles/restic/templates/resticbackup.sh.j2 +++ b/roles/restic/templates/resticbackup.sh.j2 @@ -6,8 +6,11 @@ export RESTIC_REPOSITORY="{{ restic_repository }}" export AWS_ACCESS_KEY_ID="{{ restic_aws_access_key_id }}" export AWS_SECRET_ACCESS_KEY="{{ restic_aws_secret_access_key }}" +## Prépare le répertoire de log +mkdir -p {{ restic_summary_log | dirname }} + ## lancement de la sauvegarde -{{ restic_path }} backup --exclude-caches {% for i in restic_backup_excluded_path %} -e {{ i }} {% endfor %} {% for i in restic_backup_path %}{{ i }} {% endfor %} +{{ restic_path }} backup --quiet --json --exclude-caches {% for i in restic_backup_excluded_path %} -e {{ i }} {% endfor %} {% for i in restic_backup_path %}{{ i }} {% endfor %} > {{ restic_summary_log }} ## récupération de l'espace -{{ restic_path }} forget --prune {{ restic_backup_retention }} +{{ restic_path }} forget --quiet --prune {{ restic_backup_retention }}