Coder Social home page Coder Social logo

auanasgheps / snapraid-aio-script Goto Github PK

View Code? Open in Web Editor NEW
226.0 17.0 37.0 680 KB

The definitive all-in-one SnapRAID script on Linux. Diff, sync, scrub are things of the past. Manage SnapRAID and much, much more!

License: GNU General Public License v3.0

Shell 100.00%
snapraid snapraid-aio-script script parity wrapper raid docker openmediavault helper omv

snapraid-aio-script's Introduction

Snapraid AIO Script

The definitive all-in-one SnapRAID script on Linux. I hope you'll agree :).

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

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

Supports single and dual parity configurations. It is highly customizable and has been tested with Debian 11/12 and OpenMediaVault 6/7.

Contributions are welcome!

Table of Contents

Highlights

How it works

  • 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.
  • One of the following will happen:
    • 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.
    • 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"
      • Instead of forcing a sync based on the number of deleted files, you may consider the ADD_DEL_THRESHOLD feature, by allowing a sync that would otherwise violate the delete threshold, if the ratio of added to deleted files is greater than the value set.
    • 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.
  • 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.
    • Scrub frequency can also be customized in case you don't want to do it every time the script runs.
    • It is still recommended to run scrub frequently.
  • Extra information can be added, like SnapRAID's disk health report or SnapRAID array status.
  • When the script is done sends an email with the results, both in case of error or success, and triggers any 3rd party notifications configured.

Additional Features

  • Docker container management
    • Manage containers before SnapRAID operations and restore them when finished. It avoids nasty errors aboud data being written during SnapRAID sync.
    • Support for local and remote Docker instances. Also manage multiple remote Docker instances at once.
      • Note: Remote Docker instances require SSH passwordless access.
    • You can either choose to pause or stop your containers.
  • Custom Hooks
    • Define shell commands or scripts to run before and after SnapRAID operations.
  • Multiple configuration files
    • Use a different configuration file when running the script instead of the default config
  • 3rd Party notification support
    • Healthchecks.io, Telegram and Discord can be used to track script execution time, status and promptly alert about errors.
    • You can also get notified with the Snapraid SMART log and Snapraid Status
    • Notification Hook: if your favourite notification service is not supported by this script, you can use a custom notification command or another mail binary
  • Important messages are also sent to the system log.
  • Emails are still the best place to get detailed but readable information.

Customization

Many options can be changed to your taste, their behavior is documented in the config file. If you don't know what to do, I recommend using the default values and see how it performs.

Customizable features

  • Sync options
    • Sync always (Forced Sync).
    • Sync after a number of breached threshold warnings.
    • Sync only if thresholds warnings are not breached (enabled by default).
    • Sync even if the delete threshold has been breached, but the ratio of added to deleted files is greater than the value set.
    • User definable thresholds for deleted and updated files.
  • Scrub options
    • Enable or disable scrub job.
    • 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.
    • Data to be scrubbed - by default 5% older than 10 days.
    • Scrub new data - scrub the data that was just added by the sync.
  • Pre-hashing - enabled by default. Mitigates the lack of ECC memory, reading data twice to avoid silent read errors.
  • Force zero size sync - disabled by default. Forces the operation of syncing a file with zero size that before was not. Use with caution!
  • Snapraid Status - disabled by default. Shows the status of the array.
    • This info can also be sent to Telegram or Discord
  • SMART Log - enabled by default. A SnapRAID report for disks health status.
    • This info can also be sent to Telegram or Discord
  • Verbosity option - disabled by default. When enabled, includes the TOUCH and DIFF commands output. Please note email will be huge and mostly unreadable.
  • SnapRAID Output (log) retention - disabled by default (log is overriden every run)
    • Detailed output retention for each run
    • You can choose the amount of days and the path, by default set to the user home
  • Healthchecks.io, Telegram and Discord integration
    • If you don't read your emails every day, this is a great one for you, since you can be quickly informed if things go wrong.
    • The script will report to Healthchecks.io, Telegram and Discord when is started and when is completed. If there's a failure it's included as well.
    • Healthchecks.io only: If the script ends with a WARNING message, it will report DOWN to Healthchecks.io, if the message is COMPLETED it will report UP.
    • Healthchecks.io only: This service will also show how much time the script takes to complete.
  • Notification Hook
    • Made for external services or mail binaries with different commands than mailx.
    • Configure the path of the script or the mail binary to be invoked.
    • You can still use native services since it only replaces the standard email.
  • Update Check - enabled by default
    • The script will check via GitHub if there's an update and alert the user via the configured notification systems
    • If you don't like this, it can be disabled
  • Docker Container management
    • A list of containers you want to be interrupted before running actions and restored when completed.
    • Docker mode - choose to pause/unpause or to stop/restart your containers
    • Docker remote - if docker is running on a remote machine
  • Multiple Configuration files
    • By default the script will use the predefined config file script-config.sh that must be placed in the same folder
    • You can specify another file when running the script like snapraid-aio-script.sh /home/alternate_config.sh
  • Custom Hooks
    • Commands or scripts to be run before and after SnapRAID operations.
    • Option to display friendly name to in the email output
  • Spindown - spindown disks after the script has completed operations. Uses a rewritten version of hd-idle.

