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

Hardlink instead of rsync #14

Open
PeterNerlich opened this issue Feb 3, 2021 · 1 comment
Open

Hardlink instead of rsync #14

PeterNerlich opened this issue Feb 3, 2021 · 1 comment

Comments

@PeterNerlich
Copy link

I am not well-versed in that matter, but I had the thought whether hardlinking the files would actually be a better idea.

From what I think I understand, hardlinks are directory entries that point to the same inode already referenced in another directory and/or entry. Inodes have a reference counter, so when deleting a file (path), the corresponding entry is removed and the actual inode is only really deleted if it has no more references. Does this behaviour differ in different file systems?
The only reason to use plain cp or rsync or otherwise creating new inodes with the same content then is to either then modify the independent copy, or when the two locations are on different file systems, right?

In case that all holds true, and if my assumption is correct that we expect the number of cases where /usr/lib/modules/backup/ somehow is a different file system to be negligible, then it would be a much better idea to just hardlink all the files with cp -lr: It doesn't use more space and is much faster because only directory entries are written. Being deleted should not erase the data because of the reference counter and restoring the modules will be the same, just the other way around.

@moviuro
Copy link

moviuro commented Mar 18, 2021

To add to this report: cp(1) is 10x faster than rsync here.

# time cp -alr "/usr/lib/modules/${KVER}" /usr/lib/modules/backup 
cp -alr "/usr/lib/modules/${KVER}" /usr/lib/modules/backup  0,26s user 0,26s system 105% cpu 0,497 total
# time rsync -AHXal --delete-after "/usr/lib/modules/${KVER}" /usr/lib/modules/backup/
rsync -AHXal --delete-after "/usr/lib/modules/${KVER}"   1,17s user 0,80s system 41% cpu 4,731 total

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

No branches or pull requests

2 participants