This is my current situation (simplified, in fact of course many and large files):

Dir1/
  a b c
Dir2/
  a b c d

This has happened before:

  • a b c were copied from Dir1 to Dir2.
  • Within Dir2 the timestamps of a b c got modified accidentally.
  • d got added to Dir2 intentionally.

Now I want to do this: Sync Dir2 back to Dir1. (To whom it concerns: I use rsync)

  • d is new and hence should get copied.
  • a b c in Dir2 and Dir1 are identical in size and data content, but their filestamps differ. Hence they would be unnecessarily copied.

I know that rsync can either compare files by --checksum or --size-only. But this disk/cpu intensive check would have to be repeated in every future sync. Instead I rather want to once and for all correct my mistake by restoring the original file timestamps from those in Dir1 to those in Dir2 with a tool. Then my mistake is corrected, and future syncs can run efficiently.

On Windows these tools are able to copy timestamps only (without copying data):

Does anyone know an appropriate CLI / GUI tool for Mac OS X?

link|improve this question
As mentioned, in the past I already accomplished exactly this task on Windows. I am now curious wether such a tool exists for Mac OS X! Else I will simply (wastefully) copy all data instead of filesystem metadata only. – porg Aug 27 '11 at 21:20
feedback

2 Answers

Is it possible that the timestamps aren't important for you? It isn't clear from the question if you are more interested in preserving them or in doing rsyncs without having to copy all that data. If you don't care about the timestamps you can use the touch command to set a specific date on all the files on both machines so they are the same. Something like:

find dirX -type f -print | xargs touch -t 201108250000

Then running the rsync should work without having to worry as the timestamps will be the same on both boxes. I am not near my OS X box to test if this works but I have done this in Linux before.

link|improve this answer
I had this idea too. But thanks no, I really want the original timestamps back, without re-copying (unnecessarily!). – porg Aug 26 '11 at 22:07
feedback

The --size-only flag in rsync is neither CPU nor disk intensive compared to the standard rsync check, in fact it is faster because normally rsync will check both the file size AND the timestamp. You could use the touch command to explicitly match up the timestamps on abc in Dir2. You could delete the files in dir2 and rsync again. These suggestions are great if it's a ton of files so you could wrap them in a script or find. Note that if you just run rsync again, in a typical mode but with the --partial optinoal as well (say rsync -az --partial Dir1 Dir2) it will not copy the files over again, instead it will try to intelligently synchronize them which would I believe would end up transfering over just the timestamps in this case.

link|improve this answer
Thanks for the good idea, but sadly rsync with --partial in a local send/receive situation (no network involved) does not result in an intelligent transfer (metadata only) but rather does a complete data transfer. Additionally I tried both with and without --compress. It changed nothing. So rsync seems not to be the "transfer metadata only" tool on Mac OS X, that I am looking for. – porg Aug 28 '11 at 12:20
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.