You can also change more advanced options such SnapRAID binary location, log file location and mail binary. If your mail binary uses different commands than mailx, use the Notification Hook feature.

A nice email report

This script produces emails that don't contain a list of changed files to improve clarity.

You can re-enable full output in the email by switching the option VERBOSITY. The full report is available in /tmp/snapRAID.out but will be replaced after each run, or deleted when the system is shut down. You can enable the retention policy to keep logs for some days and customize the folder location.

Here's an example email report.

## [COMPLETED] DIFF + SYNC + SCRUB Jobs (SnapRAID on omv-test.local)
SnapRAID Script Job started [Tue 20 Apr 11:43:37 CEST 2021]
Running SnapRAID version 11.5
SnapRAID AIO Script version X.YZ

----------

## Preprocessing
Healthchecks.io integration is enabled.
Configuration file found.
Checking if all parity and content files are present.
All parity files found.
All content files found.
Docker containers management is enabled.

### Stopping Containers [Tue 20 Apr 11:43:37 CEST 2021]
Stopping Container - Code-server
code-server
Stopping Container - Portainer
portainer

----------

## Processing
### SnapRAID TOUCH [Tue 20 Apr 11:43:37 CEST 2021]
Checking for zero sub-second files.
No zero sub-second timestamp files found.
TOUCH finished [Tue 20 Apr 11:43:38 CEST 2021]

### SnapRAID DIFF [Tue 20 Apr 11:43:38 CEST 2021]
DIFF finished [Tue 20 Apr 11:43:38 CEST 2021]
**SUMMARY of changes - Added [0] - Deleted [0] - Moved [0] - Copied [0] - Updated [1]**
There are no deleted files, that's fine.
There are updated files. The number of updated files (1) is below the threshold of (500).
SYNC is authorized. [Tue 20 Apr 11:43:38 CEST 2021]

### SnapRAID SYNC [Tue 20 Apr 11:43:38 CEST 2021]
Self test...  
Loading state from /srv/dev-disk-by-label-DISK1/snapraid.content...  
Scanning disk DATA1...  
Scanning disk DATA2...  
Using 0 MiB of memory for the file-system.  
Initializing...  
Hashing...  
SYNC - Everything OK  
Resizing...  
Saving state to /srv/dev-disk-by-label-DISK1/snapraid.content...  
Saving state to /srv/dev-disk-by-label-DISK2/snapraid.content...  
Saving state to /srv/dev-disk-by-label-DISK3/snapraid.content...  
Saving state to /srv/dev-disk-by-label-DISK4/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK1/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK2/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK3/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK4/snapraid.content...  
Verified /srv/dev-disk-by-label-DISK4/snapraid.content in 0 seconds  
Verified /srv/dev-disk-by-label-DISK3/snapraid.content in 0 seconds  
Verified /srv/dev-disk-by-label-DISK2/snapraid.content in 0 seconds  
Verified /srv/dev-disk-by-label-DISK1/snapraid.content in 0 seconds  
Syncing...  
Using 32 MiB of memory for 32 cached blocks.  
    DATA1 12% | *******  
    DATA2 82% | ************************************************  
   parity  0% |   
 2-parity  0% |   
     raid  1% | *  
     hash  1% |   
    sched 11% | ******  
     misc  0% |   
              |____________________________________________________________  
                            wait time (total, less is better)  
SYNC - Everything OK  
Saving state to /srv/dev-disk-by-label-DISK1/snapraid.content...  
Saving state to /srv/dev-disk-by-label-DISK2/snapraid.content...  
Saving state to /srv/dev-disk-by-label-DISK3/snapraid.content...  
Saving state to /srv/dev-disk-by-label-DISK4/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK1/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK2/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK3/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK4/snapraid.content...  
Verified /srv/dev-disk-by-label-DISK4/snapraid.content in 0 seconds  
Verified /srv/dev-disk-by-label-DISK3/snapraid.content in 0 seconds  
Verified /srv/dev-disk-by-label-DISK2/snapraid.content in 0 seconds  
Verified /srv/dev-disk-by-label-DISK1/snapraid.content in 0 seconds

SYNC finished [Tue 20 Apr 11:43:40 CEST 2021]

### SnapRAID SCRUB [Tue 20 Apr 11:43:40 CEST 2021]
Self test...  
Loading state from /srv/dev-disk-by-label-DISK1/snapraid.content...  
Using 0 MiB of memory for the file-system.  
Initializing...  
Scrubbing...  
Using 48 MiB of memory for 32 cached blocks.  
    DATA1  2% | *  
    DATA2 18% | **********  
   parity  0% |   
 2-parity  0% |   
     raid 21% | ************  
     hash  7% | ****  
    sched 51% | ******************************  
     misc  0% |   
              |____________________________________________________________  
                            wait time (total, less is better)  
