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:
commit
29086b5000
16 changed files with 83 additions and 150 deletions
18
.github/workflows/ansible-debian-bullseye.yml
vendored
18
.github/workflows/ansible-debian-bullseye.yml
vendored
|
@ -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: "./"
|
|
18
.github/workflows/ansible-debian-buster.yml
vendored
18
.github/workflows/ansible-debian-buster.yml
vendored
|
@ -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: "./"
|
|
18
.github/workflows/ansible-debian-latest.yml
vendored
18
.github/workflows/ansible-debian-latest.yml
vendored
|
@ -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: "./"
|
|
18
.github/workflows/ansible-debian-sid.yml
vendored
18
.github/workflows/ansible-debian-sid.yml
vendored
|
@ -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: "./"
|
|
18
.github/workflows/ansible-debian-stable.yml
vendored
18
.github/workflows/ansible-debian-stable.yml
vendored
|
@ -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: "./"
|
|
18
.github/workflows/ansible-debian-stretch.yml
vendored
18
.github/workflows/ansible-debian-stretch.yml
vendored
|
@ -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: "./"
|
|
18
.github/workflows/ansible-ubuntu-latest.yml
vendored
18
.github/workflows/ansible-ubuntu-latest.yml
vendored
|
@ -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: "./"
|
|
18
.github/workflows/ansible-ubuntu-trusty.yml
vendored
18
.github/workflows/ansible-ubuntu-trusty.yml
vendored
|
@ -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: "./"
|
|
|
@ -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
18
handlers/main.yml
Normal 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
|
|
@ -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 }}"
|
||||||
|
|
|
@ -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
24
tasks/systemd.yml
Normal 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
|
11
templates/restic-archiver.service.j2
Normal file
11
templates/restic-archiver.service.j2
Normal 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 -%}
|
10
templates/restic-archiver.timer.j2
Normal file
10
templates/restic-archiver.timer.j2
Normal 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
|
|
@ -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'
|
||||||
|
|
Loading…
Reference in a new issue