borgmatic : remplacement cron par timer systemdl

mise_a_niveau
korenstin 2025-01-19 23:33:29 +01:00
parent 6d6e32a7dc
commit d781e110d9
5 changed files with 51 additions and 12 deletions

View File

@ -0,0 +1,9 @@
---
- name: Restart timer
service:
name: borgmatic.timer
state: restarted
- name: systemctl daemon-reload
systemd:
daemon_reload: true

View File

@ -61,13 +61,27 @@
register: borg_init register: borg_init
changed_when: '"does not exist" in borg_init.stderr' changed_when: '"does not exist" in borg_init.stderr'
- name: Deploy borg cron - name: Deploy borgmatic systemd
template: template:
src: cron.d/borg.j2 src: "systemd/system/{{ item }}.j2"
dest: /etc/cron.d/borg{{ borg.path_suffix | default('') }} dest: /etc/systemd/system/{{ item }}
mode: 0600
owner: root
group: root
loop:
- borgmatic.service
- borgmatic.timer
notify:
- Restart timer
- systemctl daemon-reload
- name: Indicate role in motd - name: Indicate role in motd
template: template:
src: update-motd.d/04-service.j2 src: update-motd.d/04-service.j2
dest: /etc/update-motd.d/04-borgbackup dest: /etc/update-motd.d/04-borgbackup
mode: 0755 mode: 0755
- name: Enable timer
service:
name: borgmatic.timer
enabled: true

View File

@ -1,9 +0,0 @@
{{ ansible_header | comment }}
PATH=$PATH:/usr/sbin:/usr/bin:/usr/local/bin:/sbin:/bin
{% if borg.path_suffix is defined %}
{{ 60 | random(seed=inventory_hostname) }} {{ 24 | random(seed=inventory_hostname) }} * * * root borgmatic -c /etc/borgmatic/config{{ borg.path_suffix }}.yaml --syslog-verbosity 1
{% else %}
{{ 60 | random(seed=inventory_hostname) }} {{ 24 | random(seed=inventory_hostname) }} * * * root borgmatic --syslog-verbosity 1
{% endif %}

View File

@ -0,0 +1,15 @@
{{ ansible_header | comment }}
[Unit]
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
User=root
{% if borg.path_suffix is defined %}
ExecStart=borgmatic -c /etc/borgmatic/config{{ borg.path_suffix }}.yaml --syslog-verbosity 1
{% else %}
ExecStart=borgmatic --syslog-verbosity 1
{% endif %}

View File

@ -0,0 +1,10 @@
{{ ansible_header | comment }}
[Unit]
[Timer]
OnCalendar={{ 24 | random(seed=inventory_hostname) }}:{{ 60 | random(seed=inventory_hostname) }}
Persistent=true
[Install]
WantedBy=timers.target