Currently I have two directories A/ and B/ which are identical in every respect, with the exception of the timestamps. Therefore if I run the command :

rsync --dry-run -crvv A/ B/

then all files are marked "uptodate", whereas the command :

rsync --dry-run -rvv A/ B/

shows that all files are to be copied over from A/ to B/.

My question is this : given that I know the files are identical (in respect to contents), then is there any way (via rsync or otherwise) to set the timestamps for files in B/ to be identical to the timestamps of the files in A/, without copying over all the files from A/ to B/ ?

Thanks

link|improve this question

0% accept rate
If you know the files are identical, then why must you go out of your way to not copy over them to get the date/time stamp you require? – Tim Dec 28 '11 at 16:54
feedback

4 Answers

Well, you could certainly write a script that reads the timestamp from one side and then uses touch to set it on same file on the other side.

But that would likely take you much longer than simply letting rsync try to copy all the files. Very little data will actually be transferred (only block hashes if the files are truly identical). But the full contents of every file will have to be read on each side at the least. So of you are limited by disk bandwidth or IOPS it could take a while. But still probably less time than writing and testing a script to do it.

link|improve this answer
Thanks, I was unaware of this feature of rsync (it is discussed in wikipedia too). – artella Dec 28 '11 at 18:36
feedback

I think rsync is the right tool to make this but if you want some script to do this than someting this can give a good start.

You can get a file list with timestamps (acces times) like this:

find . -printf '"%p" %a\n' -type f > /tmp/times

And get the appropriate time update commands from it:

 while read line; do echo touch -a -d \"${line#* }\" ${line%% *}; done < /tmp/times

It isn't a complete script but a good start place!:)

link|improve this answer
Thanks. I think I will probably stick with Rsync for the moment, but I will definitely go out to the web and learn the different components of your script, as it may be useful in the future. – artella Dec 28 '11 at 18:38
feedback

The rsync manual: man rsync lists a -t and -N switch, they might be worth fiddling with.

link|improve this answer
feedback

Using --size-only will cause rsync to skip comparing file timestamps (and therefore file contents) if the sizes match. Combining this with --times will clone the timestamps across to the target tree.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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