Using rsync to synchronise folders without overwriting files of same name on Mac OS X

3

2

I would like to synchronise the contents of two directories.

  • Without overwriting but to create a copy if two files have the same name, but different sizes
  • Without duplicating if two files have the same name and size.
  • To work recursively

So far I have found the following command which might work

 $ rsync -varE --progress ~/folder /volumes/server/folder

But I'm not entirely sure what the -E flag does. It was suggested by a user on bananica.com but couldn't see a description for it in the manual. Would this do what I require successfully?

Adam-E

Posted 2012-02-02T11:19:05.270

Reputation: 361

1From the manual page of rsync: -E, --executability preserve executability – Der Hochstapler – 2012-02-02T14:15:19.353

1

There's an interesting approach to use rsync to build similar functionality to Apples Time Machine. I have never used it, but maybe this is for you: http://blog.interlinked.org/tutorials/rsync_time_machine.html

– Der Hochstapler – 2012-02-02T14:17:56.167

Can you be specific as to why these rules are so. e.g. by 'having the same name and size' do you consider this as a test of whether the files are the same? And by 'same name but different size' does this refer to files that have changed? – Chris2048 – 2012-04-09T13:10:10.143

Same name, same size = files are identical; same name but different size = files have changed. Sometimes copying a folder without overwriting will create duplicates of identical files which I won't want. Note, I'm doing this on a mac. – Adam-E – 2012-04-11T10:49:53.807

Answers

5

-E actually preserves extended attributes on OS X, but -a (--archive) implies -p (--perms) which implies --executability.

-b (--backup) adds a tilde to the end of files that would normally get overwritten:

rsync -ab ~/folder /Volumes/server/

-b --suffix _old would rename file.txt to file.txt_old

rsync compares both file sizes and modification times by default. --size-only only compares sizes. -c compares checksums, but it's slower.

Lri

Posted 2012-02-02T11:19:05.270

Reputation: 34 501

Perfect. I just ran a test on this and is exactly what I was after. Many thanks. – Adam-E – 2013-03-28T09:52:42.450

@LauriRatna sorry forgot to ask, will this command skip the copying of identical files, thereby speeding up the process? – Adam-E – 2013-03-28T20:30:41.177

1Yeah. You can add -v to see what files it copies. – Lri – 2013-03-28T20:34:17.097