Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(snapshots): add support for xattr #3643

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Conversation

miekg
Copy link

@miekg miekg commented Feb 12, 2024

This adds support for extended attributes on Unix - although I only tested it manually on Linux.

This should include all the needed bits, but lacks proper tests - I only did a manual tests, referenced in one of the commits, included here again:

% ./kopia repository create filesystem --path=/tmp/kopia
Enter password to create new repository:
Re-enter password for verification:

% pwd
/home/miek/src/github.com/miekg/tmp
% getfacl testfile1
# file: testfile1
# owner: miek
# group: miek
user::rw-
user:root:rw-
group::rw-
group:root:rw-
group:miek:rw-
mask::rw-
other::r--

% ./kopia --log-level=debug snapshot create /home/miek/src/github.com/miekg/tmp/

% ./kopia snapshot list
....
  2024-02-12 19:23:57 CET k0e335d9c23c5a20f78e358d1bd286865 2.1 MB drwxrwxr-x files:5 dirs:1 (latest-1..2,hourly-1,daily-1,weekly-1,monthly-1,annual-1)

% ./kopia restore k0e335d9c23c5a20f78e358d1bd286865 /tmp/XXXX
Restoring to local filesystem (/tmp/XXXX) with parallelism=8...
Processed 6 (2.1 MB) of 5 (2.1 MB).
Restored 5 files, 1 directories and 0 symbolic links (2.1 MB).

% cd /tmp/XXXX
% l
go.mod  go.sum  testfile1  tmp*  xattr.go
% getfacl testfile1
# file: testfile1
# owner: miek
# group: miek
user::rw-
user:root:rw-
group::rw-
group:root:rw-
group:miek:rw-
mask::rw-
other::r--

This adds support for reading extended attributes from disk.
Attributes() returning a fs.AttributesInfo is added to fs.Entry. Getting
the attributes from disk uses github.com/pkg/xattr.

fs.AttributesInfo is a map, which when empty is just a pointer. It being
a map (as opposed to a slice in restic) helps in comparing if the
attributes have changed (no need to allocate a map there and then).

Most other changes in snapshot/snapshotfs/* are there to implement the
extended fs.Entry interface.

Signed-off-by: Miek Gieben <[email protected]>
Signed-off-by: Miek Gieben <[email protected]>
Signed-off-by: Miek Gieben <[email protected]>
Creating a repo and backuping a file with xattrs and seeing it gets
restored.

~~~
% ./kopia repository create filesystem --path=/tmp/kopia
Enter password to create new repository:
Re-enter password for verification:

% pwd
/home/miek/src/github.com/miekg/tmp
% getfacl testfile1
user::rw-
user:root:rw-
group::rw-
group:root:rw-
group:miek:rw-
mask::rw-
other::r--

% ./kopia --log-level=debug snapshot create /home/miek/src/github.com/miekg/tmp/

% ./kopia snapshot list
....
  2024-02-12 19:23:57 CET k0e335d9c23c5a20f78e358d1bd286865 2.1 MB drwxrwxr-x files:5 dirs:1 (latest-1..2,hourly-1,daily-1,weekly-1,monthly-1,annual-1)

% ./kopia restore k0e335d9c23c5a20f78e358d1bd286865 /tmp/XXXX
Restoring to local filesystem (/tmp/XXXX) with parallelism=8...
Processed 6 (2.1 MB) of 5 (2.1 MB).
Restored 5 files, 1 directories and 0 symbolic links (2.1 MB).

% cd /tmp/XXXX
% l
go.mod  go.sum  testfile1  tmp*  xattr.go
% getfacl testfile1
user::rw-
user:root:rw-
group::rw-
group:root:rw-
group:miek:rw-
mask::rw-
other::r--
~~~

Signed-off-by: Miek Gieben <[email protected]>
@miekg miekg changed the title xattr feature: add support for xattr Feb 12, 2024
Copy link

codecov bot commented Feb 12, 2024

Codecov Report

Attention: 51 lines in your changes are missing coverage. Please review.

Comparison is base (cb455c6) 75.86% compared to head (c4de289) 77.00%.
Report is 24 commits behind head on master.

Files Patch % Lines
snapshot/restore/local_fs_output_unix.go 0.00% 18 Missing ⚠️
fs/localfs/local_fs_nonwindows.go 39.28% 16 Missing and 1 partial ⚠️
fs/entry.go 69.56% 7 Missing ⚠️
snapshot/restore/local_fs_output.go 50.00% 2 Missing and 1 partial ⚠️
snapshot/snapshotfs/all_sources.go 0.00% 2 Missing ⚠️
snapshot/snapshotfs/source_directories.go 0.00% 2 Missing ⚠️
snapshot/snapshotfs/source_snapshots.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3643      +/-   ##
==========================================
+ Coverage   75.86%   77.00%   +1.13%     
==========================================
  Files         470      470              
  Lines       37301    28537    -8764     
==========================================
- Hits        28299    21975    -6324     
+ Misses       7071     4624    -2447     
- Partials     1931     1938       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jkowalski
Copy link
Contributor

this is promising but needs a lot more work:

  • first and foremost we need a design/strategy for supporting other non-core attributes which are currently unsupported, such as Windows ACLs, additional stat_t fields, etc., perhaps 'attributes` needs to be a map of maps for extensibility, with first-level entry being the type of an attribute ("xattr", "winacl", something like that). Perhaps have a strongly-typed struct?

  • we obviously need to get it to compile on all environments and address all linter issues (make lint-all is a good check)

  • we need comprehensive tests that pass on all supported

  • we will need a way to enable/disable support for xattr for both backup and restore based on policies because fetching them is expensive and/or folks may not want to restore them. I think the default should be to not include xattrs

  • we will likely need some kind of filtering/selection so that only certain types of attributes are backed up and some can be ignored

Signed-off-by: Miek Gieben <[email protected]>
@miekg miekg changed the title feature: add support for xattr feat: add support for xattr Feb 13, 2024
Signed-off-by: Miek Gieben <[email protected]>
@miekg
Copy link
Author

miekg commented Feb 13, 2024

thanks for your comments

we obviously need to get it to compile on all environments and address all linter issues (make lint-all is a good check)

yep

we need comprehensive tests that pass on all supported

yep, and adding support for openbsd and freebsd

we will need a way to enable/disable support for xattr for both backup and restore based on policies because fetching them is expensive and/or folks may not want to restore them. I think the default should be to not include xattrs

It this with your proposed first point, or is this already expensive in it's current form, where it uploads a nil map if there are no attributes?

first and foremost we need a design/strategy for supporting other non-core attributes which are currently unsupported, such as Windows ACLs, additional stat_t fields, etc., perhaps 'attributes` needs to be a map of maps for extensibility, with first-level entry being the type of an attribute ("xattr", "winacl", something like that). Perhaps have a strongly-typed struct?

can do

we will likely need some kind of filtering/selection so that only certain types of attributes are backed up and some can be ignored

based on the first map key? I.e. like --no-axttr woudl exclude those, but leave, say, winacl? Or more detailed on specific axttr fields?

@miekg miekg changed the title feat: add support for xattr feat(snapshots): add support for xattr Feb 18, 2024
@miekg miekg marked this pull request as draft February 20, 2024 10:43
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.

None yet

2 participants