Question on sync 2 folders with checking files' modify date

Hi Linux Community

I would like to ask about how to compare files in deferent server with date.
Those A and B servers has the same folder, I have write a sample script to "ls" both folders and "diff" them, and then "rsync" the missing files.
It was running well, both A and B are sync, until one day someone updated/modified a file on A, my sample script cannot detect it and havnt sync it to B.

Is there anyway to sync folders with file modify date between 2 servers?

Thanks.

That is what rsync does by default (check on mod-time + size, -c option causes checksum verification).

There are a number of options to control features like remove files on dest that don't exist on source and the like.

Hi Chubler_XL

Thanks for the reply, but do you mean "rsync" the hold folder?

Because there are many files in the folder, directly "rsync" the hold folder would take a long time, and the problem is, sometimes user will update on A, sometimes user will update on B, sorry I havnt mention this.

---------- Post updated at 01:06 PM ---------- Previous update was at 01:02 PM ----------

I tried " if [ file1 -nt root@B:file2 ]; then ", but the result is not good, it can't detect which one is new.
seems this method can only compare 2 local files, but not remotely...