You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35-19Lines changed: 35 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,22 +16,41 @@ _This readme has some rough edges which will be smoothened over time._
16
16
# Highlights
17
17
18
18
## How it works
19
-
- After some preliminary checks, the script will execute `snapraid diff` to figure out if parity info is out of date, which means checking for changes since the last execution.
19
+
- After some preliminary checks, the script will execute `snapraid diff` to figure out if parity info is out of date, which means checking for changes since the last execution. During this step, the script will ensure drives are fine by reading parity and content files.
20
20
- One of the following will happen:
21
21
- If parity info is out of sync **and** the number of deleted or changed files exceed the threshold you have configured it **stops**. You may want to take a look to the output log.
22
-
- If parity info is out of sync **and** the number of deleted or changed files exceed the threshold, you can still **force a sync** after a number of warnings. It's useful If you often get a false alarm but you're confident enough.
23
-
- If parity info is out of sync **but** the number of deleted or changed files did not exceed the treshold, it **executes a sync** to update the parity info.
24
-
- When the parity info is in sync, either because nothing has changed or after a successfully sync, it runs the `snapraid scrub` command to validate the integrity of the data, both the files and the parity info. _Note that each run of the scrub command will validate only a configurable portion of parity info to avoid having a long running job and affecting the performance of the server._
22
+
- If parity info is out of sync **and** the number of deleted or changed files exceed the threshold, you can still **force a sync** after a number of warnings. It's useful If you often get a false alarm but you're confident enough. This is called "Sync with threshold warnings"
23
+
- If parity info is out of sync **but** the number of deleted or changed files did not exceed the threshold, it **executes a sync** to update the parity info.
24
+
- When the parity info is in sync, either because nothing has changed or after a successfully sync, it runs the `snapraid scrub` command to validate the integrity of the data, both the files and the parity info. If sync was cancelled or other issues were found, scrub will not be run. _Note that each run of the scrub command will validate only a configurable portion of parity info to avoid having a long running job and affecting the performance of the server._
25
+
- Extra information is be added, like SnapRAID's disk health report.
25
26
- When the script is done sends an email with the results, both in case of error or success.
26
27
27
-
Pre-hashing is enabled by default to avoid silent read errors. It mitigates the lack of ECC memory.
28
+
## Customization
29
+
Many options can be changed to your taste, their behavior is documented in the script config file.
30
+
If you don't know what to do, I recommend using the default values and see how it performs.
31
+
32
+
### Customizable features
33
+
- Sync options
34
+
- Sync always (forced sync)
35
+
- Sync after a number of breached threshold warnings
36
+
- Sync only if thresholds warnings are not breached (enabled by default)
37
+
- Thresholds for deleted and updated files
38
+
- Scrub options
39
+
- Enable or disable scrub
40
+
- Data to be scrubbed - by default 5% older than 10 days
41
+
- Pre-hashing - enabled by default to avoid silent read errors. It mitigates the lack of ECC memory.
42
+
- SMART Log - enabled by default, a SnapRAID report for disks health status
43
+
- Verbosity - disabled by default, does not include the TOUCH and DIFF output to have a better email
44
+
- Spindown - to spindown drives after the script, disabled because is currently not working
45
+
- Snapraid Status - show the status of the array, disabled because the report output is not rendered correctly
46
+
47
+
48
+
You can also change more advanced options such as mail binary (by default uses `mailx`), SnapRAID binary location, log file location.
28
49
29
50
## A nice email report
30
51
This report produces emails that don't contain a list of changed files to improve clarity.
31
52
32
-
You can re-enable full output in the email by switching the option `VERBOSITY` but the full report will always be available in `/tmp/snapRAID.out` and will be replaced after each run or deleted when the system is shut down if kept there.
33
-
34
-
SMART drive report from SnapRAID is also included by default.
53
+
You can re-enable full output in the email by switching the option `VERBOSITY` but the full report will always be available in `/tmp/snapRAID.out` but will be replaced after each run, or deleted when the system is shut down. You can change the location of the file, if needed.
35
54
36
55
Here's a sneak peek of the email report.
37
56
@@ -66,8 +85,9 @@ DIFF finished [Sat Jan 9 02:07:46 CET 2021]
66
85
67
86
**SUMMARY of changes - Added [2] - Deleted [0] - Moved [0] - Copied [0] - Updated [0]**
68
87
69
-
There are deleted files. The number of deleted files, (0), is below the threshold of (2). SYNC Authorized.
70
-
There are updated files. The number of updated files, (0), is below the threshold of (2). SYNC Authorized.
88
+
There are no deleted files, that's fine.
89
+
There are no updated files, that's fine.
90
+
SYNC is authorized.
71
91
72
92
### SnapRAID SYNC [Sat Jan 9 02:07:46 CET 2021]
73
93
@@ -157,16 +177,8 @@ All jobs ended. [Sat Jan 9 02:07:49 CET 2021]
157
177
Email address is set. Sending email report to example@example.com [Sat Jan 9 02:07:49 CET 2021]
158
178
```
159
179
160
-
## Customization
161
-
Many options can be changed to your taste, their behaviour is documented in the script config file.
162
-
163
-
If you don't know what to do, I recommend using the default values and see how it performs.
164
-
165
-
You can also change more advanced options such as mail binary (by default uses `mailx`), SnapRAID binary location, log file location.
166
-
167
-
168
180
# Requirements
169
-
- Markdown to have nice emails
181
+
- Markdown to have nice emails - will be installed if not found
170
182
-~~Hd-idle to spin down disks - [Link TBD] - currently not required since spin down does not work properly.~~
171
183
172
184
# Installation
@@ -179,6 +191,10 @@ If you want to use this script on OMV, don't worry about the section _Diff Scrip
179
191
5. Tweak the config file if needed
180
192
6. Schedule the script execution time
181
193
194
+
It is tested on OMV5, but will work on other distros. In such case you may have to change the mail binary or SnapRAID location.
195
+
196
+
If you want to use this script on OMV, don't worry about the section _Diff Script Settings_ in the main page of the SnapRAID plugin, since it only applies to the built-in plugin script. Also don't forget to remove from scheduling the built-in script.
197
+
182
198
# Known Issues
183
199
- Hard disk spin down does not work: they are immediately woken up. The script probably does not handle this correctly while running.
184
200
- The report is not perfect, we can't be solve this because SnapRAID does not natively support Markdown.
SYNC_WARN_COUNT=${SYNC_WARN_COUNT:-0}#value is zero if file does not exist or does not contain what we are expecting
353
-
354
-
if [ $SYNC_WARN_COUNT-ge$SYNC_WARN_THRESHOLD ];then
355
-
# YES, lets force a sync job. Do not need to remove warning marker here as it is automatically removed when the sync job is run by this script
356
-
echo"Number of threshold warning(s) ($SYNC_WARN_COUNT) has reached/exceeded threshold ($SYNC_WARN_THRESHOLD). Forcing a SYNC job to run. [`date`]"
367
+
if [ $SYNC_WARN_COUNT-ge$SYNC_WARN_THRESHOLD ];then
368
+
# force a sync
369
+
# if the warn count is zero it means the sync was already forced, do not output a dumb message and continue with the sync job.
370
+
if [ $SYNC_WARN_COUNT-eq 0 ];then
371
+
echo
372
+
DO_SYNC=1
373
+
else
374
+
# if there is at least one warn count, output a message and force a sync job. Do not need to remove warning marker here as it is automatically removed when the sync job is run by this script
375
+
echo"Number of threshold warning(s) ($SYNC_WARN_COUNT) has reached/exceeded threshold ($SYNC_WARN_THRESHOLD). Forcing a SYNC job to run."
357
376
mklog "INFO: Number of threshold warning(s) ($SYNC_WARN_COUNT) has reached/exceeded threshold ($SYNC_WARN_THRESHOLD). Forcing a SYNC job to run."
358
377
DO_SYNC=1
378
+
fi
359
379
else
360
380
# NO, so let's increment the warning count and skip the sync job
361
381
((SYNC_WARN_COUNT +=1))
362
382
echo$SYNC_WARN_COUNT>$SYNC_WARN_FILE
363
-
echo"$((SYNC_WARN_THRESHOLD - SYNC_WARN_COUNT)) threshold warning(s) until the next forced sync. NOT proceeding with SYNC job. [`date`]"
364
-
mklog "INFO: $((SYNC_WARN_THRESHOLD - SYNC_WARN_COUNT)) threshold warning(s) until the next forced sync. NOT proceeding with SYNC job."
365
-
DO_SYNC=0
383
+
if [ $SYNC_WARN_COUNT==$SYNC_WARN_THRESHOLD ];then
384
+
echo"This is the **last** warning left. **NOT** proceeding with SYNC job. [`date`]"
385
+
mklog "This is the **last** warning left. **NOT** proceeding with SYNC job. [`date`]"
386
+
DO_SYNC=0
387
+
else
388
+
echo"$((SYNC_WARN_THRESHOLD - SYNC_WARN_COUNT)) threshold warning(s) until the next forced sync. **NOT** proceeding with SYNC job. [`date`]"
389
+
mklog "INFO: $((SYNC_WARN_THRESHOLD - SYNC_WARN_COUNT)) threshold warning(s) until the next forced sync. **NOT** proceeding with SYNC job."
390
+
DO_SYNC=0
366
391
fi
392
+
fi
367
393
else
368
394
# NO, so let's skip SYNC
369
-
echo"Forced sync is not enabled. Check $TMP_OUTPUT for details. NOT proceeding with SYNC job. [`date`]"
370
-
mklog "INFO: Forced sync is not enabled. Check $TMP_OUTPUT for details. NOT proceeding with SYNC job."
395
+
echo"Forced sync is not enabled. Check $TMP_OUTPUT for details. **NOT** proceeding with SYNC job. [`date`]"
396
+
mklog "INFO: Forced sync is not enabled. Check $TMP_OUTPUT for details. **NOT** proceeding with SYNC job."
371
397
DO_SYNC=0
372
398
fi
373
399
}
@@ -389,23 +415,6 @@ function chk_zero(){
389
415
fi
390
416
}
391
417
392
-
functionservice_array_setup() {
393
-
if [ -z"$SERVICES" ];then
394
-
echo"Please configure services"
395
-
else
396
-
echo"Setting up service array"
397
-
read -a service_array <<<$SERVICES
398
-
fi
399
-
}
400
-
401
-
functionclean_desc(){
402
-
# Cleanup file descriptors
403
-
exec>&{out} 2>&{err}
404
-
405
-
# If interactive shell restore output
406
-
[[ $-==*i* ]] &&exec&>/dev/tty
407
-
}
408
-
409
418
functionprepare_mail() {
410
419
if [ $CHK_FAIL-eq 1 ];then
411
420
if [ $DEL_COUNT-ge$DEL_THRESHOLD-a$DO_SYNC-eq 0 ];then
@@ -432,10 +441,10 @@ function prepare_mail() {
432
441
MSG="Sync forced with multiple violations - Deleted files ($DEL_COUNT) / ($DEL_THRESHOLD) and changed files ($UPDATE_COUNT) / ($UP_THRESHOLD)"
0 commit comments