Added
Link Here
|
1 |
#!/bin/sh |
2 |
# |
3 |
# |
4 |
|
5 |
# If there is a global system configuration file, suck it in. |
6 |
# |
7 |
|
8 |
newline=" |
9 |
" # A single newline |
10 |
|
11 |
if [ -r /etc/defaults/periodic.conf ] |
12 |
then |
13 |
. /etc/defaults/periodic.conf |
14 |
source_periodic_confs |
15 |
fi |
16 |
|
17 |
case "$daily_trim_zfs_enable" in |
18 |
[Yy][Ee][Ss]) |
19 |
echo |
20 |
echo 'Trimming of zfs pools:' |
21 |
|
22 |
if [ -z "${daily_trim_zfs_pools}" ]; then |
23 |
daily_trim_zfs_pools="$(zpool list -H -o name)" |
24 |
fi |
25 |
|
26 |
rc=0 |
27 |
for pool in ${daily_trim_zfs_pools}; do |
28 |
# sanity check |
29 |
_status=$(zpool list "${pool}" 2> /dev/null) |
30 |
if [ $? -ne 0 ]; then |
31 |
rc=2 |
32 |
echo " WARNING: pool '${pool}' specified in" |
33 |
echo " '/etc/periodic.conf:daily_trim_zfs_pools'" |
34 |
echo " does not exist" |
35 |
continue |
36 |
fi |
37 |
_status=${_status##*$newline} |
38 |
case ${_status} in |
39 |
*FAULTED*) |
40 |
rc=3 |
41 |
echo "Skipping faulted pool: ${pool}" |
42 |
continue ;; |
43 |
*UNAVAIL*) |
44 |
rc=4 |
45 |
echo "Skipping unavailable pool: ${pool}" |
46 |
continue ;; |
47 |
esac |
48 |
|
49 |
zpool status ${pool} | grep -q '(trimming)' |
50 |
if [ $? -eq 1 ]; then |
51 |
echo " starting trim of pool '${pool}'" |
52 |
zpool trim ${pool} |
53 |
[ $rc -eq 0 ] && rc=1 |
54 |
else |
55 |
echo " trim of pool '${pool}' already in progress, skipping" |
56 |
fi |
57 |
done |
58 |
;; |
59 |
|
60 |
*) |
61 |
rc=0 |
62 |
;; |
63 |
esac |
64 |
|
65 |
exit $rc |