Results 1 to 9 of 9

Thread: copy hard links to different filesystem

  1. #1

    Default copy hard links to different filesystem

    Hi.

    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?

    regards

  2. #2
    Join Date
    Oct 2008
    Location
    Glasgow, Scotland
    Posts
    1,277

    Default Re: copy hard links to different filesystem

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

    Does the recipient filesystem support hard-links?
    --
    slàinte mhath,
    rayH

    ~ knowing the right answer is easier than knowing the right question.

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,795

    Default Re: copy hard links to different filesystem

    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).
    Henk van Velden

  4. #4
    Join Date
    Oct 2008
    Location
    Glasgow, Scotland
    Posts
    1,277

    Default Re: copy hard links to different filesystem

    “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.
    --
    slàinte mhath,
    rayH

    ~ knowing the right answer is easier than knowing the right question.

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,795

    Default Re: copy hard links to different filesystem

    Quote Originally Posted by eng-int View Post
    “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.
    Henk van Velden

  6. #6
    Join Date
    Oct 2008
    Location
    Glasgow, Scotland
    Posts
    1,277

    Default Re: copy hard links to different filesystem

    Quote Originally Posted by hcvv View Post
    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.
    --
    slàinte mhath,
    rayH

    ~ knowing the right answer is easier than knowing the right question.

  7. #7
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,795

    Default Re: copy hard links to different filesystem

    Quote Originally Posted by eng-int View Post
    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.
    Henk van Velden

  8. #8
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    15,676
    Blog Entries
    3

    Default Re: copy hard links to different filesystem

    Quote Originally Posted by fperal View Post
    Is there a way to copy a set of directories but copying them replicating hard links in the destination directory?
    I normally used the traditional old method:

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

    (sometimes called a tar pipe).
    openSUSE Leap 15.3; KDE Plasma 5.18.6;

  9. #9

    Default Re: copy hard links to different filesystem

    Quote Originally Posted by eng-int View Post
    “rsync -aH” would seem to fit (man rsync).
    Also I suspect that “dd” might work.

    Does the recipient filesystem support hard-links?

    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

    regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •