r/Snapraid • u/divergentchessboard • Aug 16 '26
Need some clarification on how SnapRAID would detect file corruption
Let's say in this scenario I have two drives that are in a mirror + a third parity drive. Syncs are done every time data is added or removed from the array, and new files are scrubbed + touched when added to the array. Every day I scrub 12% of the array for files that haven't been scrubbed in 10 days.
If a random file gets corrupted 8 days after being scrubbed, but a -sync command has been done before its next scrub. Would scrubbing pick up data corruption? or does -sync tell the array that the corrupted version of the file is the intended makeup of it so scrubbing does not detect it as being corrupted and repairable?
I'm confused on if SnapRAID is viable for a NAS that has data added or removed every few days
2
u/pgenera Aug 16 '26
sync only effects files who have changed, via mtime. scrub reads every file.
2
u/BootToggle Aug 16 '26 edited Aug 20 '26
SnapRAID is very viable for a NAS that has data added every few days. Removing files every few days is a little trickier, but can be handled to work correctly. I personally use a work-around to make it fully protected for cases where files are removed. My workaround (on my Linux system) is as follows:
Note that there is a similar problem if a file is changed in place. It isn't added or deleted, exactly, but it does have the wrong bits for drive restoration. To handle this case, I build on the prior procedure as follows:
In this fashion, the system is protected at every stage in the same fashion as for the file deletion case, at the cost of a little extra complication. But it is a pain, and suggests that if you need a lot of file-changing in place, such as for a Windows C: drive or a Linux root drive, Snapraid probably shouldn't be your first choice.
Sometimes I just don't want to bother with the "bullet-proof" file change procedure from above, and I just perform an immediate Snapraid 'sync' after changing a few files. I'm not fully protected, but if I do the 'sync' immediately then the "window of vulnerability" is quickly closed.
1
u/Unknown-4024 Aug 16 '26
The corrupted file will be detect the next time scrub reach it.. Like next 2 day if it is within the 12% or after than until it reach it queue. So to detect file during read, btrfs filesystem will scream for error
1
u/BootToggle Aug 16 '26 edited Aug 17 '26
Slight correction to another comment, a file will also be known to have changed if its exact size in bytes has changed. So either a timestamp change or a file size change will trigger parity re-computation at the next 'sync'.
The change detection by mtime will also be much improved if sub-second timestamps are used. The Snapraid 'touch' command will generate a fake value for any files that don't already have a non-zero sub-second timestamp. This isn't a true time, but is good enough for change detection. Your automatic snapraid script (or daemon invocation) should use Snapraid 'touch' as part of (and just prior to) any Snapraid 'sync' operation.
As noted in other comments, files that don't have a timestamp (or size in bytes) change will not trigger re-computation of parity bits, so for those I think the in-file corruption won't be noted until a 'scrub' is performed. At 'scrub' time, the stored checksum for a file is compared against a freshly computed checksum to detect changes.
That leaves open the question of whether bytes in a corrupted file might be accessed and used if there is a file on some other data disk that has changed and this requires reading something from all disks in order to generate new parity. My guess is that the checksum value for a file will be compared with a freshly-computed checksum before the contents of a file are used for parity generation, but I'm no expert in Snapraid internals to know for sure. This doesn't make it possible to fully recover another failed drive without error, but the problem will be noted and you should know which files could not be recovered.
As always, Snapraid should not be your only protection for an important file, anything really important you should have another copy elsewhere, just in case.
1
u/BootToggle Aug 20 '26 edited Aug 21 '26
I might suggest that scrubbing 12% of your array every day is fairly heavy wear and tear on your drives. To me, running scrubs to test for file corruption (that almost certainly has not happened unless a drive is actively failing) should not be the main cause of drive failure from overuse.
In my own case, most of my files are basically in long term storage. I doubt I access a typical file more often that once per year and that is a generous estimate. I want the files there when I need them, but really just don't access them at all otherwise, this is an archive. Reading 12% of my array every day for scrubbing would vastly increase the number of drive read accesses over my natural rate of accessing the drives in my array, by at least a factor of 10.
In my own case, I have my overnight sync script also perform a 1% scrub after syncing. This means that, on average, I scrub each file about once every 100 days. This is STILL far more often than I would normally read every file, but it ends up taking about 30 minutes of heavy read access of all drives in my array each night, and I am comfortable with that level of added wear and tear. And this takes care of checking files that may have been in my array for years without once being accessed otherwise, each file being checked about 3-4 times per year on average.
Keep in mind, your filesystem will naturally report file corruption whenever you read a file, because all modern hard drives include error correction codes and checksum values at the data block level. If the drive can correct a data block during read using ECC, then there was no un-correctable error and this is actually typical. If, even with ECC applied, there remains un-correctable error, the filesystem will report a read error and your operating system will report that you attempted a bad file read. There really is no such thing (on a modern hard drive) as reading a file and not knowing that it has secretly become corrupted in storage.