SnapRAID Documentation

repository·master·Indexed 25 days ago

https://github.com/amadvance/snapraid

A backup program for disk arrays using parity information to protect against disk failures, optimized for large, static files on home media servers. Documentation covers filesystem snapshot management (Btrfs, Bcachefs, ZFS), device and filesystem metadata queries, SMART attribute monitoring, and the devinfo_t structure. It includes details on CLI execution modes, such as the --spin-down-on-error flag, and a comprehensive reference for structured log tags used for automation, monitoring, and error reporting.

Tokens
42K
Snippets
55
Records
242
Agent score
70%

What's inside SnapRAID

  1. Overview of SnapRAID features

    master

    SnapRAID is a backup program for disk arrays designed for home media centers with large, infrequently changing files. It provides parity-based data recovery and integrity protection with the following characteristics:

    • Data Recovery: Can recover data in the event of up to six disk failures (depending on parity configuration).
    • Non-Destructive: Uses existing disks without requiring reformatting; disks can be accessed normally outside of SnapRAID.
    • Data Integrity: All data is hashed to prevent silent corruption.
    • Fault Isolation: If failures exceed the parity count, data loss is confined to the affected disks; other disks remain accessible.
    • Flexibility: Supports disks of different sizes and allows adding new disks at any time.
    • Low Power/Noise: Accessing a file only requires a single disk to spin up.
    • No Lock-in: You can stop using SnapRAID at any time without moving or reformatting your data.
  2. Use include/exclude patterns for sync

    master

    Define file or directory patterns to include or exclude from the sync process. Patterns are processed in the order specified.

    Logic:

    • If a pattern matches and is an exclude, the file is excluded.
    • If a pattern matches and is an include, the file is included.
    • If no pattern matches, the file is excluded if the last specified pattern was an include, or included if the last specified pattern was an exclude.

    Globbing Syntax:

    • ?: Matches any single character except the directory separator.
    • *: Matches any sequence of characters within a single directory level (does not cross /).
    • **: Matches any sequence of characters, including directory separators.
    exclude /lost+found/
    exclude /tmp/
    include /important_data/**
  3. Use globbing patterns to include or exclude files

    master

    SnapRAID uses globbing patterns to select files and directories for processing.

    Key distinction:

    • *, ?, and character classes [] respect directory boundaries and match only within a single path component.
    • ** is the only pattern that can match across directory separators (recursive).

    Pattern Types:

    • FILE: Matches any file named FILE. Does not match directories.
    • DIR/: Matches any directory named DIR and everything inside it. Does not match files.
    • /PATH/FILE: Matches the exact path to a specific file.
    • /PATH/DIR/: Matches the exact path to a specific directory and everything inside it.

    Note on Absolute Paths: When a path starts with /, it is relative to the array's root directory, not the local filesystem root. On Windows, you can use backslashes \ instead of forward slashes.

  4. Use filesystem snapshots for consistent operations

    master

    By enabling the snapshot option in the configuration, SnapRAID uses filesystem snapshots to ensure atomic and consistent operations during sync, scrub, check, and fix.

    Benefits:

    • Consistency: Prevents parity mismatches caused by concurrent file modifications on the live filesystem.
    • Recovery: If a file is deleted or updated on the live filesystem during a process, it remains preserved in the snapshot, allowing SnapRAID to use it for data reconstruction.

    Requirements & Support:

    • Requires administrative privileges (e.g., sudo).
    • Supported filesystems: Btrfs, Bcachefs, and ZFS on Linux; NTFS on Windows.
    • Snapshots are only created for data disks; parity disks always use the live filesystem.

    Lifecycle:

    • stable snapshot: Represents the state of the last successful sync. Used by scrub, check, and fix.
    • pending snapshot: A temporary image created at the start of a sync. It becomes the new stable snapshot upon successful completion.
  5. Enable filesystem snapshots for consistency and recovery

    master

    If enabled via the snapshot option in the configuration, SnapRAID uses filesystem snapshots (Btrfs, Bcachefs, ZFS on Linux; NTFS on Windows) to ensure atomic and consistent operations.

    Benefits:

    • Consistency: sync and scrub run against a frozen point-in-time view, preventing errors caused by concurrent file modifications.
    • Recovery: If a file is deleted or modified on the live filesystem during a sync, the snapshot preserves the data needed for parity calculations, increasing the chance of successful recovery during a disk failure.

    Behavior:

    • sync and scrub run on snapshots.
    • check and fix use snapshots for 'reference' disks, but use the live filesystem for the 'target' disk (specified with -d).
    • Requires administrative privileges (e.g., sudo).
  6. Use glob patterns for file inclusion and exclusion

    master

    SnapRAID uses glob patterns to filter files and directories.

    Pattern Syntax

    • ?: Matches any single character (excluding directory separators).
    • *: Matches any string within a single directory level (does not cross directory boundaries).
    • **: Matches any string across multiple directory levels. Use /**/ to match any depth (e.g., src/**/main.js).
    • [ ]: Character classes (e.g., [a-z]) or negated classes (e.g., [!a-z]).

    Pattern Types

    • FILE: Matches a file name (not a directory).
    • DIR/: Matches a directory and all its contents.
    • /PATH/FILE: Matches an exact file path.
    • /PATH/DIR/: Matches an exact directory path and all its contents.
    • Note: Absolute paths starting with / are relative to the array root, not the system root.

    Configuration Strategies

    1. Exclude-only: List everything you want to remove using exclude.
    2. Include-only: List only what you want to keep using include.
    3. Mixed: Use both, but order matters. Earlier rules take precedence. Typically, list exclude rules first, then include rules.

    Local Overrides

    You can place a .snapraidignore file in any directory to define local exclusion rules. These are applied after global configuration rules, meaning they have higher priority and can exclude files even if they were included globally. .snapraidignore only supports exclusion rules.

  7. How SnapRAID commands interact with snapshots and active filesystems

    master

    SnapRAID uses snapshots to ensure data consistency and prevent parity mismatches caused by simultaneous file modifications. The behavior of commands depends on whether they target specific disks or the entire array:

    • sync and scrub: These operate exclusively on snapshots. sync uses a new pending snapshot to calculate parity, while scrub uses the stable snapshot (from the last successful sync) as a reference.
    • check and fix:
      • If a specific disk is targeted using -d or --filter-disk, SnapRAID uses the active filesystem for that disk. This allows fix to restore data to an active replacement disk and check to simulate a fix under real conditions.
      • For all other (reference) data disks, SnapRAID uses their snapshots to ensure a stable reference even if files are being modified elsewhere.
      • If no disk is specified with -d, check and fix use the active filesystems for the entire array.
    • All other commands: Operate exclusively on the active filesystem.
  8. Optimize parity space for many small files

    master

    The blocksize option defines the base parity block size in KiB (default is 256). If you have millions of small files, a large block size can lead to significant parity waste (roughly half the block size per file).

    To mitigate this, you can use a smaller blocksize, but changing this value requires recreating the entire parity. Alternatively, you can use a larger partition for parity on Linux to accommodate the waste.

    Linux Tip: Format your parity partition with mkfs.ext4 -m 0 -T largefile4 DEVICE to gain extra space (approx 1.5%) to handle file overhead.

  9. Use SnapRAID snapshots for consistency

    master

    Enabling the snapshot option in the configuration allows SnapRAID to use filesystem snapshots (Btrfs, Bcachefs, ZFS on Linux; NTFS on Windows) to ensure atomic and consistent operations.

    Benefits:

    • Consistency: sync and scrub operate on a read-only snapshot, preventing parity divergence caused by concurrent file modifications.
    • Recovery: If a file is deleted or modified in the active filesystem, it remains preserved in the snapshot, allowing SnapRAID to use it for reconstruction if a disk fails.

    Command Behavior:

    • sync and scrub: Operate exclusively on snapshots.
    • check and fix: Use the last snapshot for all 'reference' disks. However, if a disk is explicitly selected with -d or --filter-disk, that specific disk uses the active filesystem (allowing you to restore data to the active disk).
    • All other commands operate on the active filesystem.
  10. Use file patterns for include/exclude rules

    master

    SnapRAID uses globbing patterns to include or exclude files and directories. Patterns are processed in the order they appear in the configuration.

    Pattern Logic:

    • If a pattern matches and is an exclude, the file is excluded.
    • If a pattern matches and is an include, the file is included.
    • If no patterns match, the file is excluded if the last specified pattern was an include, or included if the last was an exclude.

    Globbing Syntax:

    • ?: Matches any single character (except directory separators).
    • *: Matches any sequence of characters within a single directory level (does not cross directory boundaries).
    • **: Matches any sequence of characters, including directory separators.
    • /**/: A special form of ** that matches zero or more directory levels, allowing you to match files at any depth in a tree.
    exclude /lost+found/
    exclude /tmp/
    include /home/user/**/*.jpg
  11. Enable filesystem snapshots for consistency

    master

    Enabling the snapshot option in the configuration allows SnapRAID to use filesystem snapshots (Btrfs, Bcachefs, ZFS on Linux; NTFS on Windows) to ensure atomic and consistent operations.

    Benefits:

    • Consistency: sync and scrub operate on a frozen view of the data, preventing parity discrepancies caused by files being modified during long operations.
    • Recovery: If a file is deleted or updated on the live filesystem, it remains preserved in the snapshot. This allows SnapRAID to use the snapshot data to reconstruct a failed disk even if the live file is gone.

    Behavior:

    • sync and scrub operate exclusively on snapshots.
    • check and fix use the last snapshot for all reference disks, but use the live filesystem for the specific target disk (selected via -d).
    • Creating/deleting snapshots requires administrative privileges (e.g., sudo).
    snapshot
  12. Use globbing patterns for file filtering

    master

    SnapRAID uses globbing characters to include or exclude files and directories:

    • ?: Matches any single character (excluding directory separators).
    • *: Matches any sequence of characters within a single directory level (does not cross directory boundaries).
    • **: Matches any sequence of characters, including directory separators. Use /**/ to match across any number of directory levels (e.g., src/**/main.js matches src/main.js, src/ui/main.js, etc.).
    • []: Character classes that match a single character from a specified set or range. Supports negation with !.

    Pattern Types:

    • FILE: Matches all files named FILE (not directories).
    • DIR/: Matches all directories named DIR and everything inside them.
    • /PATH/FILE: Matches the exact file path (not directories).
    • /PATH/DIR/: Matches the exact directory path and everything inside it.

    Note on Absolute Paths: Paths starting with / are applied to the array root directory, not the local filesystem root.

    Platform Specifics:

    • Windows: You can use backslashes \ instead of forward slashes /. Windows system directories, junctions, and mount points are treated as files.
    • Escaping: To use literal *, ?, [, or ] in filenames, escape them with \ on Unix or ^ on Windows. If the pattern is on the command line, you must double the escape character to prevent the shell from interpreting it.