SCRUB - Everything OK  
Saving state to /srv/dev-disk-by-label-DISK1/snapraid.content...  
Saving state to /srv/dev-disk-by-label-DISK2/snapraid.content...  
Saving state to /srv/dev-disk-by-label-DISK3/snapraid.content...  
Saving state to /srv/dev-disk-by-label-DISK4/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK1/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK2/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK3/snapraid.content...  
Verifying /srv/dev-disk-by-label-DISK4/snapraid.content...  
Verified /srv/dev-disk-by-label-DISK4/snapraid.content in 0 seconds  
Verified /srv/dev-disk-by-label-DISK3/snapraid.content in 0 seconds  
Verified /srv/dev-disk-by-label-DISK2/snapraid.content in 0 seconds  
Verified /srv/dev-disk-by-label-DISK1/snapraid.content in 0 seconds

SCRUB finished [Tue 20 Apr 11:43:41 CEST 2021]

----------

## Postprocessing
SnapRAID Smart
SnapRAID SMART report:  
   Temp  Power   Error   FP Size  
      C OnDays   Count        TB  Serial                Device    Disk  
      -      -       -  SSD  0.0  00000000000000000001  /dev/sdb  DATA1  
      -      -       -  SSD  0.0  01000000000000000001  /dev/sdc  DATA2  
      -      -       -    -  0.0  02000000000000000001  /dev/sdd  parity  
      -      -       -  SSD  0.0  03000000000000000001  /dev/sde  2-parity  
      -      -       -  n/a    -  -                     /dev/sr0  -  
      0      -       -    -  0.0  -                     /dev/sda  -  
The FP column is the estimated probability (in percentage) that the disk  
is going to fail in the next year.  
Probability that at least one disk is going to fail in the next year is 0%.

## Restarting Containers [Tue 20 Apr 11:43:41 CEST 2021]

Restarting Container - Code-server
code-server
Restarting Container - Portainer
portainer
All jobs ended. [Tue 20 Apr 11:43:41 CEST 2021]
Email address is set. Sending email report to [email protected] [Tue 20 Apr 11:43:41 CEST 2021]

Requirements

If you are running a Debian based distro (with apt package manager) the script will automatically install these dependencies for you.

  • python3-markdown to format emails - will be installed if not found
  • curl to use Healhchecks - will be installed if not found
  • jq - used to send discord notifications, is a lightweight and flexible command-line JSON processor
  • bc - used for for floating-point comparisons

Dependencies that require manual installation:

  • hd-idle to spin down disks - Link, installation instructions below

Installation

  1. Install the packages listed in the Requirements section if you're not running a distro with apt package manager
  2. Download the latest version from Releases
  3. Extract the archive wherever you prefer
    • e.g. /usr/sbin/snapraid
  4. Give executable rights to the main script
    • chmod +x snapraid-aio-script.sh
  5. Open the config file and make changes to the config file as required.
    • Every config is documented but defaults are pretty resonable, so don't make changes if you're not sure.
    • When you see "" or '' in some options, do not remove these characters but just fill in your data.
    • If you want to spindown your disks, you need to install hd-idle
  6. Schedule the script execution.
    • I recommend running the script daily.

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

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.

OMV7 USERS

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. 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.

First Run

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

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

OMV and SnapRAID plugin

This script perfectly replaces the OMV built-in script. In the OMV GUI, browse to System > Scheduled Tasks and remove/disable the omv-snapraid-diff job. Also, you can igore all the settings you find at Services > SnapRAID > Diff Script Settings, since they only apply to the plugin's built-in script.

Installing hd-idle for Automatic Disk Spindown

If you would like to enable automatic disk spindown after the script job runs, then you will need to install hd-idle. The version included in default Debian and Ubuntu repositories is buggy and out of date - fortunately developer adelolmo has improved the project and released an updated version.

NOTE: This script is NOT compatible with the hd-idle version found in the Debian repositories. You must use the updated hd-idle binaries for spindown to work. If you receive and error such as hd-idle cannot spindown scsi disk /dev//dev/sda: then that is a sign that you are using the old/buggy version. Follow the instructions below to update.

  1. Remove any previously existing versions of hd-idle, either by manually removing the binaries, or running apt remove hd-idle to remove the version from the default respositories.
  2. For all recent Ubuntu and Debian releases, install the developers's repository using instructions on the developer's website. The command snippet below will select the correct repository based on your current release, and add it to your apt sources.
sudo apt-get install apt-transport-https
wget -O - http://adelolmo.github.io/[email protected] | sudo apt-key add -
echo "deb http://adelolmo.github.io/$(lsb_release -cs) $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/adelolmo.github.io.list
  1. Run apt update, and apt install hd-idle to install the updated version. You do not need to specify the respository, apt will automatically install the newset version from the new repository.
  2. In your script-config.sh file, change SPINDOWN=0 to SPINDOWN=1 to enable spindown.
  3. If you wish to use hd-idle as a service to manage your disks outside of the scope of the Snapraid AIO Script, refer to these additional instructions on the OpenMediaVault forum.

Upgrade

If you are using a previous version of the script, do not use your config file. Please move your preferences to the new script-config.sh found in the archive.

Known Issues

  • You tell me!

Star History

Star History Chart

Credits

All rights belong to the respective creators. This script would not exist without:

snapraid-aio-script's People

Contributors

auanasgheps avatar caedis avatar cmcginty avatar daflowah avatar donkeeeykong avatar phidauex avatar ranapushpender avatar tehniemer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snapraid-aio-script's Issues

Add logic to handle multiple arrays.

