1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic_archiver.git synced 2024-08-16 10:09:49 +02:00

introducing systemd timer

This commit is contained in:
L3D 2021-12-07 19:50:02 +01:00
parent 186f2d80eb
commit e653dc55c2
Signed by: l3d
GPG key ID: CD08445BFF4313D1
7 changed files with 75 additions and 4 deletions

View file

@ -33,8 +33,10 @@ restic_archiver__owner: 'root'
restic_archiver__group: 'root' restic_archiver__group: 'root'
# shedule restic cronjob # shedule restic cronjob
restic_archiver__hour: '3' restic_archiver__hour: '4'
restic_archiver__minute: '32' restic_archiver__minute: '23'
restic_archiver__oncalendar: '*-*-* 04:23:00'
restic_archiver__randomizeddelaysec: '900'
# validate if disk is mounted # validate if disk is mounted
restic_archiver__mount_required: false restic_archiver__mount_required: false
@ -66,3 +68,5 @@ restic_archiver__cache_config: false
restic_archiver__cache_dir: '~/.cache/restic' restic_archiver__cache_dir: '~/.cache/restic'
restic_archiver__prune: false restic_archiver__prune: false
restic_archiver__use_systemd_timer: true

18
handlers/main.yml Normal file
View file

@ -0,0 +1,18 @@
---
- name: systemctl daemon-reload
become: true
ansible.builtin.systemd:
daemon_reload: true
- name: systemctl start restic-archiver.timer
become: true
ansible.builtin.systemd:
name: restic-archiver.timer
enabled: true
state: started
- name: systemctl enable restic-archiver.service
become: true
ansible.builtin.systemd:
name: restic-archiver.service
enabled: true

View file

@ -18,7 +18,11 @@
- name: create cronjob - name: create cronjob
ansible.builtin.include_tasks: cron.yml ansible.builtin.include_tasks: cron.yml
# todo: replace with systemd timer when: not restic_archiver__use_systemd_timer | bool
- name: create systemd timer
ansible.builtin.include_tasks: systemd.yml
when: restic_archiver__use_systemd_timer | bool
- name: install requirements for mailing - name: install requirements for mailing
ansible.builtin.include_tasks: mail.yml ansible.builtin.include_tasks: mail.yml

24
tasks/systemd.yml Normal file
View file

@ -0,0 +1,24 @@
---
- name: create restic-archiver.service
become: true
ansible.builtin.template:
src: templates/restic-archiver.service.j2
dest: /lib/systemd/system/restic-archiver.service
mode: 0644
owner: root
group: root
notify:
- systemctl daemon-reload
- systemctl enable restic-archiver.service
- name: create restic-archiver.timer
become: true
ansible.builtin.template:
src: templates/restic-archiver.timer.j2
dest: /lib/systemd/system/restic-archiver.timer
mode: 0644
owner: root
group: root
notify:
- systemctl daemon-reload
- systemctl start restic-archiver.timer

View file

@ -0,0 +1,11 @@
[Unit]
Description=restic-archiver
Documentation=https://github.com/roles-ansible/ansible_role_restic_archiver.git
[Service]
Type=oneshot
ExecStart=/opt/restic-backup.sh
TimeoutStartSec=0
{% if restic_archiver__log_output -%}
StandardOutput=append:/var/log/restic/restic_archiver.log
{%- endif -%}

View file

@ -0,0 +1,10 @@
[Unit]
Description=Systemd Timer to run the Restic archiver from /opt/restic-backup.sh
[Timer]
OnCalendar={{ restic_archiver__oncalendar | default('*-*-* 04:23:00') }}
RandomizedDelaySec={{ restic_archiver__randomizeddelaysec }}
Persistent=true
[Install]
WantedBy=timers.target

View file

@ -1,3 +1,3 @@
--- ---
playbook_version_number: 49 # should be int playbook_version_number: 50 # should be int
playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version' playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'