4

I am trying to keep in sync three machines, on one of which I run unison to sync the other two. This 'star' architecture is advertised in the unison manual:

Using Unison to Synchronize More Than Two Machines

Unison is designed for synchronizing pairs of replicas. However, it is possible to use it to keep larger groups of machines in sync by performing multiple pairwise synchronizations.

If you need to do this, the most reliable way to set things up is to organize the machines into a “star topology,” with one machine designated as the “hub” and the rest as “spokes,” and with each spoke machine synchronizing only with the hub. The big advantage of the star topology is that it eliminates the possibility of confusing “spurious conflicts” arising from the fact that a separate archive is maintained by Unison for every pair of hosts that it synchronizes.

But, after initial sync with

unison -fat -batch "$HOME/dir" ssh://"$myhost1//dir"
unison -fat -batch "$HOME/dir" ssh://"$myhost2//dir"

for both hosts I always get the following error for one of them:

Fatal error: Internal error: On-disk archives are not identical.

This can happen when both machines have the same hostname.

If this is not the case and you get this message repeatedly, please: a) Send a bug report to [email protected] (you may need to join the group before you will be allowed to post). b) Move the archive files on each machine to some other directory (in case they may be useful for debugging). The archive files on this machine are in the directory /home/andreas/.unison and have names of the form arXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where the X's are a hexidecimal number . c) Run unison again to synchronize from scratch.

If I follow the instructions b), or if I run

unison -ignorearchives -fat "$HOME/dir" ssh://"$myhost1//dir" 

I sync this one successfully. But then snycing the other one will yield the same error above. It seems that whenever I sync one of them the other one will be in inconsistent state. How can I fix this, other than always adding -ignorearchives? Unison version is 2.40.102 from ubuntu packages and android Unison app.

4
  • Do you initiate both synchronizations from the 'hub' (centre) of the star? I don't do that; I initiate the synchronisations from the 'tips' of the star, the hub being a headless server (somewhere in Switzerland ;-) ). Do your problems persist if you initiate the synchronizations from $myhost1 and $myhost2 (presuming those are different from the hub)?
    – Edward
    Commented Feb 6, 2014 at 9:25
  • I thought about trying to reverse directions and now I definitely will. However it would be very inconvenient for me to do it permanently since the two 'tips' are small android devices. My backup script on the 'hub' contains logic to detect these devices in the local network and to connect them automatically. Then I would also need to look at diffs on the androids. Is there maybe a command line option which reverses the sync direction if there is a dependence on it?
    – highsciguy
    Commented Feb 6, 2014 at 11:09
  • I can add that, if I try the obvious - to reverse the directories in the command, i.e. unison -fat ssh://"$myhost1//dir" "$HOME/dir" etc. the same issue occurs.
    – highsciguy
    Commented Feb 6, 2014 at 11:59
  • 1
    Trying to sync from one of the android devices I found that it fails repeatedly with Uncaught unix error: read failed: Try again, so this does not seem to be an option for me either.
    – highsciguy
    Commented Feb 6, 2014 at 12:25

2 Answers 2

8

It turns out that the 'fatal error' message is more appropriate than I thought. The origin of the trouble (which would in a two-machines setup occur if a host changes its name) is that the two Android devices to sync with host names were both determined to be localhost, even though they are different and specified by different IP-addresses.

According to the unison manual the hostname can be given by hand by exporting the UNISONLOCALHOSTNAME environment variable. Since unison does not create a login shell however it cannot be exported in the .profile file on the sync devices. It turned out that also the ./ssh/environment file of my ssh servers (SshDroid in both cases) was not read. Finally the android hostname (which can be set with setprop net.hostname [hostname]) is also not read by unison. Instead it seems to default to localhost.

Therefore I came up with the following workaround:

unison -servercmd "export UNISONLOCALHOSTNAME=host1; unison" ssh://"$myhost1//dir" "$HOME/dir" 
unison -servercmd "export UNISONLOCALHOSTNAME=host2; unison" ssh://"$myhost2//dir" "$HOME/dir" 

Here the -servercmd option defines which command to run on the remote devices to start unison. In my version it exports the UNISONLOCALHOSTNAME to two different values first.

Then the hosts are recognized to be different and it is possible to repeatedly sync multiple 'tips' from a central 'hub' in a 'star' setup.

2
  • +1 for your research; I didn't actually know it was feasible to do unison on android; have to have a look at that ;-)
    – Edward
    Commented Feb 10, 2014 at 10:20
  • It's new. Search for unison in Google PlayStore. I assumed that you have an ssh-server and busybox. Then the basic free app is sufficient. You need to create a symbolic link to the binary in your path too.
    – highsciguy
    Commented Feb 10, 2014 at 10:36
1

I had exactly the same problem as the OP. I am syncing the "Books" directory on the (internal) sdcard of two android devices with a master folder on my PC. I was using SimpleSSHD on android which runs a dropbear server and appears to have no way to set environment variables for sessions that don't read .profile.

My first "solution" was a complete hack: I sync'ed /storage/emulated/0/Books on one device and /sdcard/Books on the other device.

Now I use termux on my android devices. In termux, one can install openssh and termux's sshd honors the SetEnv directive in sshd_config just fine. Just add the line:

SetEnv UNISONLOCALHOSTNAME=tablet

to the $PREFIX/etc/ssh/sshd_config file (change hostname after the = as appropriate). I also install Termux:Boot on my devices and configure so the sshd server is started automatically.

N.B. I use the unison binary at: https://github.com/vovcacik/unison-build-scripts/raw/master/binaries/2.48.4/linux-x86_64/unison. 32-bit binaries from other packages can also be used if they are wrapped in a script that unset's LD_PRELOAD.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .