Copy to another NTFS disk and preserve hard links

10

2

I have to copy directory structure from one local NTFS disk to another (Windows 7+) and preserve hard links that exist within this directory structure.

An acceptable solution would be to replace hard links with (relative) symbolic links before copy, but I'm not sure if it is practicable either.

What are the options here?

Estus Flask

Posted 2015-11-07T02:39:33.720

Reputation: 123

According to http://superuser.com/questions/624811/copy-files-from-one-drive-to-another-and-keep-hard-link-in-windows, a software caled "Shadow Copy Cloner" can do that.

– Vojtech – 2015-11-09T21:46:09.333

1@Vojtech It isn't freeware and seems to be unavailable. But ln.exe suits my needs, on the other hand. However, I would prefer to have an alternative with GUI. – Estus Flask – 2015-11-09T21:59:45.437

1@PJMahoney Yes, these are hard links, there would be no problems with copying junctions and symbolics, the latter could be just copied and fixed later. I don't intend to clone it, just to copy the directory structure (which is a part of the whole disk) to another non-empty disk. – Estus Flask – 2015-11-11T17:55:18.350

Answers

9

Tool To Copy Hard Links Across Separate Disk Partitions

LN - Command Line Hardlinks

Command: ln --copy x:\dir\dir2 y:\dir\newdir

In the above example the directories and files below x:\dir\dir2 are copied to y:\dir\newdir, and all hardlinks/junctions/symbolic links within x:\dir\dir2 are copied/tied to their new locations under y:\dir\newdir.

Resource: http://schinagl.priv.at/nt/ln/ln.html

Download: http://schinagl.priv.at/nt/ln/ln.html#contact

Note: It appears you just download this software for your CPU architecture from the ZIP file, as well as the vcredist (Visual C++ Redistributable) and install it. Then just extract the files and folders from the ZIP file to a new folder somewhere (.e.g C:\Temp). In command line, just go to that [directory] folder and then run the needed commands for your drive locations as the above example shows. Running ln --help shows help detail but the above command example is supposed to copy the hard links per the documentation.


Link Shell Extension

Resource: http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html

Download: http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html#contact

Sections or Functions of Interest with this Software

  • Smart Mirror
  • Clone
  • Smart Copy

ln - Command Line Hardlinks - Download Screen Shot enter image description here

Link Shell Extension - Download Screen Shot enter image description here


INTERESTING NOTES

It appears hard links are locked to the same disk partition for their file pointers, etc. and cannot be used across multiple partitions. Also, hard links on NTFS partitions are part of the Master File Table records (or attributes for the counts at least) so copying these to an existing disk that has it's own MFT would seem like a problem if you don't clone byte-for-byte at the partition level at least.

Pimp Juice IT

Posted 2015-11-07T02:39:33.720

Reputation: 29 425

4

The command-line utility rsync does what you ask.

Presuming your old data is on location A, and your new data is on B, do the following:

rsync -ahPruvz --hard-links A B

Quoting from rsync manual:

This tells rsync to look for hard-linked files in the source and link together the corresponding files on the destination.

How to obtain rsync and use it? There are 2 easy alternatives for Windows:

First alternative: use cygwin. It's a windows software. Install it, add rsync at the step of selecting packages. Leave everything else defaulted. After you install it, use its shell to type in the command. If you want, you may use the full path, /usr/bin/rsync instead of just rsync. If you want to access Windows drives, use paths like "/cygwin/drives" and always try to auto-complete using TAB.

Second alternative: if it's a desktop computer, use a live GNU/Linux distribution. Prepare a live USB image, boot from it, mount the desired disks and invoke rsync. If the live image does not have rsync, install it. (apt-get install rsync in Debian and its derivatives.) If you're not yet experienced with the Linux ecosystem, cygwin could be easier.

VasyaNovikov

Posted 2015-11-07T02:39:33.720

Reputation: 2 329

Thank you for clarifying this. I've checked rsync, and it does the job on hard links indeed ( /cygwin/driveletter and slashes cause some discomfort but it works). – Estus Flask – 2015-11-17T02:26:03.553

note: if A is a directory, then B should be the name that directory will take on the target (unlike cp for example, where the last argument is the parent directory) – M.M – 2016-06-20T15:16:03.930

@estus - Which methods did you try, how did it work? and what did results did you see and like the most? – Alex S – 2019-05-02T11:04:23.730

@AlexS I don't remember but likely ended up with ln like shown in another answer. Cygwin rsync from this answer may work as well, as I mentioned. – Estus Flask – 2019-05-02T11:16:48.837

@estus - What method of LN did you end up using? I need to copy a Folder Tree structure with files that have hard links internally (to an external drive maintaining the size & links) and I'm wondering how to get it done. Seems like "Smart Copy" might be it but not sure? – Alex S – 2019-05-02T11:19:04.827

1@AlexS I used CLI utility, ln --copy. As for GUI, I assume that 'Smart Copy' is what you're looking for. – Estus Flask – 2019-05-02T11:23:35.320

@estus - I dont mind using either as long as it REPLICATES entire Folder Tree structure (having internal hard links) from Drive X to Drive Y - How much did you copy in terms of GB/TB and does it maintain Date/ Time stamps. – Alex S – 2019-05-02T11:28:09.173

@AlexS Less than TB. I don't think that quantity is the problem, as long as it works. It does what it was advertised for and preserves hard links. It seems that it didn't maintain creation date. Modification dates were ok. – Estus Flask – 2019-05-02T11:50:22.813

3

Try looking into rsync for windows. Since rsync has an option to preserve hardlinks (flag -H, --hard-links) it should do the job (source: https://download.samba.org/pub/rsync/rsync.html).

You could try looking into something like cwRsync: https://www.itefix.net/cwrsync# this one has GUI.

cwRsync is a packaging of Rsync for Windows with a client GUI. You can use cwRsync for fast remote file backup and synchronization.

Martynas Smilgevičius

Posted 2015-11-07T02:39:33.720

Reputation: 61

1

Please exercise caution when recommending software. As written, your answer may be seen as spam. Your answer should include a description of the software and how it addresses the question. More information: How do I recommend software in my answers?

– bwDraco – 2015-11-10T17:03:18.710

1I wasn't able to achieve this with rsync previously (I believe I have used DeltaCopy for GUI). It may be relevant to NTFS hard link implementation and the fact that rsync is primarily *nix tool. Some clarification would be appreciated. – Estus Flask – 2015-11-10T17:56:56.610

1

Very late to the party here.

Fight fire with fire. Since robocopy allowed the mess, then we'll use robocopy to clean it up as well.

Create an empty directory then use robocopy to copy the empty dir to the target (that has the super long paths) using the purge option.

md %temp%\foo
robocopy %temp%\foo target /purge
rd target
rd %temp%\foo

That should work.

Robert Ricketts

Posted 2015-11-07T02:39:33.720

Reputation: 11