ZFS: scrub: cron --> systemd-timer (#341)

Co-authored-by: Michael Grote <michael.grote@posteo.de>
Reviewed-on: mg/ansible#341
Co-authored-by: mg <michael.grote@posteo.de>
Co-committed-by: mg <michael.grote@posteo.de>
This commit is contained in:
Michael Grote 2022-03-19 13:28:41 +01:00
parent 78b315e031
commit 49f3c00885
9 changed files with 122 additions and 41 deletions

View file

@ -21,7 +21,7 @@
# https://forum.restic.net/t/exclude-syntax-confusion/1531/12
restic_mount_timeout: "10 min"
restic_failure_delay: "30 s"
restic_schedule: "0/6:00"
restic_schedule: "0/6:00" # alle 6 Stunden
restic_folders_to_backup: "/" # --one-file-system ist gesetzt, also werden weitere Dateisysteme nicht eigeschlossen, es sei denn sie werden hier explizit angegeben; https://restic.readthedocs.io/en/latest/040_backup.html#excluding-files
restic_repository: "//fileserver2.grote.lan/restic"
restic_repository_password: "{{ lookup('keepass', 'restic_repository_password', 'password') }}"

View file

@ -42,14 +42,6 @@
zfs_extra_arc_max_size: "2147483648" # 2GB in Bytes
zfs_extra_zfs_pools:
- name: "rpool"
cron_minutes_zfs_scrub: "5"
cron_hour_zfs_scrub: "23"
cron_day_of_month_zfs_scrub: "14"
cron_day_of_week_zfs_scrub: "*"
cron_month_zfs_scrub: "*/2"
systemd_timer_schedule: "*-01,04,07,10-01 23:00"
- name: "hdd_vm_mirror"
cron_minutes_zfs_scrub: "10"
cron_hour_zfs_scrub: "23"
cron_day_of_month_zfs_scrub: "14"
cron_day_of_week_zfs_scrub: "*"
cron_month_zfs_scrub: "*/2"
systemd_timer_schedule: "*-01,04,07,10-01 23:00"

View file

@ -177,17 +177,9 @@
zfs_extra_arc_max_size: "8589934592" # 8GB in Bytes
zfs_extra_zfs_pools:
- name: "rpool"
cron_minutes_zfs_scrub: "0"
cron_hour_zfs_scrub: "23"
cron_day_of_month_zfs_scrub: "14"
cron_day_of_week_zfs_scrub: "*"
cron_month_zfs_scrub: "*/2"
systemd_timer_schedule: "*-01,04,07,10-01 23:00" # jeden ersten eines jeden Quartals
- name: "hdd_data_raidz"
cron_minutes_zfs_scrub: "0"
cron_hour_zfs_scrub: "23"
cron_day_of_month_zfs_scrub: "14"
cron_day_of_week_zfs_scrub: "*"
cron_month_zfs_scrub: "*/2"
systemd_timer_schedule: "*-01,04,07,10-01 23:00"
### mgrote.zfs_sanoid
sanoid_datasets:

View file

@ -13,11 +13,11 @@
**/**cache***/**
**/**Cache***/**
**/**AppData***/**
# timeout for cifs mount; systemd notation
# timeout for cifs mount; systemd notation(systemd-analyze calendar "Sun *-0/2-* 23:00")
restic_mount_timeout: "10 min"
# delay for restartung task; systemd notation
# delay for restartung task; systemd notation(systemd-analyze calendar "Sun *-0/2-* 23:00")
restic_failure_delay: "30 s"
# when should restic run; systemd notation
# when should restic run; systemd notation(systemd-analyze calendar "Sun *-0/2-* 23:00")
restic_schedule: "*:0/2"
# welche ordner sollen gesichert werden
restic_folders_to_backup: "/usr/local /etc /root /var/www /home"

View file

@ -1,13 +1,12 @@
## mgrote.zfs_scrub
### Beschreibung
Richtet regelmaessige Scrubs(jeden Sonntag) ein.
Richtet regelmaessige Scrubs mit systemd-timer ein.
### getestet auf
- [x] ProxMox 6.1
- [x] ProxMox 7*
### Variablen + Defaults
- see [defaults](./defaults/main.yml)
- Variablen für ``mgrote.zfs_health/trim/scrub/zed/arc_mem/`` sind zusammengefasst unter zfs_extra_*
- see [default-filter](./tasks/main.yml)

View file

@ -1,20 +1,84 @@
---
- name: remove system scrub job #https://forum.proxmox.com/threads/script-sequential-zfs-scrub-for-cron.25124/
- name: template unit-template
become: true
ansible.builtin.template:
src: zpool-scrub@.service.j2
dest: /etc/systemd/system/zpool-scrub@.service
owner: root
group: root
mode: 0644
register: template_unit
- name: template timer
become: true
ansible.builtin.template:
src: zpool-scrub@.timer.j2
dest: "/etc/systemd/system/zpool-scrub@{{ item.name }}.timer"
owner: root
group: root
mode: 0644
loop: "{{ zfs_extra_zfs_pools }}"
register: template_timer
- name: template mail.service
become: true
ansible.builtin.template:
src: zpool-scrub-mail.service.j2
dest: "/etc/systemd/system/zpool-scrub-mail.service"
owner: root
group: root
mode: 0644
register: template_mail
- name: systemctl daemon-reload
become: yes
ansible.builtin.systemd:
daemon_reload: yes
when:
- template_unit.changed
- template_timer.changed
- name: systemctl enable units - timer
become: yes
ansible.builtin.systemd:
name: "zpool-scrub@{{ item.name }}.timer"
enabled: yes
masked: no
loop: "{{ zfs_extra_zfs_pools }}"
when:
- template_unit.changed
- template_timer.changed
- name: systemctl enable units - mail
become: yes
ansible.builtin.systemd:
name: "zpool-scrub-mail.service"
enabled: yes
masked: no
when:
- template_mail
- name: systemctl start units
become: yes
ansible.builtin.systemd:
name: "zpool-scrub@{{ item.name }}.timer"
state: restarted
enabled: yes
loop: "{{ zfs_extra_zfs_pools }}"
when:
- template_unit.changed
- template_timer.changed
- name: remove old cronjobs
become: yes
ansible.builtin.cron:
name: zfs-scrub - "{{ item.name }}"
state: absent
with_items: "{{ zfs_extra_zfs_pools }}"
- name: remove proxmox system scrub job #https://forum.proxmox.com/threads/script-sequential-zfs-scrub-for-cron.25124/
become: true
ansible.builtin.lineinfile:
path: /etc/cron.d/zfsutils-linux
state: absent
line: '24 0 8-14 * * root [ $(date +\%w) -eq 0 ] && [ -x /usr/lib/zfs-linux/scrub ] && /usr/lib/zfs-linux/scrub'
- name: add cronjob "zfs-scrub"
become: yes
ansible.builtin.cron:
name: zfs-scrub - "{{ item.name }}"
state: present
job: "{{ zfs_extra_path_zpool }} scrub {{ item.name }}"
month: "{{ item.cron_month_zfs_scrub | default('*') }}"
weekday: "{{ item.cron_day_of_week_zfs_scrub | default('7') }}"
day: "{{ item.cron_day_of_month_zfs_scrub | default('*/21') }}"
hour: "{{ item.cron_hour_zfs_scrub | default('23') }}"
minute: "{{ item.cron_minutes_zfs_scrub | default('30') }}"
with_items: "{{ zfs_extra_zfs_pools }}"

View file

@ -0,0 +1,8 @@
{{ file_header | default () }}
[Unit]
Description=Send a Mail in case of an error in zpool-scrub@.service.
[Service]
Type=oneshot
ExecStart=/bin/bash -c '{{ zfs_extra_path_zpool }} status | mail -s "[ERROR] zpool scrub - %H" {{ empfaenger_mail }}'

View file

@ -0,0 +1,13 @@
{{ file_header | default () }}
[Unit]
Description=Scrub ZFS pool "%i"
Requires=zfs.target
After=zfs.target
OnFailure=zpool-scrub-mail.service
[Service]
Type=simple
ExecStartPre=-{{ zfs_extra_path_zpool }} scrub -s %i
ExecStart={{ zfs_extra_path_zpool }} scrub -w %i
ExecStop={{ zfs_extra_path_zpool }} scrub -s %i

View file

@ -0,0 +1,13 @@
{{ file_header | default () }}
[Unit]
Description=Scrub ZFS pool "%i"
[Timer]
OnCalendar={{ item.systemd_timer_schedule }}
Persistent=true
Unit=zpool-scrub@%i.service
RandomizedDelaySec=30 min
[Install]
WantedBy=timers.target