cheat-sheets

SnapRAID

SnapRAID is a snapshot parity tool for arrays of mostly static files, such as media libraries. Data disks stay independent filesystems, one or more parity disks protect them, and parity is only updated when you run snapraid sync, so it is closer to a backup than to live RAID. Pair it with mergerfs to present the disks as one pool.

Documentation: SnapRAID manual · FAQ Project: SnapRAID

Verification: commands, options and configuration directives were checked against the snapraid man page in Ubuntu 24.04. No array was built or recovered. SnapRAID is not a backup of deleted or overwritten files after a sync, and it does not protect against losing more disks than you have parity disks.

How It Works #

POINTMEANING
Parity is a snapshotChanges since the last sync are not protected
Each data disk keeps its own filesystemAny one disk can be read on its own
1 parity disk survives 1 disk failure2-parity survives two, and so on
Parity disk must be as large as the largest data diskPlus room for filesystem overhead
Content file lists every file and checksumKeep several copies on different disks
Best for large, rarely changing filesPoor fit for databases and VM images

Configuration #

/etc/snapraid.conf:

text
parity /mnt/parity1/snapraid.parity

content /var/snapraid/snapraid.content
content /mnt/disk1/snapraid.content
content /mnt/disk2/snapraid.content

data d1 /mnt/disk1/
data d2 /mnt/disk2/
data d3 /mnt/disk3/

exclude *.unrecoverable
exclude /lost+found/
exclude /tmp/
DIRECTIVEPURPOSE
parity FILEParity file; 2-parity, 3-parity add more
content FILEContent (metadata) file; list at least one more than the number of parity disks
data NAME DIRA data disk mount point; keep the name stable
exclude PATTERN / include PATTERNFilter files
nohiddenIgnore hidden files
autosave GIGABYTESSave the content file during long syncs
pool DIRDirectory for the read-only pool view
smartctl DISK OPTIONSCustom smartctl command for USB or RAID controllers (use %s for the device)

Daily Commands #

COMMANDDESCRIPTION
snapraid statusArray summary: scrub age, error counts, parity fill
snapraid diffList changes since the last sync; exit code 2 means a sync is needed
snapraid syncUpdate parity for new and changed files (can be interrupted and resumed)
snapraid scrubVerify about 8% of the oldest data and parity against checksums
snapraid scrub -p 5Scrub a different percentage
snapraid scrub -p newScrub only blocks not yet scrubbed
snapraid scrub -p badRe-check blocks marked bad
snapraid smartSMART report for all disks (uses smartctl)
snapraid up / snapraid downSpin disks up or down
snapraid -d d1 downSpin down one data disk
snapraid dupList files that are duplicates by content
snapraid poolBuild a read-only pool of symlinks in the configured pool directory
snapraid touchGive files with a zero sub-second timestamp a random one (helps move detection)
snapraid -c <CONFIG_FILE> syncUse a different configuration file

Always run snapraid diff before sync: if many files have been removed, stop and find out why before the parity is overwritten.

Recovery #

COMMANDDESCRIPTION
snapraid checkVerify all files and parity against the last sync (read-only)
snapraid check -aCheck file data only, ignore parity (faster)
snapraid fixRevert all files and parity to the state of the last sync
snapraid -d d1 -l fix.log fixRebuild one failed data disk onto a replacement mounted at the same path, with a log
snapraid -e fixFix only blocks marked bad by sync or scrub
snapraid -m fixRestore files deleted since the last sync
snapraid -f <DIR_OR_PATTERN> fixRestore a directory or pattern
snapraid -i <DIR> checkUse files from another directory (for example moved-out files) during recovery

fix unconditionally reverts changes made since the last sync. Files that cannot be recovered are renamed with the .unrecoverable extension.

Replacing a failed data disk:

bash
# 1. mount the new, empty disk at the old mount point (for example /mnt/disk1)
# 2. rebuild it, logging to a file
snapraid -d d1 -l ~/snapraid-fix.log fix
# 3. check the result
snapraid -d d1 -a check
# 4. then bring parity back in step
snapraid sync

Automation #

Run diff, then sync and a partial scrub from cron or a systemd timer, and alert on failure. Do not run sync blindly: guard it with a threshold on deleted files.

bash
#!/usr/bin/env bash
set -euo pipefail
snapraid diff > /tmp/snapraid-diff.txt || [ $? -eq 2 ]
REMOVED=$(grep -c '^remove ' /tmp/snapraid-diff.txt || true)  # line format of 'diff' output: unverified, check yours
if [ "$REMOVED" -gt 100 ]; then
  echo "Too many removed files ($REMOVED): not syncing" >&2
  exit 1
fi
snapraid sync
snapraid scrub -p 5 -o 30

The -o 30 option limits scrubbing to blocks older than 30 days. Several community scripts add pre-checks and notifications; the threshold idea above is the important part.

Troubleshooting #

SYMPTOMFIX
sync refuses with an empty or missing diskA data disk is not mounted; mount it, do not use --force-empty until sure
Content file warningsKeep content copies on several disks; check each path in snapraid.conf
Parity file too large for its diskThe parity disk needs to be at least as large as the largest data disk
Many files show as copied or updated after a moveRun snapraid touch once, then sync
Disk errors during scrubsnapraid smart, then snapraid -e fix; replace the disk if errors repeat
Files changed since last syncThey are not protected: run snapraid sync

See Also #

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.