restore: Add option --numeric-id

This commit is contained in:
Alexander Weiss 2022-07-06 13:12:53 +02:00
parent 739b207441
commit 68d28b413a
2 changed files with 18 additions and 3 deletions

View File

@ -193,11 +193,9 @@ impl LocalBackend {
fs::create_dir(&dirname).unwrap();
}
// TODO: times
pub fn set_user_group(&self, item: impl AsRef<Path>, meta: &Metadata) {
let filename = self.path.join(item);
// set uid/gid
let user = meta
.user
.as_ref()
@ -216,6 +214,15 @@ impl LocalBackend {
chown(&filename, uid, gid).unwrap();
}
pub fn set_uid_gid(&self, item: impl AsRef<Path>, meta: &Metadata) {
let filename = self.path.join(item);
let uid = meta.uid.map(Uid::from_raw);
let gid = meta.gid.map(Gid::from_raw);
chown(&filename, uid, gid).unwrap();
}
pub fn set_permission(&self, item: impl AsRef<Path>, meta: &Metadata) {
let filename = self.path.join(item);

View File

@ -26,6 +26,10 @@ pub(super) struct Opts {
#[clap(long)]
delete: bool,
/// use numeric ids instead of user/groug when restoring uid/gui
#[clap(long)]
numeric_id: bool,
/// snapshot to restore
id: String,
@ -151,7 +155,11 @@ async fn restore_metadata(
while let Some((path, node)) = node_streamer.try_next().await? {
if !opts.dry_run {
dest.create_special(&path, &node);
dest.set_user_group(&path, node.meta());
if opts.numeric_id {
dest.set_uid_gid(&path, node.meta());
} else {
dest.set_user_group(&path, node.meta());
}
dest.set_permission(&path, node.meta());
}
}