Skip to content

Commit 28c37c7

Browse files
author
Oliver Cervera
authored
Merge pull request #88 from auanasgheps/dev
Merge 3.3 dev in master
2 parents fec917f + d3f18d1 commit 28c37c7

File tree

4 files changed

+513
-345
lines changed

4 files changed

+513
-345
lines changed

README.md

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Snapraid AIO Script
2-
The definitive all-in-one [SnapRAID](https://github.com/amadvance/snapraid) script. I hope you'll agree :).
2+
The definitive all-in-one [SnapRAID](https://github.com/amadvance/snapraid) script on Linux. I hope you'll agree :).
33

44
There are many SnapRAID scripts out there, but none has the features I want. So I made my own, inspired by existing solutions.
55

66
It is meant to be run periodically (daily), do the heavy lifting and send an email you will actually read.
77

8-
Supports single and dual parity configurations. It is highly customizable and has been tested with Debian 10/11 and [OpenMediaVault 5/6](https://github.com/openmediavault/openmediavault).
8+
Supports single and dual parity configurations. It is highly customizable and has been tested with Debian 11/12 and [OpenMediaVault 6/7](https://github.com/openmediavault/openmediavault).
99

1010
Contributions are welcome!
1111

@@ -20,7 +20,7 @@ Contributions are welcome!
2020
- [Requirements](#requirements)
2121
- [Installation](#installation)
2222
* [First Run](#first-run)
23-
* [OMV5/6 and SnapRAID plugin](#omv56-and-snapraid-plugin)
23+
* [OMV and SnapRAID plugin](#omv6-and-snapraid-plugin)
2424
* [Installing `hd-idle`](#installing-hd-idle-for-automatic-disk-spindown)
2525
- [Upgrade](#upgrade)
2626
- [Known Issues](#known-issues)
@@ -45,14 +45,17 @@ Contributions are welcome!
4545
### Additional Information
4646
- Docker container management
4747
- Manage containers before SnapRAID operations and restore them when finished. It avoids nasty errors aboud data being written during SnapRAID sync.
48-
- Support for local or remote Docker instances. Also manage multiple remote Docker instances at once.
48+
- Support for local and remote Docker instances. Also manage multiple remote Docker instances at once.
4949
- **Note:** Remote Docker instances require SSH passwordless access.
5050
- You can either choose to pause or stop your containers.
5151
- Custom Hooks
5252
- Define shell commands or scripts to run before and after SnapRAID operations.
53+
- Multiple configuration files
54+
- Use a different configuration file when running the script instead of the default config
5355
- 3rd Party notification support
5456
- [Healthchecks.io](https://healthchecks.io), Telegram and Discord can be used to track script execution time, status and promptly alert about errors.
55-
- Notification Hook: if your favourite notification service is not supported by this script, you can use a custom notification command or even another mail binary
57+
- You can also get notified with the `Snapraid SMART log` and `Snapraid Status`
58+
- Notification Hook: if your favourite notification service is not supported by this script, you can use a custom notification command or another mail binary
5659
- Important messages are also sent to the system log.
5760
- Emails are still the best place to get detailed but readable information.
5861

@@ -72,10 +75,12 @@ If you don't know what to do, I recommend using the default values and see how i
7275
- Delayed option, disabled by default. Run scrub only after a number of script executions, e.g. every 7 times. If you don't want to scrub your array every time, this one is for you.
7376
- Data to be scrubbed - by default 5% older than 10 days.
7477
- Scrub new data - scrub the data that was just added by the sync.
75-
- Pre-hashing - enabled by default. Mitigate the lack of ECC memory, reading data twice to avoid silent read errors.
78+
- Pre-hashing - enabled by default. Mitigates the lack of ECC memory, reading data twice to avoid silent read errors.
7679
- Force zero size sync - disabled by default. Forces the operation of syncing a file with zero size that before was not. Use with caution!
77-
- Snapraid Status - shows the status of the array, disabled by default.
80+
- Snapraid Status - disabled by default. Shows the status of the array.
81+
- This info can also be sent to Telegram or Discord
7882
- SMART Log - enabled by default. A SnapRAID report for disks health status.
83+
- This info can also be sent to Telegram or Discord
7984
- Verbosity option - disabled by default. When enabled, includes the TOUCH and DIFF commands output. Please note email will be huge and mostly unreadable.
8085
- SnapRAID Output (log) retention - disabled by default (log is overriden every run)
8186
- Detailed output retention for each run
@@ -89,11 +94,16 @@ If you don't know what to do, I recommend using the default values and see how i
8994
- Made for external services or mail binaries with different commands than `mailx`.
9095
- Configure the path of the script or the mail binary to be invoked.
9196
- You can still use native services since it only replaces the standard email.
97+
- Update Check - enabled by default
98+
- The script will check via GitHub if there's an update and alert the user via the configured notification systems
99+
- If you don't like this, it can be disabled
92100
- Docker Container management
93101
- A list of containers you want to be interrupted before running actions and restored when completed.
94102
- Docker mode - choose to pause/unpause or to stop/restart your containers
95103
- Docker remote - if docker is running on a remote machine
96-
- Docker remote action delay - Set by default to 10 seconds, reduces errors when using remote docker
104+
- Multiple Configuration files
105+
- By default the script will use the predefined config file `script-config.sh` that must be placed in the same folder
106+
- You can specify another file when running the script like `snapraid-aio-script.sh /home/alternate_config.sh`
97107
- Custom Hooks
98108
- Commands or scripts to be run before and after SnapRAID operations.
99109
- Option to display friendly name to in the email output
@@ -258,15 +268,22 @@ Email address is set. Sending email report to yourmail@example.com [Tue 20 Apr 1
258268
```
259269

260270
# Requirements
261-
- [`markdown`](https://packages.debian.org/buster/python3-markdown) to format emails - will be installed if not found
271+
272+
If you are running a Debian based distro (with `apt` package manager) the script will automatically install these dependencies for you.
273+
- [`python3-markdown`](https://packages.debian.org/bullseye/python3-markdown) to format emails - will be installed if not found
262274
- `curl` to use Healhchecks - will be installed if not found
275+
- [`jq`](https://packages.debian.org/bullseye/jq) - used to send discord notifications, is a lightweight and flexible command-line JSON processor
276+
- [`bc`](https://packages.debian.org/bullseye/bc) - used for for floating-point comparisons
277+
278+
279+
Dependencies that require manual installation:
263280
- `hd-idle` to spin down disks - [Link](https://github.com/adelolmo/hd-idle), installation instructions [below](#installing-hd-idle-for-automatic-disk-spindown)
264281

265282
# Installation
266283

267-
_Optional: install markdown `apt install python-markdown` and curl `apt install curl` . You can skip this step since the script will try to install missing packages for you._
268284

269-
1. Download the latest version from [Releases](https://github.com/auanasgheps/snapraid-aio-script/releases)
285+
1. Install the packages listed in the Requirements section if you're not running a distro with `apt` package manager
286+
2. Download the latest version from [Releases](https://github.com/auanasgheps/snapraid-aio-script/releases)
270287
3. Extract the archive wherever you prefer
271288
- e.g. `/usr/sbin/snapraid`
272289
4. Give executable rights to the main script
@@ -276,16 +293,23 @@ _Optional: install markdown `apt install python-markdown` and curl `apt install
276293
- When you see `""` or `''` in some options, do not remove these characters but just fill in your data.
277294
- If you want to spindown your disks, you need to install [hd-idle](https://github.com/adelolmo/hd-idle)
278295
6. Schedule the script execution.
279-
- I recommend running the script daily.
296+
- I recommend running the script daily.
297+
298+
**TIP**: To use multiple config files, you can create different schedules. Just append the config file path after the script, like `snapraid-aio-script.sh /home/alternate_config.sh`
299+
300+
It is tested on OMV6 and OMV7, but will work on other distros. In such case you may have to change the mail binary or SnapRAID location.
301+
302+
### OMV7 USERS
303+
OMV7's SnapRAID plugins introduced support for multiple arrays. This means each SnapRAID config file does not have a predictable name, unlike what occurred with OMV6 or standard SnapRAID installs.
304+
If running on OMV7, the AIO Script will search for a SnapRAID configuration file in the new path `/etc/snapraid/`. If multiple arrays are found, it will inform you to adjust your configuration.
280305

281-
It is tested on OMV5/6, but will work on other distros. In such case you may have to change the mail binary or SnapRAID location.
282306

283307
## First Run
284308
If you start with empty disks, you cannot use (yet) this script, since it expects SnapRAID files which would not be found.
285309

286310
First run `snapraid sync`. Once completed, the array will be ready to be used with this script.
287311

288-
## OMV5/6 and SnapRAID plugin
312+
## OMV and SnapRAID plugin
289313
Ignore what you see at _OMV GUI > Services > SnapRAID > Diff Script Settings_, since it only applies to the plugin's built-in script. Also don't forget to remove the built-in `omv-snapraid-diff` job from _OMV GUI > System > Scheduled Tasks_, either by deleting the job, or simply disabling it.
290314

291315
## Installing `hd-idle` for Automatic Disk Spindown

script-config.sh

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
CONFIG_VERSION=3.2
2+
CONFIG_VERSION="3.3" #DEV7
33
######################
44
# USER VARIABLES #
55
######################
@@ -9,15 +9,21 @@ CONFIG_VERSION=3.2
99
### NOTIFICATION SETTINGS ###
1010

1111
# Address where the output will be emailed to.
12-
# If you do not want to receive emails and rely on other notification
12+
# If you do not want to receive emails and rely on other notification
1313
# methods, leave these fields empty.
1414
EMAIL_ADDRESS="destination-email-goes-here"
1515
FROM_EMAIL_ADDRESS="sender-email-goes-here"
1616

17+
# Check for script updates.
18+
# On each run, the script will check via GitHub if there's an update, and will
19+
# inform the user via the configured notification systems.
20+
# 1 to enable, 0 to disable.
21+
CHECK_UPDATES=1
22+
1723
# Use Healthchecks.io to report script errors. Set to 1 to enable.
1824
# Please note that every "WARNING" will be reported as failure.
1925
# When enabled, enter your Healthchecks UUID (not the full URL).
20-
# If using a self-hosted instance, change the URL to your endpoint
26+
# If using a self-hosted instance, change the URL to your endpoint
2127
# including the trailing slash.
2228
HEALTHCHECKS=0
2329
HEALTHCHECKS_ID="your-uuid-here"
@@ -30,17 +36,17 @@ TELEGRAM=0
3036
TELEGRAM_TOKEN="your-token-here"
3137
TELEGRAM_CHAT_ID="your-chat-id-here"
3238

33-
# Use Discord to report script execution summary (not the whole report)
34-
# Set 1 to enable.
35-
# To get your Webhook URL go to the channel settings -> Integrations and
39+
# Use Discord to report script execution summary (not the whole report)
40+
# Set 1 to enable.
41+
# To get your Webhook URL go to the channel settings -> Integrations and
3642
# create a web hook
3743
DISCORD=0
3844
DISCORD_WEBHOOK_URL="your-webhook-url"
3945

4046
# Custom notification service
41-
# Set this to a script/service to be used instead of the default email
42-
# notification. You may want to use a service not natively supported by this
43-
# script or a mail service with custom formatting.
47+
# Set this to a script/service to be used instead of the default email
48+
# notification. You may want to use a service not natively supported by this
49+
# script or a mail service with custom formatting.
4450
# If you don't want to use this option, don't make changes to this.
4551
# $CURRENT_DIR can be used to get the running directory of the script.
4652
# This script will pass the following parameters to HOOK_NOTIFICATION:
@@ -50,18 +56,18 @@ HOOK_NOTIFICATION=""
5056

5157
### SCRIPT AND SNAPRAID SETTINGS ###
5258

53-
# Set the threshold of deleted and updated files to stop the sync job from running.
59+
# Set the threshold of deleted and updated files to stop the sync job from running.
5460
# Note that depending on how active your filesystem is being used, a low number
5561
# here may result in your parity info being out of sync often and/or you having
5662
# to do lots of manual syncing.
5763
DEL_THRESHOLD=500
5864
UP_THRESHOLD=500
5965

6066
# Allow a sync that would otherwise violate the delete threshold, but only
61-
# if the ratio of added to deleted files is greater than the value set.
67+
# if the ratio of added to deleted files is greater than the value set.
6268
# Set to 0 to disable this option.
63-
# Example: A senario with 5000 deleted files and 3800 added files would
64-
# result in an ADD_DEL_THRESHOLD of 0.76 (3800/5000)
69+
# Example: A senario with 5000 deleted files and 3800 added files would
70+
# result in an ADD_DEL_THRESHOLD of 0.76 (3800/5000)
6571
ADD_DEL_THRESHOLD=0
6672

6773
# Set number of warnings before we force a sync job. This option comes in handy
@@ -93,9 +99,9 @@ SCRUB_DELAYED_RUN=0
9399
# allow to run a fix operation. 1 to enable, any other value to disable.
94100
PREHASH=1
95101

96-
# Forces the operation of syncing a file with zero size that before was not.
102+
# Forces the operation of syncing a file with zero size that before was not.
97103
# If SnapRAID detects a such condition, it stops proceeding unless you enable
98-
# this option. Useful when syncing system files which can genuinely get
104+
# this option. Useful when syncing system files which can genuinely get
99105
# changed to zero.
100106
# Disabled by default, 1 to enable.
101107
FORCE_ZERO=0
@@ -105,29 +111,40 @@ FORCE_ZERO=0
105111
# hd-idle is required and must be already configured.
106112
SPINDOWN=0
107113

108-
# Set the option to log SMART info collected by SnapRAID. 1 to enable and any
109-
# other value to disable.
110-
SMART_LOG=1
111-
112114
# Increase verbosity of the email output. NOT RECOMMENDED!
113-
# If set to 1, TOUCH and DIFF outputs will be kept in the email, producing
115+
# If set to 1, TOUCH and DIFF outputs will be kept in the email, producing
114116
# a mostly unreadable email. You can always check TOUCH and DIFF outputs
115-
# using the TMP file or use the feature KEEP_LOG.
117+
# using the TMP file or use the feature RETENTION_DAYS.
116118
# 1 to enable, any other value to disable.
117119
VERBOSITY=0
118120

119121
# SnapRAID detailed output retention for each run.
120-
# Default behaviour is RETENTION_DAYS=0: every time your run SnapRAID, the
122+
# Default behaviour is RETENTION_DAYS=0: every time your run SnapRAID, the
121123
# output is saved to "/tmp" and is overridden during every run.
122-
# To enable retention, set RETENTION_DAYS to the days of output you want to
123-
# keep in your home folder. Files will have timestamps.
124+
# To enable retention, set RETENTION_DAYS to the days of output you want to
125+
# keep in your home folder. Files will have timestamps.
124126
# SNAPRAID_LOG_DIR can be changed to any folder you like.
125127
RETENTION_DAYS=0
126128
SNAPRAID_LOG_DIR="$HOME"
127129

130+
# Set the option to log SMART info collected by SnapRAID.
131+
# Use SMART_LOG_NOTIFY to send the output to Telegram/Discord
132+
# 1 to enable, any other value to disable.
133+
SMART_LOG=1
134+
SMART_LOG_NOTIFY=0
135+
128136
# Run 'snapraid status' command to show array general information.
137+
# Use SNAP_STATUS_NOTIFY to send the output to Telegram/Discord
129138
# 1 to enable, any other value to disable.
130139
SNAP_STATUS=0
140+
SNAP_STATUS_NOTIFY=0
141+
142+
# SnapRAID configuration file location. The default path works on most
143+
# installations, including OMV6.
144+
# If you're using OMV7, the script will try to pick the file automatically.
145+
# If you have multiple SnapRAID arrays, you must must manually specify the
146+
# config file you want to use. On OMV7 the files are located at /etc/snapraid/
147+
SNAPRAID_CONF="/etc/snapraid.conf"
131148

132149
### DOCKER CONTAINERS MANAGEMENT ###
133150

@@ -140,26 +157,31 @@ MANAGE_SERVICES=0
140157
# This option does not have any effect if MANAGE_SERVICES is set to 0
141158
DOCKER_MODE=1
142159

143-
# Containers to manage (separated with spaces). Please ensure these containers
160+
# Manage Docker containers running on the same host.
161+
# Set to 1 to enable, 0 to disable it.
162+
# Enter containers to be managed separated with spaces. Please ensure these containers
144163
# are always running before executing the script, otherwise an error will be logged.
145-
SERVICES='container1 container2 container3'
164+
# Example:
165+
# SERVICES="syncthing kopia nextcloud $(docker container ls -q --filter name=immich*)"
146166

147-
# Manage docker containers running on a remote machine. To use this feature,
167+
DOCKER_LOCAL=0
168+
SERVICES="container1 container2 container3"
169+
170+
# Manage Docker containers running on a remote machine. To use this feature,
148171
# you must setup passwordless ssh access between snapRAID host and Docker host.
149-
# Set to 1 to enable, then enter Docker host SSH user and machine IP or hostname.
172+
# Set to 1 to enable management of Docker containers running eslewhere, then enter
173+
# Docker host SSH user and machine IP or hostname.
150174
# You can manage multiple remote Docker hosts.
151-
# Please note: for this configuration DO NOT separate containers with spaces.
152-
# Use a comma instead.
153175
# Reference:
154-
# ('HOSTIP1:container1,container2,container3' 'HOSTIP2:container1,container2,container3,container4')
176+
# ('HOSTIP1:container1 container2 container3' 'HOSTIP2:container1 container2 container3 container4')
155177
# Example:
156-
# ('192.168.0.125:code-server,portainer,plex' '192.168.0.126:nextcloud,handbrake,transmission')
178+
# ('192.168.0.125:code-server portainer plex' '192.168.0.126:nextcloud handbrake transmission')
157179
# Delay is the number of seconds to wait before sending the next docker
158180
# command to avoid errors. Change it if you're experiencing errors.
159181
DOCKER_REMOTE=0
160182
DOCKER_USER="sshusernamegoeshere"
161-
DOCKER_HOST_SERVICES=('HOSTIP1:container1,container2,container3' 'HOSTIP2:container1,container2,container3,container4')
162-
DOCKER_DELAY=10
183+
DOCKER_HOST_SERVICES=('HOSTIP1:container1 container2 container3' 'HOSTIP2:container1 container2 container3 container4')
184+
DOCKER_DELAY=0
163185

164186
### CUSTOM HOOKS ###
165187

@@ -206,7 +228,6 @@ SCRUB_COUNT_FILE="$CURRENT_DIR/snapRAID.scrubCount"
206228
TMP_OUTPUT="/tmp/snapRAID.out"
207229
SNAPRAID_LOG="/var/log/snapraid.log"
208230
SECONDS=0 #Capture time
209-
SNAPRAID_CONF="/etc/snapraid.conf"
210231

211232
# Expand PATH for smartctl
212233
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

0 commit comments

Comments
 (0)