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

Add support for hard links. #16

Open
aawsome opened this issue Nov 4, 2022 · 4 comments
Open

Add support for hard links. #16

aawsome opened this issue Nov 4, 2022 · 4 comments
Labels
A-commands Area: Related to commands in `rustic_core` C-enhancement Category: New feature or request

Comments

@aawsome
Copy link
Member

aawsome commented Nov 4, 2022

rustic currently saves the file # of links, as restic does. Other support for hard links is missing.

Restic uses the information of # of links and more (like device id) to (try to) restore hard links during restore. This so far only works for files within the restore and poses other problems, see restic/restic#3041 (comment).

Correct treatment of hard links during backup and restore is hard, but should be better supported. For instance:

  • Save more/better information in the metadata during backup.
  • Provide various options in restore to suit user's needs for restoring hard links.
@aawsome aawsome added the C-enhancement Category: New feature or request label Nov 4, 2022
@simonsan simonsan added the A-commands Area: Related to commands in `rustic_core` label Jul 16, 2023
@simonsan simonsan transferred this issue from rustic-rs/rustic Sep 18, 2023
@github-actions github-actions bot added the S-triage Status: Waiting for a maintainer to triage this issue/PR label Sep 18, 2023
@simonsan simonsan removed the S-triage Status: Waiting for a maintainer to triage this issue/PR label Sep 18, 2023
@zxcat
Copy link

zxcat commented Oct 10, 2023

Proper full snapshot restore + preserve hardlinks is important, otherwise restored data may suddenly take up MUCH MORE space than expected.

Also it's an optimization: you don't need to download/create/write file again, just create hardlink to existing one (if it's in the same snapshot).

@aawsome
Copy link
Member Author

aawsome commented Jan 12, 2024

I tried to dig a bit into this topic. Indeed it seems that the only way to detect hard links within a filesystem is to check the number of links and compare inodes - exactly what restic is doing within their restore.

Now there are the following issues:

  • a snapshot can contain multiple file systems, restic therefore uses also the device id to identify corresponding hard links
  • also, we might restore to different file systems. The "file system layout" might be especially different to the one we encountered during backup which makes it very difficult to decide what to do in edge cases. E.g. hard links on one filesystem should be restored to two file systems: What do we link? Should we fall back to soft links, if possible?
  • the device id on the other hand can change and therefore is generally not a good thing to save in a backup. rustic has to option --ignore-devid.
  • however, with --ignore-devid we might have two files with multiple links and the same inode number which were on different file systems and therefor not hard linked to each other. We therefore should also check for identical file contents, but this still doesn't help to exactly restore file system contents - identical files could exist on two filesystems while still having hard links on each filesystem.
  • So, we have to accept that we may be not 100% precise during restore. However, the question is, if this is really a serious problem. Usually we would restore to the same filesystem structure and if not, shouldn't care too much if hard links are exactly restored - as long as each restored file maps to the correct contents.

@zxcat
Copy link

zxcat commented Jan 13, 2024

So, we have to accept that we may be not 100% precise during restore. However, the question is, if this is really a serious problem. Usually we would restore to the same filesystem structure and if not, shouldn't care too much if hard links are exactly restored - as long as each restored file maps to the correct contents.

In some cases restoring hardlinks is important, e.g. there is a lot of large hardlinked files, but device space is limited. Real live example: macos Time Machine
There is a simple solution to make everyone happy: add an optional flag to restore hardlinks only for those users, who understand what they are doing. Or pair of flags, which only work together.
Something like: --force-restore-hardlinks --i-understand-that-hardlinks-may-be-not-precise-on-different-fs.

@zxcat
Copy link

zxcat commented Aug 25, 2024

Hi @aawsome ! Any updates on this?
Maybe just implement one simple, most likely way to restore, and notify on any errors? Seems like filename edge cases, where it's too expensive to account for all the edge cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-commands Area: Related to commands in `rustic_core` C-enhancement Category: New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants