I have an external USB drive, which I plug into a Linux NAS. I want to keep specific folders synchronised, so changes to files in FolderA on the NAS are applied to FolderA on the USB drive, and vice-versa.

Would an appropriate solution be to run an rsync command twice, i.e. once to sync NAS to USB and then again to sync USB to NAS, e.g. as follows:

# sync NAS to USB
rsync -av --stats /share/FolderA/ /share/USBDisk1/FolderA/

# sync USB to NAS
rsync -av --stats /share/USBDisk1/FolderA/ /share/FolderA/

I'd like the process to only update/add (no deletes, just to be safe), and to be as efficient as possible.

NB: I'll be running the commands as Cron job(s).



Yes, rsync running in both directions would be a (and probably the best) viable solution.

  • The problem with this is that depending on which way you synchronize first, one or the other folders will take precedence when the same file has changed on both ends. If that's ok with you, then go for it. But even then unison might be faster, since it only has to run once instead of twice (Warning: hypothesis based on zero evidence!) – Ryan C. Thompson Oct 31 '09 at 7:09

You may also want to look into something like Unison. It's designed to do exactly what you want and will let you know if a file has been updated on both drives, whereas the rsync method will just clobber the file on the the USB disk.

  • 1
    I was just about to suggest this as well. Another advantage is that it would run in one pass instead of two. – Pete TerMaat Jun 19 '09 at 14:27
  • Thanks, I will need to compile unison for my NAS, but this looks like a good solution. – user10097 Jun 19 '09 at 19:41

How can you ever delete something on /FolderA/ ? Next run the files are back from /USBDisk1/FolderA/ So.... How do you keep control of removing old files?

  • Yeah, good question! I don't have a solution to this. I also want to be able to rename files, which is essentially the same problem. Any ideas welcome! – user10097 Jul 29 '09 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy