How to copy directory across filesystems while keeping hard links

Cibot

New Member
Joined
Nov 29, 2021
Messages
2
Reaction score
0
Credits
28
I've recently been trying to move my docker data from one path to another. This is due to the fact, that we wanted to move it to a larger filesystem. Now currently, when I call df it tells me that the filesystem has this usage:

Code:
/dev/sda2                         163544064 114299880  46210088  72% /

When I call du /var/lib/docker.old/ -hs, I see following:

Code:
193G    /var/lib/docker.old/

I assumed this is due to the fact that hard links are used a lot. So I tried rsync -aHP or rsync -aP or cp -R and finally I also tried tar -cf - /var/lib/docker.old/ | tar -C /fs1/docker -xv. According to rsync, -H should preserve hard links and -a implicitly does -l which keeps symlinks. Also from reading on StackOverflow I could find that TAR's keep the hard links aswell as such they should be preserved after packing and unpacking. Unfortunately, when I do df on the newly created docker directory:

Code:
/dev/mapper/vg01-lv01             261590020 202665432  58924588  78% /fs1

This translates to rougghly the 193G which du shows.
After analyzing the files with find .. -links 2 and stat I could see the inodes of certain files.
As an example, there are lots of zoneinfo files in all the containers in docker which use the same inode. Here a concrete example:
Code:
/var/lib/docker.old/btrfs/subvolumes/138ade54fda6a1ecd5b061b2eb57d6b0d6617ff01de12b28384b34ce4b24bc9a/usr/share/zoneinfo/posix/America/Lower_Princes

Original:
Code:
/fs1# find /var/lib/docker.old -inum 13998 | wc -l
88

Copied:
Code:
/fs1# find /fs1/docker -inum 29883 | wc -l
2

From this my conclusion is, that the hard links are not copied correctly. This result is the same for any of the copying methods used above.
Am I doing something incorrect or wrong? My operating system is SLES 12 SP5. Now I definitely could just export all the images from my current docker and import them to a newly installed one on the new location. But that just doesn't sit right with me as I feel like this should be easily doable but I just can't get it right.
 


f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,900
Reaction score
3,526
Credits
35,667
You could try using rsync which had this option.
Code:
 --hard-links, -H         preserve hard links
 
OP
C

Cibot

New Member
Joined
Nov 29, 2021
Messages
2
Reaction score
0
Credits
28
As I wrote, I already tried: rsync -aHP
This should use -H. Unless for some reason -a breaks it.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Latest posts

Top