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

Merge pull request #12 from roles-ansible/cron

introducing systemd timer
This commit is contained in:
L3D 2021-12-08 11:24:09 +01:00 committed by GitHub
commit 29086b5000
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 83 additions and 150 deletions

View file

@ -1,18 +0,0 @@
---
name: Ansible check debian:bullseye
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: ansible check with debian:bullseye
uses: roles-ansible/check-ansible-debian-bullseye-action@main
with:
targets: "./"

View file

@ -1,18 +0,0 @@
---
name: Ansible check debian:buster
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: ansible check with debian:buster
uses: roles-ansible/check-ansible-debian-buster-action@master
with:
targets: "./"

View file

@ -1,18 +0,0 @@
---
name: Ansible check debian:latest
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: ansible check with debian:latest
uses: roles-ansible/check-ansible-debian-latest-action@master
with:
targets: "./"

View file

@ -1,18 +0,0 @@
---
name: Ansible check debian:sid
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: ansible check with debian:sid
uses: roles-ansible/check-ansible-debian-sid-action@master
with:
targets: "./"

View file

@ -1,18 +0,0 @@
---
name: Ansible check debian:stable
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: ansible check with debian:stable
uses: roles-ansible/check-ansible-debian-stable-action@master
with:
targets: "./"

View file

@ -1,18 +0,0 @@
---
name: Ansible check debian:stretch
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: ansible check with debian:stretch
uses: roles-ansible/check-ansible-debian-stretch-action@master
with:
targets: "./"

View file

@ -1,18 +0,0 @@
---
name: Ansible check ubuntu:latest
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: ansible check with ubuntu:latest
uses: roles-ansible/check-ansible-ubuntu-latest-action@master
with:
targets: "./"

View file

@ -1,18 +0,0 @@
---
name: Ansible check ubuntu:trusty
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: ansible check with ubuntu:trusty
uses: roles-ansible/check-ansible-ubuntu-trusty-action@master
with:
targets: "./"

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

@ -5,12 +5,18 @@
name: "{{ restic_archiver__package }}" name: "{{ restic_archiver__package }}"
state: present state: present
- name: migrate cronjob to cron.d directory
become: true
ansible.builtin.cron:
name: "archive restic backup with ansible_role_restic_archiver"
state: absent
- name: setup cronjob for restic with logging - name: setup cronjob for restic with logging
become: true become: true
ansible.builtin.cron: ansible.builtin.cron:
name: "archive restic backup with ansible_role_restic_archiver" name: "archive restic backup with ansible_role_restic_archiver"
job: /opt/restic-backup.sh >> /var/log/restic/restic_archiver.log job: /opt/restic-backup.sh >> /var/log/restic/restic_archiver.log
cron_file: /etc/crontab cron_file: restic_archiver
hour: "{{ restic_archiver__hour }}" hour: "{{ restic_archiver__hour }}"
minute: "{{ restic_archiver__minute }}" minute: "{{ restic_archiver__minute }}"
user: "{{ restic_archiver__owner }}" user: "{{ restic_archiver__owner }}"
@ -21,7 +27,7 @@
ansible.builtin.cron: ansible.builtin.cron:
name: "archive restic backup with ansible_role_restic_archiver" name: "archive restic backup with ansible_role_restic_archiver"
job: /opt/restic-backup.sh job: /opt/restic-backup.sh
cron_file: /etc/crontab cron_file: restic_archiver
hour: "{{ restic_archiver__hour }}" hour: "{{ restic_archiver__hour }}"
minute: "{{ restic_archiver__minute }}" minute: "{{ restic_archiver__minute }}"
user: "{{ restic_archiver__owner }}" user: "{{ restic_archiver__owner }}"

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'