SnapRAID
SnapRAID protects against disk failure, but but not in the normal way. Rather than calculating parity with every write, it calculates parity on a schedule. Think of it as off-line RAID that’s like a backup. If you delete a file, you can recover it. If you loose a disk, you can rebuild it. Just not in real-time. All you need is a spare disk to save the parity to.
The natural question is: If you have an extra disk, why wouldn’t you just run RAID to begin with? The answers are usually:
- You need something like backup but don’t have enough space for a full copy.
- You already have a collection of individual drives without raid, and want to protect them.
- You’d like to setup RAID, but don’t have the space to copy it out and back in.
- Your case is full so you plug in a USB drive occasionally for a snap.
- You want to send the snap to another site, like the cloud.
- You have a mix of drive sizes and can’t do normal RAID.
- You want to protect your existing data from bit-rot.
The developer mentions it’s targeted at large media collections, so the first few points are most common.
I say disk a lot, but I should really say filesystem, as it works at that level. If you already have a large mdadm raid0 filesystem, your parity storage will have to be as large as the whole mdadm filesystem. So mostly too late in that case.
One common use is paired with MergerFS. It has individual file systems so you can snap it easily. And MergerFS lets the (remaining) content to continue being served while the missing filesystem is recovered.
Installation
You can install from apt but on most systems it’s a major version behind. The developer recommends downloading the current version and building.
https://www.snapraid.it/download
# If you're OK with v12
apt install snapraid
# If you prefer v13 and don't mind all the space from the build tools
sudo apt-get update && sudo apt-get install gcc git make -y
git clone https://github.com/amadvance/snapraid.git
cd snapraid
./autogen.sh
./configure
make
make check
sudo make install
Configuration
SnapRAID needs a configuration file and a content file. The first is where you tell it what to do, and the second is for it to keep track of what it’s done.
It also needs a place to store parity information. This can grow as large as the largest disk. So if your largest disk is 10TB you’ll need a 10TB parity disk.
For an example, let’s assume we have 4 disks that range from 4 to 8 TB. To that we’ll add an 8TB disk to store parity. The developer’s suggests1 this command to maximize space (though if you go past 16TB use xfs).
mkfs.ext4 -m 0 -T largefile4 DEVICE
That give us:
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdb 8:16 0 4T 0 disk
└─sdb5 8:21 0 3.9T 0 part /mnt/pics
sdc 8:32 0 4T 0 disk /mnt/movies
sdd 8:48 0 6T 0 disk /mnt/movies2
sde 8:64 0 8T 0 disk /mnt/tv.shows
sdf 8:64 0 8T 0 disk /mnt/snapraid # <-- Just added this
So you’d create the config file with the following options:
sudo vi /etc/snapraid.conf
/var/snapraid/snapraid.content
data d1 /mnt/pics/
data d2 /mnt/movies/
data d3 /mnt/movies2/
data d4 /mnt/tv.shows/
parity /mnt/snapraid/snapraid.parity
# This is the 'working' file for snapraid
content /var/snapraid/snapraid.content
# A couple more copies is suggested as backup
content /mnt/pics/.snapraid.content
content /mnt/movies/.snapraid.content
Operations
Backup
The command to sync up the parity disk is just sync. This will take a long time for it’s initial run.
snapraid sync
Undelete
You can restore a deleted file or directory with:
snapraid fix -f SOMETHING
Rebuilding
If you loose a disk, just add a new one, format and mount it at the same place, and type:
# Assuming 'd2' was the replaced disk
snapraid -d d2 fix
Scrub
If your disks are suspect, you can run periodic scrubs to check for bit-rot.
snapraid scrub
snapraid status
There are may other options and the manual is worth checking out.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.