4

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).

Thanks.

3 Answers3

8

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.

Mark
  • 2,856
  • 20
  • 13
  • 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. –  Jun 19 '09 at 19:41
  • Does it work with more than two drives? Does it have any single point of failure in that case? – hafiz031 Jan 16 '22 at 16:29
1

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

Matt Simmons
  • 20,396
  • 10
  • 68
  • 116
  • 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 07:09
-1

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! –  Jul 29 '09 at 20:30