From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox-backup 4/5] client: pxar: optionally fail on entries left out for lack of permission
Date: Tue, 1 Dec 2026 10:11:10 +0100 [thread overview]
Message-ID: <20261201091111.940190-5-dietmar@proxmox.com> (raw)
In-Reply-To: <20261201091111.940190-1-dietmar@proxmox.com>
Leaving out entries that cannot be read lets a backup succeed while
it misses data, which retention may then use to replace complete
snapshots. A caller that needs all data, for example because it backs
up folders it expects to own, cannot rely on such a backup.
A new option fails the archive at the first such entry instead. This
includes a .pxarexclude that cannot be read, also one excluded as an
entry, as ignoring its patterns may add much more data than intended.
It is off by default, so existing callers keep leaving entries out.
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
---
pbs-client/src/pxar/create.rs | 39 +++++++++++++++----
proxmox-backup-client/src/main.rs | 1 +
.../src/proxmox_restore_daemon/api.rs | 1 +
pxar-bin/src/main.rs | 1 +
4 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs
index 47ae4b01c..c6d4b8b41 100644
--- a/pbs-client/src/pxar/create.rs
+++ b/pbs-client/src/pxar/create.rs
@@ -62,6 +62,9 @@ pub struct PxarCreateOptions {
/// Called with the archive-relative path of each entry left out for lack of permission. For
/// a `.pxarexclude` file, this also means that its patterns were not applied.
pub on_access_denied: Option<Box<dyn FnMut(&Path) + Send>>,
+ /// Fail on the first entry that cannot be read for lack of permission, instead of leaving it
+ /// out
+ pub fail_on_access_denied: bool,
}
pub type MetadataArchiveReader = Arc<dyn ReadAt + Send + Sync + 'static>;
@@ -199,6 +202,7 @@ struct Archiver {
reuse_stats: ReuseStats,
split_archive: bool,
on_access_denied: Option<Box<dyn FnMut(&Path) + Send>>,
+ fail_on_access_denied: bool,
}
type Encoder<'a, T> = pxar::encoder::aio::Encoder<'a, T>;
@@ -311,6 +315,7 @@ where
reuse_stats: ReuseStats::default(),
split_archive,
on_access_denied: options.on_access_denied,
+ fail_on_access_denied: options.fail_on_access_denied,
};
archiver
@@ -511,7 +516,7 @@ impl Archiver {
warn!("failed to open file: {path:?}: access denied");
// reported here rather than as an entry, as its patterns are not applied, also
// when a pattern excludes it as an entry
- self.report_access_denied(Some(&path));
+ self.report_access_denied(Some(&path))?;
return Ok(());
}
Err(Errno::ESTALE) => {
@@ -696,7 +701,7 @@ impl Archiver {
Err(Errno::EACCES) => {
// may happen for fuse mountpoints without allow_other or allow_root
warn!("warning: failed to stat file: {full_path:?}: access denied");
- self.report_access_denied(Some(&full_path));
+ self.report_access_denied(Some(&full_path))?;
continue;
}
Err(Errno::ESTALE) => {
@@ -733,11 +738,15 @@ impl Archiver {
warn!("warning: stale file handle encountered while reading: {path:?}");
}
- fn report_access_denied(&mut self, path: Option<&PathBuf>) {
+ fn report_access_denied(&mut self, path: Option<&PathBuf>) -> Result<(), Error> {
let path = path.unwrap_or(&self.path);
if let Some(callback) = self.on_access_denied.as_mut() {
callback(path);
}
+ if self.fail_on_access_denied {
+ bail!("unable to back up {path:?}: access denied");
+ }
+ Ok(())
}
fn report_vanished_file(&self) {
@@ -784,7 +793,7 @@ impl Archiver {
warn!("failed to open file: {c_file_name:?}: access denied");
// reported when its directory's patterns were read, which comes first
if c_file_name != c".pxarexclude" {
- self.report_access_denied(None);
+ self.report_access_denied(None)?;
}
return Ok(());
}
@@ -2009,8 +2018,9 @@ mod tests {
Ok(testdir)
}
- /// Archives `dir` and returns the entries reported as left out for lack of permission.
- fn archive_access_denied(dir: &Path) -> Result<Vec<PathBuf>, Error> {
+ /// Archives `dir` and returns the entries reported as left out for lack of permission, or
+ /// with `fail`, fails at the first of them.
+ fn archive_access_denied(dir: &Path, fail: bool) -> Result<Vec<PathBuf>, Error> {
let denied: Arc<Mutex<Vec<PathBuf>>> = Arc::default();
let collect = Arc::clone(&denied);
let options = PxarCreateOptions {
@@ -2018,6 +2028,7 @@ mod tests {
on_access_denied: Some(Box::new(move |path| {
collect.lock().unwrap().push(path.to_path_buf())
})),
+ fail_on_access_denied: fail,
..Default::default()
};
let source_dir = Dir::open(dir, OFlag::O_DIRECTORY, Mode::empty())?;
@@ -2065,16 +2076,27 @@ mod tests {
PathBuf::from("sub/.pxarexclude"),
];
// the unreadable .pxarexclude only once, though it is also opened as an entry
- let reported = archive_access_denied(&testdir);
+ let reported = archive_access_denied(&testdir, false);
+ let failed = archive_access_denied(&testdir, true);
// also when a pattern excludes it as an entry
std::fs::write(testdir.join(".pxarexclude"), ".pxarexclude\n")?;
- let excluded = archive_access_denied(&testdir);
+ let excluded = archive_access_denied(&testdir, false);
+ std::fs::write(
+ testdir.join(".pxarexclude"),
+ "locked\nsecret\n.pxarexclude\n",
+ )?;
+ let excluded_failed = archive_access_denied(&testdir, true);
for path in ["locked", "secret", "sub/.pxarexclude"] {
chmod(path, 0o755)?;
}
assert_eq!(reported?, expected);
assert_eq!(excluded?, expected);
+ assert!(failed.is_err());
+ // only the .pxarexclude is left, which is excluded as an entry, but whose patterns would
+ // have been ignored
+ let err = format!("{:#}", excluded_failed.unwrap_err());
+ assert!(err.contains("sub/.pxarexclude"), "{err}");
Ok(())
}
@@ -2154,6 +2176,7 @@ mod tests {
reuse_stats: ReuseStats::default(),
split_archive: true,
on_access_denied: None,
+ fail_on_access_denied: false,
};
let accessor = Accessor::new(pxar::PxarVariant::Unified(reader), metadata_size)
diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs
index ef1b1575b..e71677633 100644
--- a/proxmox-backup-client/src/main.rs
+++ b/proxmox-backup-client/src/main.rs
@@ -1243,6 +1243,7 @@ async fn create_backup(
previous_ref,
max_cache_size,
on_access_denied: None,
+ fail_on_access_denied: false,
};
let upload_options = UploadOptions {
diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
index aac46592b..c3ca6b807 100644
--- a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
+++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
@@ -371,6 +371,7 @@ fn extract(
previous_ref: None,
max_cache_size: None,
on_access_denied: None,
+ fail_on_access_denied: false,
};
let pxar_writer = pxar::PxarVariant::Unified(TokioWriter::new(writer));
diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs
index 6511c1b17..05358fa52 100644
--- a/pxar-bin/src/main.rs
+++ b/pxar-bin/src/main.rs
@@ -384,6 +384,7 @@ async fn create_archive(
previous_ref: None,
max_cache_size: None,
on_access_denied: None,
+ fail_on_access_denied: false,
};
let source = PathBuf::from(source);
--
2.47.3
next prev parent reply other threads:[~2026-12-01 9:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 9:11 [PATCH proxmox-backup 0/5] client: report or fail on files left out for lack of permission Dietmar Maurer
2026-12-01 9:11 ` [PATCH proxmox-backup 1/5] client: pxar: handle open errors at the call sites Dietmar Maurer
2026-12-01 9:11 ` [PATCH proxmox-backup 2/5] client: pxar: name the directory of an unreadable .pxarexclude Dietmar Maurer
2026-12-01 9:11 ` [PATCH proxmox-backup 3/5] client: pxar: let callers see entries left out for lack of permission Dietmar Maurer
2026-12-01 9:11 ` Dietmar Maurer [this message]
2026-12-01 9:11 ` [PATCH proxmox-backup 5/5] client: backup: add option to fail on files that cannot be read Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201091111.940190-5-dietmar@proxmox.com \
--to=dietmar@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.