8

With rsync command I want only copy/sync changed files/folder to the destination folder. I had some issue with Rsync-like whenever am executing the rsync command am copied along with the time stamp as well.

For example, my destination folder ‘Linux’ had updated on 1 month back and in my source folder there is no update info for the 'Linux' folder, but when am performing the rsync command my destination 'Linux' folder time stamp has been updated with latest source folder time stamp. I don’t want to copy the timestamp. please suggest me on this and please glance on below command which I have used.

rsync -avh /source/Linux/ /destination/Linux/ 

rsync -uan /source/Linux/ /destination/Linux/

rsync -uav /source/Linux/ /destination/Linux/
1
  • 6
    You do want to copy the timestamps, these will be used when you run rsync next time to find out what has changed. The alternative is to use checksums, which are much slower. Jul 13, 2016 at 14:55

2 Answers 2

10

The -a option (--archive) implies the -t option (--times, "preserve modification times").

You may negate this option using either --no-t or --no-times after -a:

rsync -a --no-t /source/Linux/ /destination/Linux/

This would not copy the source timestamps to the destination. Note though, that rsync compares timestamps (and other metadata) to determine whether files are updated and needs copying. You may therefore want to use -u (--update) too.

3
  • Thanks for your response Kusalananda. I have already tried like- rsync -rlpgoD /source/Linux/ /destination/Linux/. Actually -a represent -rlptgoD so on this I have eliminated the 't' option and tried but no luck.
    – Raja
    Jul 13, 2016 at 11:39
  • rsync -rlvi sets all the file modification timestamps to now.. I think the goal was to not change them at all.
    – adfaklsdjf
    Jun 12, 2019 at 13:48
  • 1
    @adfaklsdjf Note that "not copying the remote timestamps" is not the same as "preserving the timestamps locally". My answer concerns "not copying the remote timestamps", as this is what the user asks about.
    – Kusalananda
    Feb 21, 2020 at 14:44
0

In general, you should copy the timestamps, because this allows rsync to run more efficiently in future.

But there may be times when you really don't want to keep the timestamps in sync. For example, git keeps changing the timestamps on your files, but when you run rsync you don't want to see these timestamps being transferred, you only want to see the files which have really changed.

--no-times will avoid copying the timestamp, but if a file is updated, the target file will have its modification time set to now. That means the timestamps will now differ, so the next rsync will think an update is needed, and will send it again!

To avoid this, --ignore-times will not help, because it causes all files to be updated.

What you can do is use --checksum, which is hard work for rsync, but it will do what you want: it will ignore the timestamps, and only update a file if its actual contents have changed.

So you might like to use a command like this:

rsync -i -a --no-times --checksum /source/Linux/ /destination/Linux

Alternative approach

If you want to keep rsync efficient, then you should keep the timestamps in sync.

But if you don't want to see updates which are only timestamp changes, then you can hide these from the output:

rsync -ai /source/Linux/ /destination/Linux |
grep --line-buffered -v '^.[fd]\.\.t\.\.\.\.\.\. '

Please note that if you take this approach, you will get grep's exit code, instead of rsync's! So this may not be suitable for scripting, because the exit code may be misleading. You can work around that using pipefail or PIPESTATUS.

In the end, I used this:

rsync_ai_with_quiet_timestamps() {
  # This will not send timestamps, and not check timestamps, but it is slow
  #rsync -a --no-times --checksum -i "$@"

  # This will send timestamps, but hide updates which are only timestamp changes
  (
    set +e
    rsync -ai "$@" |
    grep --line-buffered -v '^.[fd][.][.]t[.][.][.][.][.][.] '
    exit "${PIPESTATUS[0]}"
  )
}

...

rsync_ai_with_quiet_timestamps /source/Linux/ /destination/Linux

You must log in to answer this question.

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