Skip to content

Commit

Permalink
feat: add zfs-scrub systemd units (#146)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Sherman <[email protected]>
  • Loading branch information
Eelviny and bsherman authored Nov 19, 2024
1 parent 27d8fcd commit 95783da
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,20 @@ If you do forget to specify the mountpoint, or you need to change the mountpoint
# zfs set mountpoint=/var/tank tank
```
#### ZFS scrub timers
It's good practice to run a `zpool scrub` periodically on ZFS pools to check and repair the integrity of data. This can be easily configured with ucore by enabling the timer. There are two timers available: weekly and monthly.
```bash
# Substitute <pool> with the name of the zpool
systemctl enable --now zfs-scrub-weekly@<pool>.timer
# Or to run it monthly:
systemctl enable --now zfs-scrub-monthly@<pool>.timer
```
This can be enabled for multiple storage pools by enabling and starting a timer for each.
#### Sanoid/Syncoid
sanoid/syncoid is a great tool for manual and automated snapshot/transfer of ZFS datasets. However, there is not a current stable RPM, rather they provide [instructions on installing via git](https://github.com/jimsalterjrs/sanoid/blob/master/INSTALL.md#centos).
Expand Down
12 changes: 12 additions & 0 deletions ucore/usr/lib/systemd/system/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Monthly zpool scrub timer for %i
Documentation=man:zpool-scrub(8)

[Timer]
OnCalendar=monthly
Persistent=true
RandomizedDelaySec=1h
Unit=zfs-scrub@%i.service

[Install]
WantedBy=timers.target
12 changes: 12 additions & 0 deletions ucore/usr/lib/systemd/system/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Weekly zpool scrub timer for %i
Documentation=man:zpool-scrub(8)

[Timer]
OnCalendar=weekly
Persistent=true
RandomizedDelaySec=1h
Unit=zfs-scrub@%i.service

[Install]
WantedBy=timers.target
15 changes: 15 additions & 0 deletions ucore/usr/lib/systemd/system/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=zpool scrub on %i
Documentation=man:zpool-scrub(8)
Requires=zfs.target
After=zfs.target
ConditionACPower=true
ConditionPathIsDirectory=/sys/module/zfs

[Service]
EnvironmentFile=-@initconfdir@/zfs
ExecStart=/bin/sh -c '\
if /usr/sbin/zpool status %i | grep -q "scrub in progress"; then\
exec /usr/sbin/zpool wait -t scrub %i;\
else exec /usr/sbin/zpool scrub -w %i; fi'
ExecStop=-/bin/sh -c '/usr/sbin/zpool scrub -p %i 2>/dev/null || true'

0 comments on commit 95783da

Please sign in to comment.