copy hard links to different filesystem


I make regular backups with storebackup to a USB HD.
Storebackup use incremental baclup using hard links: if I make today a backup it stores it in a directory called 2018_03_01 and it backs up every single file (zipped).
If tomorrow I make another backup it will create another directory called 2018_03_02 and again it will copy every single file to it, but unchanged files will be hard links to the files in 2018_03_01. So if directory 2018_03_01 was 10GB in size and I changed only files total 100Mb, the size of both 2018_03_01 and 2018_03_02 will be 10.1GB instead of 20GB altough each one contains a “full” copy.

the point is that now I would like to move a complete set of directories with my backup (an old backup) to a different usb HD, but I don’t know how to handle hard links.
I’m afraid that just a cp -a will not copy hard links but instead will create a complete copy of each directory, resulting in a lot of space wasted.

Is there a way to copy a set of directories but copying them replicating hard links in the destination directory?


“rsync -aH” would seem to fit (man rsync).
Also I suspect that “dd” might work.

Does the recipient filesystem support hard-links?

Reading what you say, I come to the conclusion that you simply want a copy of a file system to another place (partition most probably). As suggested above, dd will copy bye for byte and thus when you dd the contents of one partition to another partition, nothing will change (and thus when that contents is a file system with hard links, that will be found on the new place). But take care, the new partition should be exact the same size as the old one (it can be larger, but that is a constructions you must know how to handle).

“dd” is a general purpose file manipulation tool, it’s not just for copying filesystems or partitions. It works for files and directories too with a number of translation-substitution options.
“rsync” is simpler to use, but probably a bit slower.

In fact it only copies files, but because in Unix/Linux “everything is a file”, it can copy partitions (the file is /dev/sdXn) and complete disks (the file is /dev/sdX), etc.

The important thing here is that it copies bye for byte. Thus if the contents of the “file” copied is a file system, that file system will be copied byte for byte and thus when that file system has hard links, they will be copied by definition. And that is what I assume the OP wants.

BTW, dd on a file that is of the type directory, might not do what you expect.

I mistakenly thought that it would copy a listt of inodes and names. Actually dd refuses to copy directories, I am not sure why.

I assume that there is no real use case for copying the bytes that make up a directory. Outside it’s environment you can not do much with it IMO.

I see the same happens when you try to list the bytes with od.

I normally used the traditional old method:

cd new-directory
( cd old-directory && tar cf - . ) | tar xpf -

(sometimes called a tar pipe).

Yes, the recipient support hard links.
The origin is a ext4 partitioned usb HD and the recipient is also a ext4 partitioned usb HD.
The content of the first usb HD is a backup of some parts of my /home filesystem created with storeBackup which uses hard links to create incremental copies.

I have found that a copy from usb HD A to usb HD b using midnight commander copy reproduces the hard links structure