2010-06-15 10:58:16 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# If there is a global system configuration file, suck it in.
|
|
|
|
#
|
2011-01-25 14:41:48 +01:00
|
|
|
|
|
|
|
newline="
|
|
|
|
" # A single newline
|
|
|
|
|
2010-06-15 10:58:16 +02:00
|
|
|
if [ -r /etc/defaults/periodic.conf ]
|
|
|
|
then
|
|
|
|
. /etc/defaults/periodic.conf
|
|
|
|
source_periodic_confs
|
|
|
|
fi
|
|
|
|
|
2011-10-27 23:25:41 +02:00
|
|
|
: ${daily_scrub_zfs_default_threshold=35}
|
2010-06-15 10:58:16 +02:00
|
|
|
|
|
|
|
case "$daily_scrub_zfs_enable" in
|
|
|
|
[Yy][Ee][Ss])
|
|
|
|
echo
|
|
|
|
echo 'Scrubbing of zfs pools:'
|
|
|
|
|
|
|
|
if [ -z "${daily_scrub_zfs_pools}" ]; then
|
|
|
|
daily_scrub_zfs_pools="$(zpool list -H -o name)"
|
|
|
|
fi
|
|
|
|
|
2011-05-04 14:37:10 +02:00
|
|
|
rc=0
|
2010-06-15 10:58:16 +02:00
|
|
|
for pool in ${daily_scrub_zfs_pools}; do
|
|
|
|
# sanity check
|
2011-01-25 14:41:48 +01:00
|
|
|
_status=$(zpool list "${pool}" 2> /dev/null)
|
2010-06-15 10:58:16 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
2011-05-04 14:37:10 +02:00
|
|
|
rc=2
|
2010-06-15 10:58:16 +02:00
|
|
|
echo " WARNING: pool '${pool}' specified in"
|
|
|
|
echo " '/etc/periodic.conf:daily_scrub_zfs_pools'"
|
|
|
|
echo " does not exist"
|
|
|
|
continue
|
|
|
|
fi
|
2011-01-25 14:41:48 +01:00
|
|
|
_status=${_status##*$newline}
|
|
|
|
case ${_status} in
|
|
|
|
*FAULTED*)
|
2011-05-04 14:37:10 +02:00
|
|
|
rc=3
|
2011-01-23 18:13:29 +01:00
|
|
|
echo "Skipping faulted pool: ${pool}"
|
2011-01-25 14:41:48 +01:00
|
|
|
continue ;;
|
2015-12-16 05:32:33 +01:00
|
|
|
*UNAVAIL*)
|
|
|
|
rc=4
|
|
|
|
echo "Skipping unavailable pool: ${pool}"
|
|
|
|
continue ;;
|
2011-01-25 14:41:48 +01:00
|
|
|
esac
|
2010-06-15 10:58:16 +02:00
|
|
|
|
|
|
|
# determine how many days shall be between scrubs
|
2011-06-15 21:33:02 +02:00
|
|
|
eval _pool_threshold=\${daily_scrub_zfs_$(echo "${pool}"|tr ".:-" "_")_threshold}
|
2010-06-15 10:58:16 +02:00
|
|
|
if [ -z "${_pool_threshold}" ];then
|
|
|
|
_pool_threshold=${daily_scrub_zfs_default_threshold}
|
|
|
|
fi
|
|
|
|
|
|
|
|
_last_scrub=$(zpool history ${pool} | \
|
|
|
|
egrep "^[0-9\.\:\-]{19} zpool scrub ${pool}\$" | tail -1 |\
|
|
|
|
cut -d ' ' -f 1)
|
|
|
|
if [ -z "${_last_scrub}" ]; then
|
|
|
|
# creation time of the pool if no scrub was done
|
|
|
|
_last_scrub=$(zpool history ${pool} | \
|
|
|
|
sed -ne '2s/ .*$//p')
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Now minus last scrub (both in seconds) converted to days.
|
|
|
|
_scrub_diff=$(expr -e \( $(date +%s) - \
|
|
|
|
$(date -j -f %F.%T ${_last_scrub} +%s) \) / 60 / 60 / 24)
|
2010-08-25 10:09:42 +02:00
|
|
|
if [ ${_scrub_diff} -lt ${_pool_threshold} ]; then
|
2010-06-15 10:58:16 +02:00
|
|
|
echo " skipping scrubbing of pool '${pool}':"
|
|
|
|
echo " last scrubbing is ${_scrub_diff} days ago, threshold is set to ${_pool_threshold} days"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
_status="$(zpool status ${pool} | grep scrub:)"
|
|
|
|
case "${_status}" in
|
|
|
|
*"scrub in progress"*)
|
|
|
|
echo " scrubbing of pool '${pool}' already in progress, skipping:"
|
|
|
|
;;
|
|
|
|
*"none requested"*)
|
2010-08-25 10:09:42 +02:00
|
|
|
echo " starting first scrub (since reboot) of pool '${pool}':"
|
2010-06-15 10:58:16 +02:00
|
|
|
zpool scrub ${pool}
|
2011-05-04 14:37:10 +02:00
|
|
|
[ $rc -eq 0 ] && rc=1
|
2010-06-15 10:58:16 +02:00
|
|
|
;;
|
|
|
|
*)
|
2010-08-25 10:09:42 +02:00
|
|
|
echo " starting scrub of pool '${pool}':"
|
2010-06-15 10:58:16 +02:00
|
|
|
zpool scrub ${pool}
|
2011-05-04 14:37:10 +02:00
|
|
|
[ $rc -eq 0 ] && rc=1
|
2010-06-15 10:58:16 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo " consult 'zpool status ${pool}' for the result"
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
rc=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $rc
|