rsync hard link preservation across heterogeneous destination filesystems
0 reputation · 07 Apr 2022, 16:22 UTC
0 reputation · 07 Apr 2022, 16:22 UTC
When using rsync to restore a dataset containing hard links, the default behavior treats each link as an independent file. While the --hard-links flag is intended to preserve the inode relationship from the source, the outcome becomes inconsistent when the destination filesystem differs from the source.
The challenge arises when the target volume does not support hard links, such as a mounted FAT32 partition or a non-configured NTFS volume. In these scenarios, rsync may create duplicate file copies for every link encountered. This leads to significant disk space inflation and breaks any application logic that relies on shared inode semantics for deduplication or data consistency.
How does rsync handle the failure to create a hard link on the destination when the --hard-links flag is active? Is there a specific configuration to prevent the creation of duplicate files if the destination lacks link support during the restoration process?
When --hard-links is active and the destination lacks hard link support, rsync silently creates independent copies for each file that was hard-linked on the source. No warning or error is emitted; the transfer completes with exit code 0.
rsync attempts to recreate hard link relationships by matching files with identical content and metadata. When link() fails on the destination (e.g., FAT32, exFAT, read-only NTFS, or permission-restricted directories), rsync falls back to copying each file independently. This is by design—rsync does not treat link creation failure as a fatal condition.
link() system call will always fail.link().The result is silent disk space inflation and broken application logic that depends on shared inodes for deduplication or change detection.
touch testfile && ln testfile testlink && rm testfile testlinkIf this succeeds, hard links are supported.
rsync -avh --hard-links --progress src/ dest/Check whether files that should be linked appear as separate copies.
find dest/ -links +1 -type fThis lists files that retain hard link counts; absence indicates duplication occurred.
rsync has no flag to abort when hard link creation fails. The --hard-links option only enables link recreation; it does not enforce it. If link preservation is a hard requirement, pre-check the destination or use a filesystem-aware tool that can report unsupported operations.
If you can share the destination filesystem type and mount options (e.g., mount | grep /path/to/dest), I can confirm whether hard links are technically possible there.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.