This is a continuation of the discussion of #80

OMV7 allows for configuring multiple SnapRAID arrays, it would be nice if this script could be configured similarly.

[question/feature request] Is there a explicit option to "force sync" option?

I've been getting the "Forced sync is not enabled. NOT proceeding with SYNC job" often due to some file operations I've been doing lately, is there a explicit FORCE_SYNC option? The wording of this warning makes it seem as if there was one but as far as I understand it this can be accomplished by way of either the SYNC_WARN_THRESHOLD or ADD_DEL_THRESHOLD but sometimes you may just want to force a sync via the script. I saw others were using a different config file with such settings changed for such instances but is there a explicit FORCE_SYNC option that can be used? If not, it'd be great to have one that could also be passed as an cli argument to the script.

Discord notification not sent upon completion

The start notification works, but I get no notifications after that. Looking at the script, it seems like it's because the "all jobs done" part of the script only checks if email and custom hooks are defined, and not Discord, Telegram, or Healthchecks, unlike earlier in the script. Changing the following line from:

  # all jobs done, let's send output to user if configured
  if [ "$EMAIL_ADDRESS" ] || [ -x "$HOOK_NOTIFICATION" ]; then

to:

  # all jobs done, let's send output to user if configured
  if [ "$EMAIL_ADDRESS" ] || [ -x "$HOOK_NOTIFICATION" ] || [ "$HEALTHCHECKS" -eq 1 ] || [ "$TELEGRAM" -eq 1 ] || [ "$DISCORD" -eq 1 ]; then

Seems to fix it. Or at least gives the following notification:

image

I dunno if this is worth a pull request since it's just a one line change, but if this is the expected output and nothing is missing, I can submit one if necessary.

job ran but did not complete successfully

Hi! Could you add some kind of explanation or advice as comment in code or in notification, what user should do after such message?
job ran but did not complete successfully
It is really unclear now how to fix it:
image
When I executed your script from console I can see:

No sync is in progress.
The 63% of the array is not scrubbed.
No file has a zero sub-second timestamp.
No rehash is in progress or needed.
DANGER! In the array there are 2 errors!

They are from block 15575536 to 15575538, specifically at blocks: 15575536 15575538

To fix them use the command 'snapraid -e fix'.
The errors will disappear from the 'status' at the next 'scrub' command.

I will try to execute snapraid -e fix but would be great to have this in notification.

Formatting change in email

I noticed in my email this morning the font and formatting changes after the sync starts, I realize this probably has something to do with markdown support, but is it possible to get the entire output in the same format? Either one.

image

Can't manage local Docker and remote Docker at the same time

In my AIO script, I've enabled both DOCKER_REMOTE=1 and DOCKER_MODE=1 (along with appropriate SERVICES=). In this setup, the script only pauses the Remote services.

If I use only DOCKER_MODE=1, the script works fine and all my local docker containers are paused.
If I then add DOCKER_REMOTE=1, this mode also works but then it only pauses the remote containers. It skips over the previously setup local docker services.

The relevant part of my config script is:

# DOCKER CONTAINERS MANAGEMENT ###

# Set to 1 to manage docker containers. They will be paused/stopped or
# resumed/restarted accordingly. If set to 0, all other options related to Docker
# will be ignored.
MANAGE_SERVICES=1

# Choose how to manage your containers: 1 to pause/unpause, 2 to stop/restart
# This option does not have any effect if MANAGE_SERVICES is set to 0
DOCKER_MODE=1

# Containers to manage (separated with spaces). Please ensure these containers
# are always running before executing the script, otherwise an error will be logged.
SERVICES='overseerr radarr sonarr sabnzbd'

# Manage docker containers running on a remote machine. To use this feature,
# you must setup passwordless ssh access between snapRAID host and Docker host.
# Set to 1 to enable, then enter Docker host SSH user and machine IP or hostname.
# You can manage multiple remote Docker hosts.
# Please note: for this configuration DO NOT separate containers with spaces.
# Use a comma instead.
# Delay is the number of seconds to wait before sending the next docker
# command to avoid errors. Change it if you're experiencing errors.
DOCKER_REMOTE=1
DOCKER_USER="user"
DOCKER_HOST_SERVICES=('frigate.lan:frigate')
DOCKER_DELAY=10

And the resulting log (see that it only paused the Remote service):

Preprocessing
Healthchecks.io notification is enabled. Notifications sent to https://hc-ping.com/.
Configuration file found.
Checking if all parity and content files are present.
All parity files found.
All content files found.
Docker containers management is enabled.

Pausing Containers [Tue Feb 27 10:26:58 EST 2024]
Pausing Container - Frigate
frigate

Processing...

Email still sending after removing it

Hi,

Thanks for a great script. I noticed that I still receive emails even though I removed or put "" in the email in the config. I can't see that the email is stored somehere else so how do I make it stop? I have set up a webhook via Discord which I prefer.

Always shows newer version is available when curl is not installed.

Thanks for the great script. I set it up yesterday (version 3.3). Everything worked well, the e-mail I got contained the following part though:

/opt/snapraid-aio-script/snapraid-aio-script.sh: Zeile 125: curl: Kommando nicht gefunden.
A newer version () is available! You can find more information by visiting https://github.com/auanasgheps/snapraid-aio-script/releases

