Repository navigation
create: back up automounted directories, fixes #6652 - #10509
Merged
Merged
Conversation
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 Report❌ Patch coverage is
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. |
…#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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6652.
Problem
stat()/lstat()do not trigger an automount (on Linux, they act as ifAT_NO_AUTOMOUNTwas given), but opening the directory does.borg createstats a directory, then opens it and compares withfstat(): for an automount point that is not mounted yet, the first stat is the automount point and thefstat()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
.automountunits 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), asst_devis not good enough there (btrfs subvolumes have their ownst_devwithout being a mount). Other platforms comparest_dev. If it can not be determined, the answer isNone, 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 raisesBackupRaceConditionError.fstat()result and redo theskip_inodesand--one-file-systemdecisions, so an automounted filesystem is handled like an already mounted one.--one-file-systemuses the device number of the mounted filesystem.--paths-from-stdinare 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 aborg createtest 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:
-x-xonly the mountpoint dir.automountunit (direct autofs mount)-xon.zfs/snapshot/<snap>as recursion rootst_devcomparison would say "different")ZFS 2.3.9 keeps the inode number of the snapshot root (only
st_devchanges), so the original error does not appear there anymore, but the-xdecision was based on the automount point'sst_dev.FreeBSD 15 and NetBSD 11 autofs do not mount when the directory is opened (only on the first lookup inside it), so
stat()andfstat()agree there and this change makes no difference. FreeBSD ZFS mounts snapshots on lookup, so it is not affected either.🤖 Generated with Claude Code