Automatic monthly zpool scrubs

Add your Tips and tricks to configure and tweak your GhostBSD System here.
Post Reply
q-pa
Posts: 12
Joined: Mon Nov 22, 2021 5:35 am

Automatic monthly zpool scrubs

Post by q-pa »

To automatically do a monthly scrub on all zpools I am using a simple script "borrowed" from Project Trident OS in combination with fcron. The latter replaces cron on my system for its ability to run tasks after their scheduled time. Just install fcron, copy your cron tasks to /var/spool/fcron (e.g. for the root user use the command "sudo fcrontab -e -u root") and add the following lines to /etc/rc.conf:
fcron_enable="YES"
cron_enable="NO"

Also add via sudo fcrontab -e -u root:

Code: Select all

&bootrun 0 0 1 * * /path/to/zfs-scrub.sh
The zfs-scrub script has the following permissions: -rwxr--r-- 1 root wheel

This is the script zfs-scrub.sh:

Code: Select all

#!/bin/sh
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:~/bin"
#Monthly task to scrub the available zpools and check/fix errors
for pool in $(zpool list -H | cut -f 1)
do
  /usr/bin/logger "Starting ZFS scrub on pool: ${pool}"
  /sbin/zpool scrub ${pool}
  /usr/bin/logger "Scrub finished on pool: ${pool}"
done
Make sure that the export PATH line corresponds to your /path/to/zfs-scrub.sh!

Now your pools should be scrubbed at 00:00 on the 1st of every month or if your machine was shut down at that time when you start up your machine, due to fcron.
Post Reply