Curl is not installed on my system. Looking into the code, the script seems to check if curl is installed only when Discord, Telegram or Healthcheck notifications are enabled. However, it is always used to check for updates as well, and, if not installed, produces the above output even when running the latest version of the script.

Emails not sending.

Hey man im glad to see youre back in action working on the script.

Anyways i havnt been able to get emails to send in a long time. I recently updated the script hoping maybe it would fix it and it doesnt.

Im running on ubuntu 22.04.4. and i do have mailutils installed. the mailx command in CLI does work as intended and when i run the script at the end it does say email address is set. sending email report to desired email address. maybe im doing something wrong? fwiw i am using gmail accounts.

Add "raw" logs

I found myself unsure of what was happening during an extended snapraid sync since there is no insight into the process while it's running, unless you have the stdout pipe. I was thinking, would it be possible to add a "raw" log entry somewhere, so you can tail it to see what the current sync/scrub progress is?

Thanks

Docker Containers - Unpause after sync but before scrub

I wanted to minimize the pause duration of my docker containers so I moved the Resume paused containers section of the script before the SCRUB is done. Is there a benefit to having them paused for the SCRUB? Happy to do a PR if that makes sense.

Maybe add some custom message when Snapraid job completed?

Because honestly when I see something like that I have no idea what should I do - google how to run full scrub or ignore...

The oldest block was scrubbed 109 days ago, the median 92, the newest 5. WARNING! The array is NOT fully synced. You have a sync in progress at 99%. The 30% of the array is not scrubbed. No file has a zero sub-second timestamp. No rehash is in progress or needed. No error detected.

Send various things to webhooks

Script is great. Would love to see the ability to push things like snapraid status or snapraid smart or some form of summary to the webhooks, particularly on a fail.

Generally I don't want many notifications, but getting a Telegram or Discord message/summary when something failed would be excellent.

"SnapRAID Script Job started" just tells you that it did in fact start, which isn't particularly valuable.

Mailx not sending

The script end succesfully and says it send the mail but I never receive a mail on Gmail.

Using Debian, mailx is default installed.

Add option to specify different snapraid-aio config file

HI all,

Thanks for this wondefull all-in-one script which I use with such a pleasure.

Currently, when I encounter a situation where the update count of updated/deleted files is higher than the threshhold, I have to manually run the command to force a sync from the command line on the server.
I would really appreciate the possibility to rexecute a dedicated cron job with a different config file (without deleted/updated files theshhold) after checking the reasons behind the warnings.

To be completely honest I use the cronicle app (that I recommend) to manage all my cron jobs on all my servers. Some jobs are set as "manual". AIO script is a perfect example.

Thank you,
Denis

Send mail error. No such entry, file or director.

OS

archlinux

test script

#!/bin/bash

body="asdasdasdasd"
echo $body
echo $(echo "$body" | sed '/^[[:space:]]*$/d; /^ -*$/d; s/$/  /')
echo $(echo "$body" | sed '/^[[:space:]]*$/d; /^ -*$/d; s/$/  /' | python -m markdown)
echo $(echo "$body" | sed '/^[[:space:]]*$/d; /^ -*$/d; s/$/  /' | python -m markdown | sed 's/<code>/<pre>/;s%</code>%</pre>%')

mailx -a 'Content-Type: text/html' -s "aaal" "[email protected]" \
    < <(echo "$body" | sed '/^[[:space:]]*$/d; /^ -*$/d; s/$/  /' |
      python -m markdown |
      sed 's/<code>/<pre>/;s%</code>%</pre>%')

echo "$body" | sed '/^[[:space:]]*$/d; /^ -*$/d; s/$/  /' |
      python -m markdown |
      sed 's/<code>/<pre>/;s%</code>%</pre>%' |
      mailx -a 'Content-Type: text/html' -s "TTTT" "[email protected]"

out:

asdasdasdasd
asdasdasdasd
<p>asdasdasdasd </p>
<p>asdasdasdasd </p>
mail: Failed to access attachment 'Content-Type: text/html': No such entry, file or directory
mail: Failed to access attachment 'Content-Type: text/html': No such entry, file or directory

Unused variable SNAPRAID_CONF

I use OpenMediaVault and am trying out OMV7, in that version the SnapRAID plugin is able to serve muliple arrays so snapraid.conf has a unique name for each array. The variable SNAPRAID_CONF in the config file is able to be set to something different, but it doesn't seem to be referenced at all in the script.

KEEP_LOG is mentioned in the config as a feature, I believe it should be RETENTION_DAYS instead.

From the config file, the 4th line down, unless it really is something different.

# Increase verbosity of the email output. NOT RECOMMENDED!
# If set to 1, TOUCH and DIFF outputs will be kept in the email, producing 
# a mostly unreadable email. You can always check TOUCH and DIFF outputs
# using the TMP file or use the feature KEEP_LOG.
# 1 to enable, any other value to disable.
VERBOSITY=0

./snapraid-aio-script.sh: line 567: /usr/bin/snapraid: No such file or directory

Debian 12
snapraid binary location: /usr/local/bin/snapraid
snapraid-aio-script location: ~/scripts/snapraid-aio-script-v.3.3/snapraid-aio-script.sh

