6 # If there is a global system configuration file, suck it in.
12 if [ -r /etc/defaults/periodic.conf ]
14 . /etc/defaults/periodic.conf
18 : ${daily_scrub_zfs_default_threshold=35}
20 case "$daily_scrub_zfs_enable" in
23 echo 'Scrubbing of zfs pools:'
25 if [ -z "${daily_scrub_zfs_pools}" ]; then
26 daily_scrub_zfs_pools="$(zpool list -H -o name)"
30 for pool in ${daily_scrub_zfs_pools}; do
32 _status=$(zpool list "${pool}" 2> /dev/null)
35 echo " WARNING: pool '${pool}' specified in"
36 echo " '/etc/periodic.conf:daily_scrub_zfs_pools'"
37 echo " does not exist"
40 _status=${_status##*$newline}
44 echo "Skipping faulted pool: ${pool}"
48 echo "Skipping unavailable pool: ${pool}"
52 # determine how many days shall be between scrubs
53 eval _pool_threshold=\${daily_scrub_zfs_$(echo "${pool}"|tr ".:-" "_")_threshold}
54 if [ -z "${_pool_threshold}" ];then
55 _pool_threshold=${daily_scrub_zfs_default_threshold}
58 _last_scrub=$(zpool history ${pool} | \
59 egrep "^[0-9\.\:\-]{19} zpool scrub ${pool}\$" | tail -1 |\
61 if [ -z "${_last_scrub}" ]; then
62 # creation time of the pool if no scrub was done
63 _last_scrub=$(zpool history ${pool} | \
66 if [ -z "${_last_scrub}" ]; then
67 echo " skipping scrubbing of pool '${pool}':"
68 echo " can't get last scrubbing date"
72 # Now minus last scrub (both in seconds) converted to days.
73 _scrub_diff=$(expr -e \( $(date +%s) - \
74 $(date -j -f %F.%T ${_last_scrub} +%s) \) / 60 / 60 / 24)
75 if [ ${_scrub_diff} -lt ${_pool_threshold} ]; then
76 echo " skipping scrubbing of pool '${pool}':"
77 echo " last scrubbing is ${_scrub_diff} days ago, threshold is set to ${_pool_threshold} days"
81 _status="$(zpool status ${pool} | grep scrub:)"
83 *"scrub in progress"*)
84 echo " scrubbing of pool '${pool}' already in progress, skipping:"
87 echo " starting first scrub (since reboot) of pool '${pool}':"
92 echo " starting scrub of pool '${pool}':"
98 echo " consult 'zpool status ${pool}' for the result"