Lines 4-17
Link Here
|
4 |
|
4 |
|
5 |
# If there is a global system configuration file, suck it in. |
5 |
# If there is a global system configuration file, suck it in. |
6 |
# |
6 |
# |
7 |
|
|
|
8 |
if [ -r /etc/defaults/periodic.conf ] |
7 |
if [ -r /etc/defaults/periodic.conf ] |
9 |
then |
8 |
then |
10 |
. /etc/defaults/periodic.conf |
9 |
. /etc/defaults/periodic.conf |
11 |
source_periodic_confs |
10 |
source_periodic_confs |
12 |
fi |
11 |
fi |
13 |
|
12 |
|
14 |
case "$daily_trim_zfs_enable" in |
13 |
: ${daily_trim_zfs_default_threshold=14} |
|
|
14 |
|
15 |
case "${daily_trim_zfs_enable}" in |
15 |
[Yy][Ee][Ss]) |
16 |
[Yy][Ee][Ss]) |
16 |
echo |
17 |
echo |
17 |
echo 'Trimming of zfs pools:' |
18 |
echo 'Trimming of zfs pools:' |
Lines 34-53
case "$daily_trim_zfs_enable" in
Link Here
|
34 |
case ${_status} in |
35 |
case ${_status} in |
35 |
FAULTED) |
36 |
FAULTED) |
36 |
rc=3 |
37 |
rc=3 |
37 |
echo "Skipping faulted pool: ${pool}" |
38 |
echo " skipping faulted pool '${pool}'" |
38 |
continue ;; |
39 |
continue |
|
|
40 |
;; |
39 |
UNAVAIL) |
41 |
UNAVAIL) |
40 |
rc=4 |
42 |
rc=4 |
41 |
echo "Skipping unavailable pool: ${pool}" |
43 |
echo " skipping unavailable pool '${pool}'" |
42 |
continue ;; |
44 |
continue |
|
|
45 |
;; |
43 |
esac |
46 |
esac |
44 |
|
47 |
|
45 |
if ! zpool status "${pool}" | grep -q '(trimming)'; then |
48 |
if zpool status ${pool} | grep -q "trimming"; then |
46 |
echo " starting trim of pool '${pool}'" |
49 |
echo " trimming of pool '${pool}' already in progress, skipping" |
47 |
zpool trim ${daily_zfs_trim_flags} "${pool}" |
50 |
echo " consult 'zpool status -t ${pool}' for the result" |
48 |
else |
51 |
continue |
49 |
echo " trim of pool '${pool}' already in progress, skipping" |
52 |
fi |
|
|
53 |
|
54 |
# determine how many days shall be between trimming |
55 |
eval _pool_threshold=\${daily_trim_zfs_$(echo "${pool}" | tr ".:-" "_")_threshold:-${daily_trim_zfs_default_threshold}} |
56 |
|
57 |
_last_trim=$(zpool history ${pool} | \ |
58 |
sed -Ene 's/^([0-9.:-]{19}) zpool trim .*$/\1/p' | tail -1) |
59 |
if [ -z "${_last_trim}" ]; then |
60 |
# creation time of the pool if no trim was done |
61 |
_last_trim=$(zpool history ${pool} | \ |
62 |
sed -Ene '2s/^([0-9.:-]{19}) .*$/\1/p') |
63 |
fi |
64 |
if [ -z "${_last_trim}" ]; then |
65 |
rc=2 |
66 |
echo " skipping trimming of pool '${pool}':" |
67 |
echo " can't get last trimming date" |
68 |
continue |
69 |
fi |
70 |
|
71 |
# Now minus last trim (both in seconds) converted to days |
72 |
_trim_diff=$(expr -e \( $(date +%s) - \ |
73 |
$(date -j -v -70M -f %F.%T ${_last_trim} +%s) \) / 60 / 60 / 24) |
74 |
if [ ${_trim_diff} -lt ${_pool_threshold} ]; then |
75 |
echo " skipping trimming of pool '${pool}':" |
76 |
echo " last trimming is ${_trim_diff} days ago, threshold is set to ${_pool_threshold} days" |
77 |
continue |
50 |
fi |
78 |
fi |
|
|
79 |
|
80 |
# determine the rate at which the TRIM operation is performed |
81 |
eval _trim_rate=\${daily_trim_zfs_$(echo "${pool}" | tr ".:-" "_")_rate:-${daily_trim_zfs_default_rate}} |
82 |
if [ -n "${_trim_rate}" ]; then |
83 |
_trim_flags="-r ${_trim_rate}" |
84 |
fi |
85 |
|
86 |
_status="$(zpool status ${pool} | grep scan:)" |
87 |
case "${_status}" in |
88 |
*"scrub in progress"*) |
89 |
echo " scrubbing of pool '${pool}' is in progress, skipping" |
90 |
;; |
91 |
*"resilver in progress"*) |
92 |
echo " resilvering of pool '${pool}' is in progress, skipping" |
93 |
;; |
94 |
*) |
95 |
echo " starting TRIM of pool '${pool}'" |
96 |
echo " consult 'zpool status -t ${pool}' for the result" |
97 |
zpool trim ${_trim_flags} ${pool} |
98 |
[ $rc -eq 0 ] && rc=1 |
99 |
;; |
100 |
esac |
51 |
done |
101 |
done |
52 |
;; |
102 |
;; |
53 |
|
103 |
|