[WARNING] - Unable to continue with SYNC/SCRUB job(s). Check DIFF job output. (SnapRAID on snapraid)

SnapRAID Script Job started [Tue Apr 2 06:00:28 AM PDT 2024]
Running SnapRAID version 12.3
SnapRAID AIO Script version 3.3
Using configuration file: ./script-config.sh
Preprocessing

SnapRAID is not running, proceeding.
Checking if all parity and content files are present.
All parity files found.
All content files found.
Processing
SnapRAID TOUCH [Tue Apr 2 06:00:28 AM PDT 2024]

Checking for zero sub-second files.
./snapraid-aio-script.sh: line 567: /usr/bin/snapraid: No such file or directory
No zero sub-second timestamp files found.
TOUCH finished [Tue Apr 2 06:00:28 AM PDT 2024]
SnapRAID DIFF [Tue Apr 2 06:00:28 AM PDT 2024]

DIFF finished [Tue Apr 2 06:00:28 AM PDT 2024]
ERROR - Failed to get one or more count values. Unable to continue.
Exiting script. [Tue Apr 2 06:00:28 AM PDT 2024]

Thank you.

Error in preprocessing in 3.2-DEV3

I'm seeing errors in the preprocessing section of my logs, but the script still runs. It seems to have something to do with RETENTION_DAYS, this is the error line 83: [: : integer expression expected

Dependencies should be listed in the ReadMe

I noticed there are more dependencies required in the dev version, it would probably be a good idea to list them in the ReadMe somewhere so people understand what will be installed on their systems on the first run of the script.

Adding exclude folder or another solution

Hello,

I'm using your script daily on cron and it's working great.

I've started using docker and I'm having issues with files that change during sync.

here an example:

Unexpected time change at file '/srv/dev-disk-byuuid-/data/private/photoprism_conf/storage/albums/state/arminbp35jb45mjs.yml' from 1670651708.738499700 to 1670652619.312280600.  
WARNING! You cannot modify files during a sync. 

Im'searching for a solution, should I exclude this folder for the sync (how can I do it?) or should I make an automation to stop dockers containers before the sync start and start the containers after the sync?

for info, the containers are in another VM using the smb share from OMV6.

thanks for the help

Make the healthchecks.io URL configurable

I am running a selfhosted instance of Healtchecks, and I would like to set up reporting in the Snapraid-AIO script.
Currently the URL is hardcoded to:
curl -fsS -m 5 --retry 3 -o /dev/null https://hc-ping.com/"$HEALTHCHECKS_ID"/start

Can the URL be modified to be a variable, with a default to 'https://hc-ping.com' to not break compatibility?

Problem with disk spin down

In line 330 there is the command to spin down the disk: hd-idle -t /dev/"$DRIVE" but it trows the error /dev//dev/sda: No such file or directory.
It seems that hd-idle just needs the drive name like sda, not the whole path.

The meaning of the '-a' option in send_mail() will vary with the MAIL_BIN

For default /usr/bin/mailx provided by mailutils, -a means "append given header", which is the expected behavior.
But if I set MAIL_BIN=/usr/bin/s-nail, -a means "attach file", so sending mail will fail. The equivalent option is -M 'text/html'.

So, is it necessary to add an option to customize arguments of MAIL_BIN in the config file?

Issue with docker pause on 3.3dev

Hi,

Pause is not working within the script, I only noticed when I had to run a manual sync (lazy and just changed the delete threshold). I confirmed that containers are still functioning.

Also noted that the error handling for pause doesn't seem to be working.

Cheers and thanks!

Relevant log info:

Discord notification is enabled.
SnapRAID is not running, proceeding.
SnapRAID output retention is enabled. Detailed logs will be kept in /root for 10 days.
Checking if all parity and content files are present.
All parity files found.
All content files found.
Docker containers management is enabled.

### Pausing Containers [Wed 06 Mar 2024 08:25:06 AM CST]
Pausing Local Container(s)
"docker pause" requires at least 1 argument.
See 'docker pause --help'.

Usage:  docker pause CONTAINER [CONTAINER...]

Pause all processes within one or more containers

----------------------------------------

Docker Config:

### DOCKER CONTAINERS MANAGEMENT ###

# Set to 1 to manage docker containers. They will be paused/stopped or
# resumed/restarted accordingly. If set to 0, all other options related to Docker
# will be ignored.
MANAGE_SERVICES=1

# Choose how to manage your containers: 1 to pause/unpause, 2 to stop/restart
# This option does not have any effect if MANAGE_SERVICES is set to 0
DOCKER_MODE=1

# Manage Docker containers running on the same host.
# Set to 1 to enable, 0 to disable it.
# Enter containers to be managed separated with spaces. Please ensure these containers
# are always running before executing the script, otherwise an error will be logged.
# Example:
# SERVICES=('syncthing kopia nextcloud immich')

DOCKER_LOCAL=1
SERVCES=('qbittorrent radarr sonarr readarr readarr-audio calibre calibre-web photoprism mariadb')

