Unison File Synchronizer
cis.upenn.edu
cis.upenn.edu
> Further improvements to the OS X GUI (thanks to Alan Schmitt and Craig Federighi).
Here are Craig's commits:
- https://github.com/bcpierce00/unison/commit/48f8e1b27edbe2df...
- https://github.com/bcpierce00/unison/commit/6645d1793ce843f6...
Around the same time, Dave Abrahams, now of Apple's Swift team, makes an appearance on the unison-hackers mailing list.
I'd be really happy to receive feedback if you have a chance to try it out!
You can also orchestrate your setup a bit (e.g. to work with Docker Compose) using Mutagen's new orchestration infrastructure. You can find an example of this at the bottom of the Mutagen homepage: https://mutagen.io
I use Syncthing now. It's really useful.
I reluctantly installed Dropbox one day after forgetting my external drive at home. Honestly, that was the beginning of a miserable time. Dropbox never really delivered, it took forever to sync, and constantly caused the internal disk to trash. I had tons of other problems with Dropbox over the years and was very happy the day I quit using it.
I still have a unison alias in my .profile
alias unison="unison -logfile /Users/eddie/log/unison.log"
I really miss the control Unison gave me.(That said, one of the problems I encountered with Syncthing seemed to be that it wouldn’t properly reconnect when I switched networks, which is necessary since it runs as a persistent daemon. With Unison, so far I’ve been starting it up in the foreground in a terminal as needed, so it hasn’t had to provide the same functionality. But I expect I’ll eventually set up some type of auto-reconnect, which will hopefully work better than Syncthing did.)
Of course I've not tried it in a while because of those issues so it could be fixed now.
When go to another country, open my laptop, connect to a wireless network and bam. Syncthing connects, things got synced automagically.
Not C but not super powerful seems like the worst of both worlds.
Enable your android phone's hotspot, and connect your laptop to that hotspot.
Install termux on android (playstore). Install openssh in termux. Setup passwordless pub/private keys to log in from laptop to android termux sshd.
cat ~/.ssh/config # Laptop.
Host someName # Your android.
User u0_a168 # Whatever username termux gave you.
HostName 192.168.43.1 # 'ifconfig' in termux for this.
IdentityFile /home/you/.ssh/someName_id_rsa
Port 8022 # Default termux sshd port.
Now this should work from your laptop: ssh someName
Log out of your laptop's termux session.Install sshfs on your laptop, through your package manager or the manly way from github. I'm not manly.
Here's part of a script I use to get photos from my phone to my laptop.
# Mount the phone's DCIM directory locally over ssh.
# I had trouble with termux symlinks, so I went directly to /storage/...
sshfs someName:/storage/emulated/0/DCIM ~/mnt/someName
cd ~/mnt/someName/Camera
cp -vn * ~/Pictures/. # Copy all pictures that aren't yet on laptop.
mv * ../Saved/. # So ops on dcim/Camera don't take longer with more pics.
cd ~/Pictures # Can't unmount until leave mount.
fusermount -u ~/mnt/someName # Dismount. Gymnastic salute.
# Do whatever postprocessing you like on your photos ...
https://wiki.termux.com/wiki/Main_Pagehttps://wiki.termux.com/wiki/Remote_Access
https://wiki.termux.com/wiki/Internal_and_external_storage
https://en.wikipedia.org/wiki/SSHFS
man sshfs
stackoverflow
In Fedora (and I think this applies in Debian too) we have to maintain 3 versions because Unison isn't interoperable across minor releases. For this reason we package 2.13, 2.27 and 2.40, and I think there is discussion about packaging the latest release too. Keeping these ancient (esp 2.13) versions going is a pain to say the least.
Ouch! FWIW, Thanks for all your work.
But you package for Fedora, which is "upstream" for RHEL (if I'm not mistaken) with their 10 year life cycles, so I'm sure RHEL customers would love you to keep as many versions available as possible :)
The last straw came when it turns out that unison was incompatible with the same version, if that version had been built on a different system. I can't remember the details but there was some library version difference that results in a unison that has the same version number but wouldn't talk to one from another system without crashing.
Drove me crazy.
Oh, so OCaml is a toy language from academics. I've read so many good things about it over the years, but no one mentioned that aspect of it. There should be a law about putting a warning in Big Red Letters on the box so someone doesn't make the mistake of using it in a large, long lived project.
What? Why did you conclude so?
> but no one mentioned that aspect of it.
Really? Did you open the documentation? It's stated explicitly.
https://caml.inria.fr/pub/docs/manual-ocaml/libref/Marshal.h...
> There should be a law about putting a warning in Big Red Letters on the box so someone doesn't make the mistake of using it in a large, long lived project.
It's documented, and it's not intended to be used for serialization, you use it in very particular cases, for example for faster object sharing with IPC for multicore. We use Json or S-expressions or other stuff for that purposes.
I really don't know why unison people don't switch to a proper serialization.
On Fedora I'm using unison251-text from the croadfeldt/Unison COPR. On Gentoo it's net-misc/unison-2.51.2, on FreeBSD it's unison-nox11-2.51.2 from pkg.
My use-case is that I run Unison on two computers running Fedora, to implement a form of "sneakernet" file sync. Work computer <-> usb thumb drive <-> home computer.
I wasn't aware that the exact version of Unison was so important. Will start paying attention to that.
Unison was the first backup binary that we built into the rsync.net platform - breaking our original design goal of only offering client agnostic SSH and the tools that would run over that.
Shortly afterward we also added rdiff-backup. Both of these tools were quite popular and we saw a lot of interest back in 2005 - 2010 but we see very little use or interest in them now.
All of the interest in backup clients is now in rclone[1], restic[2] and borg[3].
restic was easy - you can point it at any SFTP capable host.
borg and rclone, on the other hand, we had to (like unison and rdiff-backup) build and maintain on the rsync.net server side.
All of these (save rclone, which is a binary executable) are python scripts. But we don't have a python interpreter (or any interpreter) in our very locked down platform. Can anyone guess how we do that ?
[1] https://github.com/rclone/rclone/issues/3254
Like you did with attic and borg? Quoting you on January 2016:
> We solved the problem by (cx)freezing the attic and borg python tools into binary executables. So, still no python in our environment (reducing attack surface) but the ability to run attic and borg just like they are meant to be run.
As seen here: https://news.ycombinator.com/item?id=10925123
Also, open source but non free license but duplicacy, in my opinion is technically superior to restic.
But Unison is for syncing, which means maintaining eventually consistent replicas of a changing directory tree (up to some pragmatic exceptions and manual tweaks). The whole point of Unison is to turn multiple devices into a single failure domain, which requires a separate system for storing safe backups.
The problem with trying to edit these files was that everyone logged in on the network had access to them and could change them arbitrarily. Or they could even just inadvertently lock the files if they left them open on their PCs. There was no control or change management.
I decided to keep the 'canonical' versions of the files on my PC at work and use Unison to sync them over to the shared network versions of the files once a day. Unison would instantly tell me if anyone other than me had changed the files, and I could investigate further. It was a huge relief knowing that I had proper control over those files.
[0] https://wiki.archlinux.org/index.php/Unison#Version_incompat... , https://groups.yahoo.com/neo/groups/unison-users/conversatio...
Something I love about Unison is the fact that I can sync files from anywhere on my filesystem without having to move them or replace them with symlinks.
I can also sync subsets of my files by defining multiple profiles. I have Unison set up to default to a "common" profile that includes nearly everything, but I can explicitly request a sub-profile if I want. I also have a separate profile that syncs the profiles themselves, so I can make profile changes on one machine and run `unison profiles` to upload them.
I often evaluate a wide range of software before choosing what I consider best for a job, and many years ago, Unison came out way ahead in such an evaluation. It never failed me.
There is one issue that I have run into though. If I format the USB as fat32 it can't properly store permissions. And if I format it as ext4 then I need to make sure that my numeric user ID is exactly the same in both my home and work computers (otherwise the permissions get messed up).
Is there a way to make my arrangement more robust so that I can sync files through and USB drive, without needing to use the same numeric user id in all my computers?
$ chown -Rf ufo.users /media/usbdrive && unison
A hint regarding running the latest Mac binary on Mojave: if the GUI crashes on you, it's likely to be an issue regarding syncing file _permissions_ and not just files.
This has been biting me for a couple of months now whenever I sync my development tree between Dropbox and OneDrive, since Windows' WSL tends to set wonky 0x777 permissions on entire file trees, and it is usually those that cause Unison to crash.
Otherwise, I've been using it to sync 400K+ files without incident.
- Unison is written in OCaml, which is (probably) a perfectly fine language but not commonly used
- Unison synchronizes files to files, but for a Dropbox-like system you really want deduplication for space savings (i.e. server-side storage is a bunch of pointers to content-addressed blocks.)
- in general, it's not clear to me that the client is really the hard part of Dropbox. Note e.g. the part where Dropbox now runs its own data centers for cost reasons.
- there's a million fiddly things to get right, and Unison hasn't had that much usage
The whole point of Unison is that you do not need a server. And certainly not a server run by a for-profit corporation in the United States of Surveillance.
I agree it doesn't have to be a corporate-owned, or even corporate-snoopable "cloud" server, and if this is your goal then unison will work well. Also you can trivially solve the dedup using zfs, but I don't think dedup is a killer feature for personal storage.
(Better would be a "manual dedup" utility to catch those instances where you copied off the same thing multiple times over the years. I'd appreciate any recommendations here, although writing one seems trivial when I get around to it - calculate recursive sha256sums for every node in the filesystem tree, and look for the biggest matching ones)
You do not need a spanning tree or loops, you just need to do a topological sort on the nodes/disks and then consistently sync them in that order. There is no magic algorithm that will handle conflict resolution for arbitrary syncing.
Create file F on A. Sync A-B, A-C. Delete F on A. Sync A-B. ?????. Sync B-C. Sync A-B. File F now re-exists on A (and B and C).
??? is some event where you cannot sync A-C to directly save A's changes on C, yet you still want to save any changes from B on C. Say a remote machine crashes and becomes unavailable, you didn't have the time over 3G, or some other type of ad-hoc craziness which is why you're using distributed syncing in the first place.
Which implies you need to choose one node from {A,B,C} that is the most likely to be available to sync the other two to. That node can also provide connectivity to a larger network, which generalizes to a spanning tree.
IMO a topological sort would be an even stricter requirement than spanning tree, in that if one node becomes available, you can't sync anything "below" it! Also what does syncing disks "in order" mean when changes can happen at any time? (eg I use unison for maildir).
That is conflict resolution, over the set of files. Which is why Unison provides the "reconciling changes" UI.
> Which implies you need to choose one node from {A,B,C} that is the most likely to be available to sync the other two to.
Yes, that is a way to avoid update conflicts.
> IMO a topological sort would be an even stricter requirement than spanning tree, in that if one node becomes available, you can't sync anything "below" it!
Yes, it is also a way to avoid update conflicts.
> (eg I use unison for maildir).
Why? IMAP already takes care of synchronization, without any potential problems.
> Why? IMAP already takes care of synchronization, without any potential problems.
Less configuration, less attack surface. Sharing mail over NFS is a common thing, and I view unison as a type of distributed filesystem.
Unison is the only bidirectional sync tool that I trust to get the details right. It is backed by a formal model with various proofs of correctness. Such models are also easily representated in OCaml; which I can assure you is more than a fine language, especially if one cares about correctness. Dropbox has struggled to get these details correct in the past (see the paper "Mysteries of DropBox", by Unison's author Professor Benjamin Pierce). TLDR, Pierce teaches these Python hackers how to fix their broken code.
That's just about the sync process/stages, the easy part that can actually be formalized.
The "million fiddly things" are about OS and filesystem issues, incompatibilities, and so on, and Dropbox has a hugely larger test base for those things...
The issues and subtleties are with bidirectional sync. It is not "the easy part". Dropbox didn't get it right in the past, we have no proof they have it right now.
I know nothing about POSIX, but I presume we all want stronger guarantees to avoid the risk of syncing a corrupted file.
First of all, POSIX semantics are not what Windows support. Second, even where available, POSIX is a tiny part of the possible issues. Adequate for naive apps that need to open or write some files, not for a reliable sync tool.
A long time ago used unison to keep file uploads on 2x primary web servers[1] in sync. It worked like a charm. With IIS on Windows!