When restoring files from ZFS snapshots, a simple way is to simply copy back the files (rsync -aX /rpool/homes/.zfs/snapshot/autosnap_2025-02-01_00:00:02_daily/steffen/testdir/ /rpool/homes/steffen/testdir/).
What happens if someone uses a hardlink instead of the file copy? From what I hope form ZFS this is either not possible or safe, is this correct? In the internet, when it comes to restoring files, all suggest copying instead of hardlinking, so that’s why I’m asking.
When using a hardlink, I assume this would be a faster operation, at least for huge files (if it is possibly to hardlink at all).
ZFS snapshots are read-only. The hard link would have the same property so it wouldn’t really be restoring the file, but it wouldn’t be any less safe than mounting the snapshot to copy a file.
thank you for your quick reply. So it would work, would be safe from ZFS point of view, but could lead to any kind of unexpected trouble because having an “immutable” file, is this correct?
You have it right with one caveat:
Hard links only work across the same file system.
I’m not sure how ZFS exposes mounted snapshots, so it might be a new file system which would stop hard links from being created.
What’s your use case for this? If it’s more than academic than there might be a reasonable solution outside of hard linking
It would not work. Hard links cannot cross filesystem boundaries, and a snapshot is a separately mounted filesystem.
With that said, modern ZFS features the BRT which enables deduplicated copies. This isn’t entirely free, but it accelerates copies which use it by several orders of magnitude (eg copying several GiB in a couple of hundred milliseconds).