How to Schedule SnapRAID on Ubuntu Server

NOTE: This guide has been written for Focal Fossa 20.04LTS but has also been tested on Xenial Xerus 16.04 LTS, Ubuntu Trusty Tahr 14.04LTS, Precise Pangolin 12.04 & Lucid Lynx 10.04 although it may work equally well on earlier versions of Ubuntu too.

Scheduling SnapRAID

To keep the SnapRAID parity up to date you have to “sync” it. You can either do this manually when you know you have changed files protected by SnapRAID (ie. you have added, deleted or updated them) or you can use a cron job to do it. I plumped for the latter option to save me having to remember to do it manually. For information, you issue the command snapraid sync in a Putty session or at the command prompt to bring the SnapRAID parity information up to date.

So, the script I use can be found here: SnapRAID Script and I downloaded it from here so all credit to the author. I did however change it so the scrub job ran weekly and not each day.

Instead of downloading the script you can create it via Putty:

  • Using Putty navigate into the folder where you’re going to store the script.
    For example type cd /media/WD40EFRX/RAIDMain/MyScripts
  • Next type vim SnapRAIDSync.sh (or your preferred script name) and press Enter. This will open the file for editing.
  • Highlight the whole script from here, right click and select Copy.
  • Then in your Putty Session press the [Insert] key once, insert a few blank lines by pressing the [Enter] key and then right click and the whole script will be pasted into the screen. Double-check you’ve pasted the whole script and not missed the first or last few lines.
  • Edit the script as required and then press the [Esc] key once and type :wq to save and quit out of the script. If you make a mistake then issue :q! instead of :wq to abort your changes.

Next, you need to make the script executable by issuing the following command:

chmod a+x SnapRAIDSync.sh

As a last step you might need to install an extra package if you’ve not got it already:

sudo apt-get install mailutils

NOTE: If you see a Postfix Configuration menu then select “No Configuration” and press Enter.

This script is really rather neat in many ways, one being that it will do nothing if you have deleted more than x files (x being 20 by default but you can change it to whatever number you like). This will ensure that if you accidentally delete a load of files you can still recover them from parity. If this fail-safe option wasn’t there then those deleted files would be lost once you’d brought the parity information up to date. Another cool feature of this script is it will send you an email of exactly what it did. You obviously have to put your own email address in the script for it to email you.

Run the script as a cron job using Webmin

To set up the above script as a cron job within Webmin launch Webmin then click on System and then Scheduled Cron Jobs. Then click Create a new scheduled cron job at the top of the screen that opens.

Click the button next to the Execute cron job as option and choose your username.

Type the full path of the script into the Command box.
So you’d type /media/WD40EFRX/RAIDMain/MyScripts/SnapRAIDSynch.sh >/dev/null 2>&1 replacing the path as required.

In the When to Execute section choose whatever time period you like. It is obviously not wise to schedule a sync when you are potentially in the midst of changing any of the data so choose a time period when you know you won’t be. For example, to run the sync at 3am each day choose the Times and dates selected below .. option and in the Minutes section choose Selected .. and highlight 0. In the Hours section choose Selected .. and highlight 3. Leave the Days, Months and Weekdays options as All.

Don’t forget to click the Create button when you’ve set up the schedule to create the cron job.

SnapRAID Pool

One of the newer features of SnapRAID is the pooling facility. This facility creates a unified view of all the individual files and folders which are spread across the various drives in your Array and displays them as though they were stored on one single huge drive. So, instead of needing to know which drive a particular file was stored on you can instead access it directly via the pool.

For example, on each of the drives in my Array I have a folder called “Blu-Rays” and inside there I have a separate folder for each blu-ray movie that I own. When I access the Blu-Rays folder via the pool I see all the individual movie folders inside it even tho in reality they are spread across 6 different disks. This makes browsing your movie collection a much more family-friendly affair.

You create or update the pool by issuing the following command after having updated the array:

snapraid pool

Of course you can append this command to the end of the above script if you like.

SnapRAID Scrubbing

One of the more unpleasant things that can happen to your data is it goes “bad”. By that I mean the area on a drive where the data has been written to previously suddenly starts throwing up read errors so can no longer be accessed. SnapRAID has an option that allows you to check for such a situation and so you can work round it. It effectively allows you to recover that chunk of data from parity or if the error is on the parity drive itself it recomputes parity for that data and writes the recovered data to a different part of the affected disk.

You can initiate a scrub as follows:

snapraid scrub

I suggest you consult the online documentation for how to scrub your data and deal with any issues which may arise.

More help required

If you need to consult the manual you can issue the following command in a Putty session:

man snapraid

Or visit the SnapRAID website.