Is there a single cron command to keep 2 directories on different hosts mirrored or do I need to use 2 cron commands like I’m currently doing?
i.e. sshpass rsync server A to server B and vice versa
You would either need to setup a cron job (as you’ve suggested) which would be a little inefficient but not too bad (depends how critical that data is). Alternatively, this looks ideal for you.
Maybe consider something like SyncThing which is designed for exactly this use case - keeping stuff in sync across multiple computers. It’s similar to Dropbox except peer-to-peer, so no server is required.
If you do want to stick with rsync, using inotify to only run rsync when files are modified should work reasonably well.
Ive used syncthing in the past, but had some issues that made it an inviable solution. Inotify looks promising, I’ll definitely give that a try, thank you both for the suggestion
You want to do sync both ways? Forget about using inotify, you will end up with data corruption.
Another option I just discovered: Unison File Synchronizer
If at all possible, I’d recommend having a master copy, and making the second copy read-only. Two way syncing always has the possibility of conflicts, if the same file is edited at both ends at the same time.
Why do you not use something like GlusterFS?