# Manage Docker containers running on a remote machine. To use this feature,
# you must setup passwordless ssh access between snapRAID host and Docker host.
# Set to 1 to enabl management of Docker containers running eslewhere, then enter
# Docker host SSH user and machine IP or hostname.
# You can manage multiple remote Docker hosts.
# Reference:
# ('HOSTIP1:container1 container2 container3' 'HOSTIP2:container1 container2 container3 container4')
# Example:
# ('192.168.0.125:code-server portainer plex' '192.168.0.126:nextcloud handbrake transmission')
# Delay is the number of seconds to wait before sending the next docker
# command to avoid errors. Change it if you're experiencing errors.
DOCKER_REMOTE=0
DOCKER_USER="sshusernamegoeshere"
DOCKER_HOST_SERVICES=('HOSTIP1:container1 container2 container3' 'HOSTIP2:container1 container2 container3 container4')
DOCKER_DELAY=0

Docker containers not unpausing

I’ve encountered a few cases where my docker containers are paused, but then not unpaused. Can’t find anything in the logs regarding it.

Add update check to the script

Now that you're actively developing the script, it would be nice if it could check for a new version on startup, and notify us if there is one. That way I don't have to come and check the github page every so often :)

UP_THRESHOLD, keeps complaining on same old folder/files

Recently found this script and it looked cleaner then my older one but i am running into an odd problem.
I have a lower UP_THRESHOLD and it keeps complaining over the same really old files/folder being new, even after many manual snapraid sync jobs over the last days.
Running script manually with scrub off it runs through without complains but reports that 40% of the array is not scrubbed even though i run a manual scrub few days ago and not much add/removed on the array.
Just reporting this in and i am out of ideas where to look, will report back if i see changes.

Getting error on execution: line 742: exec: {OUT}: not found

Hi,

currently I'm preparing SnapRAID 11.5 and your aio-script to use on my Mac mini running macOS Catalina.

On execution of your script I'm getting the error

./snapraid-aio-script.sh: line 742: exec: {OUT}: not found

Do you know if this is an apple-specific problem or if I made a mistake I didn't realize?

Greetings

Bastian

Touch not running after update to snapraid 12.3

Since I updated to snapraid 12.3 I noticed an increasing number of files with a zero sub-second timestamp in the snapraid status part of my mail notification.
It was strange since the snapraid touch part of this script should correct these files on the next run.
It did not.

The reason is a small change in the output of the command "snapraid status" in snapraid 12.3.

From (before snapraid 12.3): You have %u files with zero sub-second timestamp.
https://github.com/amadvance/snapraid/blob/986e16b4e87437eb2d7a018a2dd714be44db7f04/cmdline/status.c#L483

To (since snapraid 12.3): You have %u files with a zero sub-second timestamp.
https://github.com/amadvance/snapraid/blob/cd327c60c79b24e09f6a362c0d22fc3a2c7aebed/cmdline/status.c#L475

Because of this change:

TIMESTATUS=$($SNAPRAID_BIN -c $SNAPRAID_CONF status | grep 'You have [1-9][0-9]* files with zero sub-second timestamp\.' | sed 's/^You have/Found/g')

grep does not get the correct output because of the missing "a".
TIMESTATUS is empty.
"No zero sub-second timestamp files found."
Touch does not run, the number of files with a zero sub-second timestamp increases indefinitely.

Quick fix for anyone using snapraid 12.3, change the following line from:

TIMESTATUS=$($SNAPRAID_BIN -c $SNAPRAID_CONF status | grep 'You have [1-9][0-9]* files with zero sub-second timestamp\.' | sed 's/^You have/Found/g')

to:

TIMESTATUS=$($SNAPRAID_BIN -c $SNAPRAID_CONF status | grep 'You have [1-9][0-9]* files with a zero sub-second timestamp\.' | sed 's/^You have/Found/g')

In order to maintain compatibility with old snapraid versions, it should be possible to add a version query before the actual query to avoid errors.

Error: Failed to get one or more count values.

Hi @auanasgheps,

Thanks for this nice script. I'm running your script with success for a couple of years now, but I'm getting a error lately. This is the output in my email:

Processing
SnapRAID TOUCH [Sat 03 Jun 2023 01:00:01 AM CEST]
Checking for zero sub-second files.
No zero sub-second timestamp files found.
TOUCH finished [Sat 03 Jun 2023 01:00:11 AM CEST]

SnapRAID DIFF [Sat 03 Jun 2023 01:00:11 AM CEST]
DIFF finished [Sat 03 Jun 2023 01:10:11 AM CEST]
ERROR - failed to get one or more count values. Unable to proceed.
Exiting script. [Sat 03 Jun 2023 01:10:17 AM CEST]

I understand that it's failing to count some values, but haven't got a clue on how to solve this.

I'm running an older script, version 2.6.4, and I'm deploying the newest version soon, but I'm not able to do it right now.

Can you give me some direction?

Kind regards,

Niels

Source not found and "(" unexpected

Good evening,

I would like to start by congratulating you on this script. It is incredibly feature rich.

Unfortunately, I'm trying to run it on my instance of OMV and am running into issues.

I extracted the newest release 3.2 to sbin in on my server. I then only changed the email settings in the config file. I left the " marks.

When I run the aio script it files with the following messages:

21: source not found 
32: Syntax error: "(" unexpected 

