-
Notifications
You must be signed in to change notification settings - Fork 15
/
scrubPools.sh
124 lines (101 loc) · 3.51 KB
/
scrubPools.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/sh
#############################################################################
# Script aimed at scrubing all zpools in order to find checksum errors
#
# Author: fritz from NAS4Free forum
#
#############################################################################
# Initialization of the script name
readonly SCRIPT_NAME=`basename $0` # The name of this file
# set script path as working directory
cd "`dirname $0`"
# Import required scripts
. "config.sh"
. "common/commonLogFcts.sh"
. "common/commonMailFcts.sh"
. "common/commonLockFcts.sh"
# Record the timestamp corresponding to the start of the script execution
readonly START_TIMESTAMP=`$BIN_DATE +"%s"`
# Initialization of the constants
readonly LOGFILE="$CFG_LOG_FOLDER/$SCRIPT_NAME.log"
readonly TMPFILE_ARGS="$CFG_TMP_FOLDER/$SCRIPT_NAME.$$.args.tmp"
# Set variables corresponding to the input parameters
ARGUMENTS="$@"
##################################
# Check script input parameters
#
# Params: all parameters of the shell script
# return : 1 if an error occured, 0 otherwise
##################################
parseInputParams() {
local opt
# parse the optional parameters
# (there should be none)
while getopts ":" opt; do
case $opt in
\?)
echo "Invalid option: -$OPTARG"
return 1 ;;
esac
done
# Remove the optional arguments parsed above.
shift $((OPTIND-1))
# Check if the number of mandatory parameters
# provided is as expected
if [ "$#" -ne "0" ]; then
echo "No mandatory arguments should be provided"
return 1
fi
return 0
}
##################################
# Check if scrubing is still in progress for a given pool
# Return : 0 if scrub is in progress,
# 1 otherwise
##################################
scrubInProgress() {
if $BIN_ZPOOL status | grep "scrub in progress">/dev/null; then
return 0
else
return 1
fi
}
##################################
# Scrub all pools
# Return : 0 no problem detected
# 1 problem detected
##################################
main() {
# Starting scrubbing
log_info "$LOGFILE" "Starting scrubbing"
$BIN_ZPOOL list -H -o name | while read pool; do
$BIN_ZPOOL scrub $pool
log_info "$LOGFILE" "Starting scrubbing of pool: $pool"
done
# Waiting for the end of the scrubbing
while scrubInProgress; do sleep 10; done;
log_info "$LOGFILE" "Scrub finished for all pools"
# Check if the pools are healthy
if ZPOOL_STATUS_NON_NATIVE_ASHIFT_IGNORE=1 $BIN_ZPOOL status -x | grep "all pools are healthy">/dev/null; then
ZPOOL_STATUS_NON_NATIVE_ASHIFT_IGNORE=1 $BIN_ZPOOL status -x | log_info "$LOGFILE"
return 0
else
$BIN_ZPOOL status -v | log_error "$LOGFILE"
return 1
fi
}
# Parse and validate the input parameters
if ! parseInputParams $ARGUMENTS > "$TMPFILE_ARGS"; then
log_info "$LOGFILE" "-------------------------------------"
cat "$TMPFILE_ARGS" | log_error "$LOGFILE"
get_log_entries_ts "$LOGFILE" "$START_TIMESTAMP" | sendMail "$SCRIPT_NAME : Invalid arguments"
else
log_info "$LOGFILE" "-------------------------------------"
cat "$TMPFILE_ARGS" | log_info "$LOGFILE"
# run script if possible (lock not existing)
run_main "$LOGFILE" "$SCRIPT_NAME"
# in case of error, send mail with extract of log file
[ "$?" -eq "2" ] && get_log_entries_ts "$LOGFILE" "$START_TIMESTAMP" | sendMail "$SCRIPT_NAME : issue occured during execution"
fi
$BIN_RM "$TMPFILE_ARGS"
exit 0