From 00212fa4a8b07f2d1436910a35906967bb7f8eef Mon Sep 17 00:00:00 2001 From: Tesshu Flower Date: Mon, 2 Dec 2024 23:33:15 -0500 Subject: [PATCH] linux default restore only user xattrs, doc update * On Linux restore only user.* xattrs by default * restore all for other OSs * Update docs and changelog about the new restore flags --exclude-xattr and --include-xattr Signed-off-by: Tesshu Flower --- changelog/unreleased/issue-5089 | 22 ++++++++++++++++++++++ cmd/restic/cmd_restore.go | 11 ++++++++++- doc/050_restore.rst | 16 ++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/issue-5089 diff --git a/changelog/unreleased/issue-5089 b/changelog/unreleased/issue-5089 new file mode 100644 index 000000000..51b5a679c --- /dev/null +++ b/changelog/unreleased/issue-5089 @@ -0,0 +1,22 @@ +Enhancement: Allow including or excluding extended file attributes +during restore. + +# Describe the problem in the past tense, the new behavior in the present +# tense. Mention the affected commands, backends, operating systems, etc. +# If the problem description just says that a feature was missing, then +# only explain the new behavior. +# Focus on user-facing behavior, not the implementation. +# Use "Restic now ..." instead of "We have changed ...". +# +Restic restore used to attempt to restore all extended file attributes. +Now two new command line flags are added to restore to control which +extended file attributes will be restored. + +The new flags are `--exclude-xattr` and `--include-xattr`. + +If the flags are not provided, restic will default to restoring +only `user` namespaced extended file attributes on Linux, and all +extended file attributes on other operating systems. + +https://github.com/restic/restic/issues/5089 +https://github.com/restic/restic/pull/5129 diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index 3bc6ac5c5..870d496c9 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -3,6 +3,7 @@ package main import ( "context" "path/filepath" + "runtime" "time" "github.com/restic/restic/internal/debug" @@ -300,6 +301,14 @@ func getXattrSelectFilter(opts RestoreOptions) (func(xattrName string) bool, err }, nil } - // no includes or excludes, set default of including all xattrs + // User has not specified any xattr includes or excludes + if runtime.GOOS == "linux" { + // For Linux, set default of including only user.* xattrs + return func(xattrName string) bool { + shouldInclude, _ := filter.IncludeByPattern([]string{"user.*"}, Warnf)(xattrName) + return shouldInclude + }, nil + } + // Not linux, default to including all xattrs return func(_ string) bool { return true }, nil } diff --git a/doc/050_restore.rst b/doc/050_restore.rst index 9558ab1d4..4ca738a3f 100644 --- a/doc/050_restore.rst +++ b/doc/050_restore.rst @@ -88,6 +88,22 @@ disk space. Note that the exact location of the holes can differ from those in the original file, as their location is determined while restoring and is not stored explicitly. +Restoring extended file attributes +---------------------------------- + +By default, user namespaced extended attributes for files are restored on Linux, +and all extended attributes are restored for other operating systems. + +Use ``--exclude-xattr`` and ``--include-xattr`` to control which extended +attributes are restored for files in the snapshot. For example, to restore +user and security namespaced extended attributes for files: + +.. code-block:: console + + $ restic -r /srv/restic-repo restore 79766175 --target /tmp/restore-work --include-xattr user.* --include-xattr security.* + enter password for repository: + restoring to /tmp/restore-work + Restoring in-place ------------------