0

I have a large remote directory A and local directory B that are nearly identical in content, though many of the modification times may have changed by copying files etc. I want to create a local directory C with identical content to A, hard-linking to files in B whenever the content is the same. I don't care about getting the modification times the same.

Is this possible with rsync?

For a test case, I have the following local setup (I assume the behavior won't change when A is on a remote server):

[Compputer:/tmp] % cat A/a B/a
foo
foo

[Compputer:/tmp] % rsync -rIv --link-dest=$PWD/B/ /tmp/A/ /tmp/C  
building file list ... done
created directory /tmp/C
./
a
b

sent 169 bytes  received 71 bytes  480.00 bytes/sec
total size is 8  speedup is 0.03

[Compputer:/tmp] % ls -lT A B C
A:
total 16
-rw-r--r--  1 ken  wheel  4 May 28 00:01:15 2016 a
-rw-r--r--  1 ken  wheel  4 May 28 00:01:22 2016 b

B:
total 8
-rw-r--r--  1 ken  wheel  4 May 28 00:01:34 2016 a

C:
total 16
-rw-r--r--  1 ken  wheel  4 May 28 20:46:31 2016 a
-rw-r--r--  1 ken  wheel  4 May 28 20:46:31 2016 b

Notice that a isn't hardlinked.

1
  • Not sure whether this belongs on Stack Overflow or Super User better. By subject matter I'd think so, but there seem to be more rsync questions on Server Fault than the other sites. Please propose a move if appropriate. May 31, 2016 at 2:49

1 Answer 1

0

Found a solution: the -c switch requests that a checksum be compared for every file. That ignores the last-modified dates, and rsync (usually) detects identical files better (at the expense of reading every file in full, but still not needing to transfer over the network).

[Compputer:/tmp] % rsync -rcv --link-dest=$PWD/B/ A/ C
building file list ... done
created directory C
./
b

sent 150 bytes  received 48 bytes  396.00 bytes/sec
total size is 8  speedup is 0.04
[Compputer:/tmp] % ls -l A B C
A:
total 16
-rw-r--r--  1 ken  wheel  4 May 28 00:01 a
-rw-r--r--  1 ken  wheel  4 May 28 00:01 b

B:
total 8
-rw-r--r--  2 ken  wheel  4 May 28 00:01 a

C:
total 16
-rw-r--r--  2 ken  wheel  4 May 28 00:01 a
-rw-r--r--  1 ken  wheel  4 May 30 21:33 b

The 2 before the a files in B/ and C/ indicates that they are hard linked.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .