Skip to content

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

Open
ThomasWaldmann wants to merge 2 commits into
borgbackup:masterfrom
ThomasWaldmann:automount-6652
Open

ThomasWaldmann wants to merge 2 commits into
borgbackup:masterfrom
ThomasWaldmann:automount-6652

Conversation

@ThomasWaldmann

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 and --paths-from-stdin directories are opened before taking their stat, so the mount happens early and --one-file-system uses the device number of 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.50000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.10%. Comparing base (7e3d305) to head (ee710a4).
⚠️ Report is 9 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/borg/archiver/create_cmd.py 81.81% 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.10%   -0.02%     
==========================================
  Files         103      103              
  Lines       19783    19818      +35     
  Branches     3099     3105       +6     
==========================================
+ Hits        17631    17659      +28     
- Misses       1490     1496       +6     
- Partials      662      663       +1     

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

…#6652

OpenBSD has no /proc.

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

This branch has not been deployed

No deployments
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