diff --git a/README.md b/README.md index 4fd62ce..ee4e5e1 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ Available variables: | `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_hour` | no (`2`) | 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 ) | | `schedule_month` | no (`*`) | Month when the job is run. ( 1-12, *, */2, etc ) | | `exclude` | no (`{}`) | Allows you to specify files to exclude. See [Exclude](#exclude) for reference. | diff --git a/tasks/timer.yml b/tasks/timer.yml index cf3b48d..695b4a7 100644 --- a/tasks/timer.yml +++ b/tasks/timer.yml @@ -70,9 +70,28 @@ - restic_create_cron - item.name is defined - item.scheduled | default(false) + + - name: delete old cronjob entry if available + ansible.builtin.cron: + name: "do1jlr.restic backup {{ item.name }}" + job: "CRON=true {{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh" + minute: '{{ item.schedule_minute | default("*") }}' + hour: '{{ item.schedule_hour | default("2") }}' + weekday: '{{ item.schedule_weekday | default("*") }}' + month: '{{ item.schedule_month | default("*") }}' + state: absent + cron_file: '/etc/crontab' + user: 'root' + become: true + no_log: true + with_items: '{{ restic_backups }}' + when: + - restic_create_cron + - item.name is defined + - item.scheduled | default(false) when: ansible_service_mgr == 'systemd' rescue: - - name: set ceonjo intead of systemd + - name: set cronjob intead of systemd set_fact: restic_force_cron: true @@ -82,7 +101,7 @@ name: "do1jlr.restic backup {{ item.name }}" job: "CRON=true {{ restic_script_dir }}/backup-{{ item.name | replace(' ', '') }}.sh" minute: '{{ item.schedule_minute | default("*") }}' - hour: '{{ item.schedule_hour | default("*") }}' + hour: '{{ item.schedule_hour | default("2") }}' weekday: '{{ item.schedule_weekday | default("*") }}' month: '{{ item.schedule_month | default("*") }}' state: present diff --git a/templates/restic_script_Linux.j2 b/templates/restic_script_Linux.j2 index 7355176..f1ab0c3 100644 --- a/templates/restic_script_Linux.j2 +++ b/templates/restic_script_Linux.j2 @@ -145,6 +145,10 @@ then else echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" >> {{ forget_result_log }} {% if item.mail_on_error is defined and item.mail_on_error == true %} - mail -s "restic backup failed on {{ ansible_hostname }}" {{ item.mail_address }} <<< 'Something went wrong while running restic backup script at {{ ansible_hostname }}' + mail -s "restic backup failed on {{ ansible_hostname }}" {{ item.mail_address }} <<< "Something went wrong while running restic backup script running at {{ ansible_hostname }} at $(date -u '+%Y-%m-%d %H:%M:%S'). + {%- if item.src is defined -%} + {{ ' ' }}We tried to backup '{{ item.src }}'. + {%- endif -%} + {{ ' ' }}Please repair the restic-{{ item.name | replace(' ', '') }} job." {% endif %} fi diff --git a/vars/main.yml b/vars/main.yml index a45ce99..5d48ccb 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -10,5 +10,5 @@ restic_os_variables: paths: - 'vars' -playbook_version_number: 10 # should be int +playbook_version_number: 11 # should be int playbook_version_path: 'do1jlr.restic.version'