A simple way to keep two drives in sync using rsync?
Solution 1
Yes, rsync running in both directions would be a (and probably the best) viable solution.
Solution 2
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.
Related videos on Youtube
Admin
Updated on September 17, 2022Comments
-
Admin over 1 year
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.
-
Pete TerMaat almost 15 yearsI was just about to suggest this as well. Another advantage is that it would run in one pass instead of two.
-
Alex F almost 15 yearsThanks, I will need to compile unison for my NAS, but this looks like a good solution.
-
Admin over 14 yearsYeah, 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!
-
Ryan C. Thompson over 14 yearsThe 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!) -
hafiz031 over 2 yearsDoes it work with more than two drives? Does it have any single point of failure in that case?