I had a look at the script and couldn't see any reason why these errors would appear. The config file is in the same directory as the aio script and is correctly named.

Any help would be greatly appreciated.

Thank you!

Add ability to specify a config file for snapraid to use

I am looking to add a second snapraid pool and will need to call the snapraid executable using snapraid -c /path/to/config cmd would this be a feature you are interested in adding?

If I feel froggy I might make a PR for it, would you rather it using master or dev for HEAD?

Add possibility to ignore deleted files in certain locations

I'd love to see a feature where I can specify files / folders (or a regular expression) which should not count to the deleted file count. But are still synced (so I can't use the SnapRAID exclude feature).

I know that this also means, that the script will have to parse the output of the diff instead of just reading the summary.

Why would I need something like this?

I have a rolling backup running onto my SnapRAID, certain parts will get deleted after a day or two and new things will pop up. This is a mess with counting the deleted files, you never know how much it'll be and honestly I don't really care. Of course someone could just delete my whole backup and the sync would just continue when the backup is excluded from counting, but that is a risk I'll take over just setting the delete count to 1000 and miss that I deleted the wrong folder in some after work delirium.

Remote Docker host error pausing containers.

I gave the most recent script a try last night and came across some new errors in the container control section. It looks like they are pausing, but it's trying a second time without an argument. These are different than the errors I was previously experiencing.

Pausing Containers [Wed 21 Apr 2021 12:00:04 AM CDT]
Pausing Container - Amtd
"docker pause" requires at least 1 argument.
See 'docker pause --help'.
Usage: docker pause CONTAINER [CONTAINER...]
Pause all processes within one or more containers
Pausing Container - Bazarr
"docker pause" requires at least 1 argument.
See 'docker pause --help'.
Usage: docker pause CONTAINER [CONTAINER...]
Pause all processes within one or more containers
Pausing Container - Filebot
"docker pause" requires at least 1 argument.
See 'docker pause --help'.
Usage: docker pause CONTAINER [CONTAINER...]
Pause all processes within one or more containers
Pausing Container - Filerun
"docker pause" requires at least 1 argument.
See 'docker pause --help'.
Usage: docker pause CONTAINER [CONTAINER...]
Pause all processes within one or more containers

...

Resuming Containers [Wed 21 Apr 2021 01:20:17 AM CDT]
Resuming Container - Amtd
"docker unpause" requires at least 1 argument.
See 'docker unpause --help'.
Usage: docker unpause CONTAINER [CONTAINER...]
Unpause all processes within one or more containers
Resuming Container - Bazarr
"docker unpause" requires at least 1 argument.
See 'docker unpause --help'.
Usage: docker unpause CONTAINER [CONTAINER...]
Unpause all processes within one or more containers
Resuming Container - Filebot
"docker unpause" requires at least 1 argument.
See 'docker unpause --help'.
Usage: docker unpause CONTAINER [CONTAINER...]
Unpause all processes within one or more containers
Resuming Container - Filerun
"docker unpause" requires at least 1 argument.
See 'docker unpause --help'.
Usage: docker unpause CONTAINER [CONTAINER...]
Unpause all processes within one or more containers

Files with zero sub-second timestamp and Syncthing

Probably a stupid question, but what happens when the script is checking for zero sub-second files? I sync files from some machines to my OMV server, which uses Snapraid & MergerFS for the data drives.

I regular have Syncthing complain about "Locally Changed Items" on the server, and I am starting to believe this is due to the script. Last night, the script returned:

Checking for zero sub-second files.
Found 12 files with zero sub-second timestamp.
Running TOUCH job to timestamp. [Di 18. Apr 01:03:04 CEST 2023]
TOUCH finished [Di 18. Apr 01:03:07 CEST 2023]

Today, I have twelve files in Syncthing with local changes. The files I checked are binary equal to the originals, so I guess the change must be in the "metadata". I switched off syncing of permissions and the such, so the time stamp remains a possible culprit.

Any way to prevent the script from changing files without excluding them from syncs?

Handle case where snapraid is already running

I run this script every day, but sometimes the execution runs for over 24h, due to large changes to the data. The script should check that snapraid is available before going ahead with pausing and doing all the stuff it does

snapraid config diff location with OMV 6.2 plugin

Hi,

OMV 6 with Snapraid 6.2 plugin

The old location for the snapraid.conf is @ etc/snapraid.conf

New location is @ etc/snapraid/omv-snapraid-88f2fa6e-f7f8-4258-82f6-be63f6d90259.conf

thats my config, not sure what thenumbers mean. To overcome this i had to rename the above file to snapraid.conf and place it ion the etc folder.

Script then works as normal. This is even the case if i try to run the snapraid sync under cli it searches etc for the config., In the OMV plugin GUI it works as expected.

Thanks

Errors posted at end of email.

I've been seeing this and just ignoring it. But since I see no mention of it I thought you should know about it.

At the very end of the emailed message sent on script completion I see the following few lines:

All jobs ended. [Fri Nov 10 09:24:59 EST 2023]
awk: cmd. line:1: BEGIN {exit !( < 0)}
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: BEGIN {exit !( < 0)}
awk: cmd. line:1: ^ syntax error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.