Guide - How to check BTRFS volume integrity using Monit
Posted: Saturday 19 October 2019 22:44
A Monit rule and script that does a read only BTRFS file system volume scrub (in this case the root volume / ) at a set time each day and generates a Monit alert if errors were detected.
Rule for /etc/monit/monitrc:
Script that goes in:
/etc/monit/scripts/btrfsintegritycheck.sh
This is an extremely useful tool for detecting for example corruption of an SD card.
Rule for /etc/monit/monitrc:
Code: Select all
# BTRFS File System Integrity
check program btrfsintegritycheck with path "/etc/monit/scripts/btrfsintegritycheck.sh"
with timeout 1800 seconds
# Run at 4am each day
every "0 4 * * *"
if status != 0 then alert
/etc/monit/scripts/btrfsintegritycheck.sh
Code: Select all
#!/bin/bash
btrfs scrub start -Br / | grep -e 'no errors found' -e 'with 0 errors'