Skip to content

create: back up automounted directories, fixes #6652 - #10509

Merged
ThomasWaldmann merged 3 commits into
borgbackup:masterfrom
ThomasWaldmann:automount-6652
Oct 11, 2026
Merged

ThomasWaldmann merged 3 commits into
borgbackup:masterfrom
ThomasWaldmann:automount-6652

Conversation

@ThomasWaldmann

@ThomasWaldmann ThomasWaldmann commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Fixes #6652.

Problem

stat() / lstat() do not trigger an automount (on Linux, they act as if AT_NO_AUTOMOUNT was given), but opening the directory does. borg create stats a directory, then opens it and compares with fstat(): for an automount point that is not mounted yet, the first stat is the automount point and the fstat() is the root directory of the filesystem that just got mounted there. borg considered that a race condition ("file type or inode changed") and skipped the whole tree.

This affects autofs (indirect and direct maps), systemd .automount units and ZFS .zfs/snapshot/* on Linux.

Fix

  • platform.on_different_mounts(fd1, fd2): Linux compares the mount ids (from /proc/self/fdinfo/<fd>, Linux >= 3.15), as st_dev is not good enough there (btrfs subvolumes have their own st_dev without being a mount). Other platforms compare st_dev. If it can not be determined, the answer is None, which is handled like "no".
  • archive.is_automount(): accepts the change only if it is a directory before and after and the opened directory is on a different mount than its parent directory. Everything else still raises BackupRaceConditionError.
  • In the recursive walk, we then use the fstat() result and redo the skip_inodes and --one-file-system decisions, so an automounted filesystem is handled like an already mounted one.
  • Recursion roots that are directories are opened before taking their stat, so the mount happens early and --one-file-system uses the device number of the mounted filesystem.
  • Directories given via --paths-from-stdin are not pre-opened (that would cost an extra open/fstat/close per directory): for an automount point that is not mounted yet, the existing race condition retry already picks up the mounted filesystem.

Testing

Unit tests (is_automount, on_different_mounts) and a borg create test that simulates an automount point (with and without a mount, with and without --one-file-system).

Manual tests on Debian 13 (kernel 6.12), comparing 2.0.0b25 with this branch:

setup b25 this PR
autofs indirect map (bind): as recursion root / while recursing / with -x rc 103, tree skipped complete; with -x only the mountpoint dir
systemd .automount unit (direct autofs mount) rc 103, tree skipped complete
ZFS 2.3.9, -x on .zfs/snapshot/<snap> as recursion root rc 0 but incomplete (subdir contents missing) complete
btrfs subvolume vs. mount – mount id check says "same mount" (st_dev comparison would say "different")

ZFS 2.3.9 keeps the inode number of the snapshot root (only st_dev changes), so the original error does not appear there anymore, but the -x decision was based on the automount point's st_dev.

FreeBSD 15 and NetBSD 11 autofs do not mount when the directory is opened (only on the first lookup inside it), so stat() and fstat() agree there and this change makes no difference. FreeBSD ZFS mounts snapshots on lookup, so it is not affected either.

🤖 Generated with Claude Code

stat() does not trigger an automount (autofs, systemd automount units,
ZFS .zfs/snapshot/*), but opening the directory does. borg then saw a
different inode in fstat() than in the stat() before and skipped the
whole tree as a race condition.

Now, if a directory turns into another directory on a different mount
than its parent directory, we accept that as an automount, use the
fstat() result and redo the skip_inodes and --one-file-system decisions.
platform.on_different_mounts() compares the mount ids on Linux (st_dev
is not good enough there, e.g. for btrfs subvolumes) and st_dev elsewhere.

Recursion roots and --paths-from-stdin directories are opened before
taking their stat, so --one-file-system uses the device number of the
mounted filesystem (this also fixes incomplete -x backups of a ZFS
snapshot directory given as a recursion root).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.17949% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.24%. Comparing base (7e3d305) to head (dc473d2).
⚠️ Report is 27 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/borg/archiver/create_cmd.py 80.95% 3 Missing and 1 partial ⚠️
src/borg/platform/__init__.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10509      +/-   ##
==========================================
+ Coverage   89.12%   89.24%   +0.12%     
==========================================
  Files         103      104       +1     
  Lines       19783    19927     +144     
  Branches     3099     3124      +25     
==========================================
+ Hits        17631    17784     +153     
+ Misses       1490     1483       -7     
+ Partials      662      660       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

ThomasWaldmann and others added 2 commits October 7, 2026 14:50
…#6652

OpenBSD has no /proc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…borgbackup#6652

That cost an extra open/fstat/close per directory (noticeable when e.g.
find feeds millions of entries, and on network filesystems).

It is not needed: if such a directory is an automount point that is not
mounted yet, the race condition check in process_dir triggers a retry,
which then sees the mounted filesystem. Usually, the program producing
the paths has already triggered the mount anyway.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ThomasWaldmann
ThomasWaldmann merged commit e052b0e into borgbackup:master Oct 11, 2026
26 of 27 checks passed
@ThomasWaldmann
ThomasWaldmann deleted the automount-6652 branch October 11, 2026 15:57
ThomasWaldmann added a commit to ThomasWaldmann/borg that referenced this pull request Oct 30, 2026
stat() does not trigger an automount (autofs, systemd automount units,
ZFS .zfs/snapshot/*), but opening the directory does. borg create then
saw a different inode for fstat() than for stat(), considered that a
race condition and skipped the whole tree.

When the directory is a directory before and after and the opened
directory is on a different mount than its parent, accept it, use the
fstat() result and redo the skip_inodes and --one-file-system decisions.
platform.on_different_mounts() compares the mount ids on Linux (st_dev
is not good enough there, e.g. for btrfs subvolumes) and st_dev elsewhere.

Recursion roots are opened before taking their stat, so --one-file-system
uses the device number of the mounted filesystem (this also fixes
incomplete -x backups of a ZFS snapshot directory given as a recursion
root).

Backport of borgbackup#10509.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error "file inode changed" on ZFS snapshot

1 participant