6 # If there is a global system configuration file, suck it in.
8 if [ -r /etc/defaults/periodic.conf ]
10 . /etc/defaults/periodic.conf
14 : ${daily_scrub_zfs_default_threshold=30}
16 case "$daily_scrub_zfs_enable" in
19 echo 'Scrubbing of zfs pools:'
21 if [ -z "${daily_scrub_zfs_pools}" ]; then
22 daily_scrub_zfs_pools="$(zpool list -H -o name)"
25 for pool in ${daily_scrub_zfs_pools}; do
27 zpool list ${pool} >/dev/null 2>&1
29 echo " WARNING: pool '${pool}' specified in"
30 echo " '/etc/periodic.conf:daily_scrub_zfs_pools'"
31 echo " does not exist"
35 # successful only if there is at least one pool to scrub
38 # determine how many days shall be between scrubs
39 eval _pool_threshold=\${daily_scrub_zfs_${pool}_threshold}
40 if [ -z "${_pool_threshold}" ];then
41 _pool_threshold=${daily_scrub_zfs_default_threshold}
44 _last_scrub=$(zpool history ${pool} | \
45 egrep "^[0-9\.\:\-]{19} zpool scrub ${pool}\$" | tail -1 |\
47 if [ -z "${_last_scrub}" ]; then
48 # creation time of the pool if no scrub was done
49 _last_scrub=$(zpool history ${pool} | \
53 # Now minus last scrub (both in seconds) converted to days.
54 _scrub_diff=$(expr -e \( $(date +%s) - \
55 $(date -j -f %F.%T ${_last_scrub} +%s) \) / 60 / 60 / 24)
56 if [ ${_scrub_diff} -lt ${_pool_threshold} ]; then
57 echo " skipping scrubbing of pool '${pool}':"
58 echo " last scrubbing is ${_scrub_diff} days ago, threshold is set to ${_pool_threshold} days"
62 _status="$(zpool status ${pool} | grep scrub:)"
64 *"scrub in progress"*)
65 echo " scrubbing of pool '${pool}' already in progress, skipping:"
68 echo " starting first scrub (since reboot) of pool '${pool}':"
72 echo " starting scrub of pool '${pool}':"
77 echo " consult 'zpool status ${pool}' for the result"