diff --git a/README.md b/README.md index 2e732d3..16905f1 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,8 @@ Available variables: | `keep_within` | no | If set, only keeps snapshots in this time period. | | `keep_tag` | no | If set, keep snapshots with this tags. Make sure to specify a list. | | `prune` | no (`false`) | If `true`, the `restic forget` command in the script has the [`--prune` option](https://restic.readthedocs.io/en/stable/060_forget.html#removing-backup-snapshots) appended. | -| `scheduled` | no (`false`) | If `restic_create_cron` is set to `true`, this backup is scheduled. | +| `scheduled` | no (`false`) | If `restic_create_cron` is set to `true`, this backup is scheduled and tries to create a systemd timer unit. If it fails, it is creating a cronjob. | +| `schedule_oncalendar` | ``'*-*-* 02:00:00'`` | The time for the systemd timer. Please notice the randomDelaySec option. By Default the backup is done every night at 2 am (+0-4h). But only if scheduled is true. | | `schedule_minute` | no (`*`) | Minute when the job is run. ( 0-59, *, */2, etc ) | | `schedule_hour` | no (`*`) | Hour when the job is run. ( 0-23, *, */2, etc ) | | `schedule_weekday` | no (`*`) | Weekday when the job is run. ( 0-6 for Sunday-Saturday, *, etc ) | @@ -151,7 +152,7 @@ restic_backups: repo: remove src: /path/to/data scheduled: true - schedule_hour: 3 + schedule_oncalendar: '*-*-* 01:00:00' ``` > You can also specify restic_backups as an array, which is a legacy feature and diff --git a/defaults/main.yml b/defaults/main.yml index b9af5df..01d4385 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -13,5 +13,9 @@ restic_create_cron: false restic_dir_owner: '{{ ansible_user | default(ansible_user_id) }}' restic_dir_group: '{{ ansible_user | default(ansible_user_id) }}' +# timer defaults +restic_systemd_timer_randomizeddelaysec: '4h' +restic_systemd_timer_default_OnCalendar: '*-*-* 02:00:00' + # perform simple version check for this role? (true is recomended) submodules_versioncheck: false diff --git a/tasks/configure.yml b/tasks/configure.yml index 9e09609..d3d7049 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -23,4 +23,4 @@ loop: "{{ restic_repos|dict2items }}" when: - item.value.init is defined - - item.value.init + - item.value.init|bool diff --git a/tasks/timer.yml b/tasks/timer.yml index 90f71db..cf3b48d 100644 --- a/tasks/timer.yml +++ b/tasks/timer.yml @@ -1,21 +1,4 @@ --- -- name: cleanup old CRON jobs from migration - ansible.builtin.cron: - name: 'arillso.restic backup {{ item.name }}' - job: 'CRON=true {{ restic_script_dir }}/backup-{{ item.name }}.sh' - minute: '{{ item.schedule_minute | default("*") }}' - hour: '{{ item.schedule_hour | default("*") }}' - weekday: '{{ item.schedule_weekday | default("*") }}' - month: '{{ item.schedule_month | default("*") }}' - state: absent - become: true - no_log: true - with_items: '{{ restic_backups }}' - when: - - restic_create_cron - - item.name is defined - - item.scheduled | default(false) - - name: create systemd timer block: - name: copy systemd timer diff --git a/templates/restic.timer.j2 b/templates/restic.timer.j2 index 79d80a4..00feded 100644 --- a/templates/restic.timer.j2 +++ b/templates/restic.timer.j2 @@ -2,8 +2,8 @@ Description=Run restic backup {{ item.name }} every night [Timer] -OnCalendar=*-*-* 02:00:00 -RandomizedDelaySec=3h +OnCalendar=*-*-* 02:00:00 {{ restic_systemd_timer_default_OnCalendar }} +RandomizedDelaySec={{ restic_systemd_timer_randomizeddelaysec }} Persistent=yes [Install]