I have a setup in which I sync files between two Linux servers using Unison over an SSH connection. This is implemented by running the following command via cron:
unison -auto -batch PROFILE
Changes to the fileset happen almost exclusively on one side (the other system is an off-site replica). They mostly take place through another Unison sync run (triggered manually) with a client machine, and can be from a few hours to a few weeks apart. Thus, conflicts between the two machine are not much of a concern in practice, and a delay of up to 24 hours for changes to get propagated to the other side is acceptable.
Reasons I am running Unison as a cron job rather than with -repeat
(presumably as a systemd service) are:
- Predictable sync times, as the cron job is scheduled at a time when I am not expecting any manual sync operations from the third machine (whereas, say,
-repeat 86400
would drift by the duration of the sync operation). - Changes mostly happen on server A, while the server-to-server sync job is triggered by server B (is it is easier network-wise if server B initiates the connection). Thus, as I understand,
-repeat watch
would not pick up most of the changes and even with-repeat watch+TIME
, I’d be relying onTIME
almost exclusively (correct me if I missed something).
When changes do happen, they are usually low in volume. Occasionally, however, the data volume to be transferred is such that a single Unison run lasts several times as long as the interval between two Unison cron jobs (bandwidth between the systems is somewhat constrained). That would mean one Unison process is still running when cron launches the next one on the same set of files.
I take it that Unison has lock mechanisms in place, which presumably prevent the “new” process from messing with anything the “old” one is working on (but correct me if I’m wring or have missed something). But I’m wondering what the second Unison process would do in that case – I have observed it does not exit but stays around. Does that mean the second process would wait for the first to finish and only then start synchronization (which would then only include files that changed while the first sync was in progress and therefore failed to sync on the first run)?
Is it safe to launch a second Unison process while another one is still running on the same profile? (If not, what is a recommended way to prevent two concurrent Unison instances if, and only if, they are at risk of interfering with each other?)
What about the resource overhead of unison -repeat wait+TIME
vs. occasionally having multiple Unison instances queued up, one running and the others waiting for it to finish?