Skip to content

feat(internal/fs/node): Restore ownership by name#5449

Merged
MichaelEischer merged 1 commit into
restic:masterfrom
provokateurin:restore-ownership-by-name
Nov 16, 2025
Merged

feat(internal/fs/node): Restore ownership by name#5449
MichaelEischer merged 1 commit into
restic:masterfrom
provokateurin:restore-ownership-by-name

Conversation

@provokateurin

Copy link
Copy Markdown
Contributor

What does this PR change? What problem does it solve?

When doing a restore the UID and GID for the chown are now looked up on the current system, so that the ownership will actually match the expected user/group names.

I am not sure if this needs extra tests, since the existing ones all pass which at least validates that it didn't break existing behavior.
I am also not sure if this should be behind a CLI flag and if this needs additional documentation.
Please let me know if any of those things are needed, I'm happy to put more work into this feature.

This is my first PR to restic, but I've been a very happy user so far and this issues has been biting me quite a bit. I went so far to even create a script that would be put into every snapshot, in order to correctly restore the ownership, but it would be great to have a solution directly in restic.

Was the change previously discussed in an issue or on the forum?

Fixes #3572

Checklist

  • I have added tests for all code changes.
  • I have added documentation for relevant changes (in the manual).
  • There's a new file in changelog/unreleased/ that describes the changes for our users (see template).
  • I'm done! This pull request is ready for review.

@zumm

zumm commented Aug 2, 2025

Copy link
Copy Markdown

I think it should be optinal. Setting it as default is breaking change.

Also any chance we could get it for Windows?

@provokateurin

Copy link
Copy Markdown
Contributor Author

While I can see why you say it is a breaking change, I don't think it is one since the original behavior should stay on most systems where the uid and gid mappings are the same. It just fixes the behavior for systems where this isn't the case.

I don't know about Windows, but it didn't have any chown-like thing before on a restore. Also I just don't know much about Windows in general, do they even have the concept of file ownership with uid and gid?

@zumm

zumm commented Aug 2, 2025

Copy link
Copy Markdown

There is concept of Security Descriptors on Windows. Support was introduced in #4509 (and this is the example why features should be optional even if they seems like good default).

@provokateurin provokateurin force-pushed the restore-ownership-by-name branch from f4b1cd1 to fed57ac Compare August 20, 2025 14:10
@provokateurin

Copy link
Copy Markdown
Contributor Author

@zumm I added a CLI flag to optionally enable the new behavior.

@MichaelEischer

Copy link
Copy Markdown
Member

There is concept of Security Descriptors on Windows. Support was introduced in #4509 (and this is the example why features should be optional even if they seems like good default).

Windows will have to be handled separately. The security descriptors rely on unique IDs which can't be easily translated between systems.

@provokateurin provokateurin force-pushed the restore-ownership-by-name branch from fed57ac to cf722eb Compare October 4, 2025 09:18
@provokateurin

Copy link
Copy Markdown
Contributor Author

Rebased to resolve conflicts

@MichaelEischer MichaelEischer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While taking a closer look, I noticed a rather ugly problem that cannot be solved by this PR. Restic stores POSIX ACLs in a backup, but only in their numeric on-disk format. Thus, we have no way of restoring those based on their name.

However, fixing that is out of scope for this PR. Instead let's document the limitation somewhere (ideally in the CLI parameter). Besides that the PR only needs tests for the new codepaths.

Comment thread cmd/restic/cmd_restore.go Outdated
Comment thread changelog/unreleased/issue-3572
Comment thread changelog/unreleased/issue-3572 Outdated
Comment thread internal/fs/node_unix.go Outdated
Comment thread changelog/unreleased/issue-3572 Outdated
Comment thread changelog/unreleased/issue-3572 Outdated
Comment thread internal/fs/node.go
@provokateurin

Copy link
Copy Markdown
Contributor Author

Instead let's document the limitation somewhere (ideally in the CLI parameter)

What exactly would you write there? I feel like it does not really belong into the usage description of the new CLI flag, but maybe for the restore command itself.

@provokateurin provokateurin force-pushed the restore-ownership-by-name branch from cf722eb to daef32b Compare October 5, 2025 08:55
@MichaelEischer

Copy link
Copy Markdown
Member

What exactly would you write there? I feel like it does not really belong into the usage description of the new CLI flag, but maybe for the restore command itself.

The CLI flag could get a (except POSIX ACLs) suffix. Or add a somewhat longer description to the restore command itself. Or probably better: add both.

Comment thread cmd/restic/cmd_restore.go Outdated
@provokateurin

Copy link
Copy Markdown
Contributor Author

@MichaelEischer anything missing from my side or something I can do to get it merged? No pressure though, I see you are doing a lot of work for restic already! ❤️

@provokateurin

Copy link
Copy Markdown
Contributor Author

Sorry to ping again, @MichaelEischer any chance you could have another look? I resolved all review comments.

@MichaelEischer MichaelEischer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long delay. I only have two small nits regarding the changelog left, then this is ready for merging.

Comment thread changelog/unreleased/issue-3572
Comment thread changelog/unreleased/issue-3572 Outdated
@provokateurin

Copy link
Copy Markdown
Contributor Author

Done! Thanks for reviewing!

@MichaelEischer MichaelEischer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

For handling POSIX ACLs correctly, I've created a minimal issue: #5598

@MichaelEischer MichaelEischer merged commit 3b854d9 into restic:master Nov 16, 2025
12 checks passed
@provokateurin provokateurin deleted the restore-ownership-by-name branch November 16, 2025 15:56
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.

Also support restoring ownership by name

4 participants