diff --git a/README.md b/README.md index 2f6c806..4e82e4f 100644 --- a/README.md +++ b/README.md @@ -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 with the name of the zpool +systemctl enable --now zfs-scrub-weekly@.timer + +# Or to run it monthly: +systemctl enable --now zfs-scrub-monthly@.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). diff --git a/ucore/usr/lib/systemd/system/zfs-scrub-monthly@.timer b/ucore/usr/lib/systemd/system/zfs-scrub-monthly@.timer new file mode 100644 index 0000000..961dc7f --- /dev/null +++ b/ucore/usr/lib/systemd/system/zfs-scrub-monthly@.timer @@ -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 \ No newline at end of file diff --git a/ucore/usr/lib/systemd/system/zfs-scrub-weekly@.timer b/ucore/usr/lib/systemd/system/zfs-scrub-weekly@.timer new file mode 100644 index 0000000..d4cd754 --- /dev/null +++ b/ucore/usr/lib/systemd/system/zfs-scrub-weekly@.timer @@ -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 \ No newline at end of file diff --git a/ucore/usr/lib/systemd/system/zfs-scrub@.service b/ucore/usr/lib/systemd/system/zfs-scrub@.service new file mode 100644 index 0000000..0eecc61 --- /dev/null +++ b/ucore/usr/lib/systemd/system/zfs-scrub@.service @@ -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'