Tuesday, December 29, 2015

Sync Files Between Windows and Linux with Unison

I'd been using GoodSync to synchronize and backup all my important files on windows.  I was GoodSync to perform backups both locally and to remote machines.  I loved it.  It worked perfectly fine when both machines were windows based.  Now that I'm at least partially switched to Linux, Goodsync still works, but it's a command line tool that isn't quite as nice as it was before.

First I tried rsync.  That required a push and a pull command to get updates propagated both directions.  That's fine in one direction but once files get deleted, problems abound since you'd have to know the direction to propagate the deletion to specify the order of the push and pull.  I wanted something that could handle things a bit better.

My setup:  Linux (Ubuntu) as primary, Windows as remote

First Install ssh on windows.  OpenSSH should work fine but for some reason years ago I tried out Bitvise and stuck with it.  Either way, should be fine

Now download the binary for windows
http://unison-binaries.inria.fr/

and install unison on Linux
sudo apt-get install unison

make sure you can connect to the windows ssh - port forwarding could be required

ssh username@ipaddress
for those of us without dydns setup

Set up the unison binary:
I used the text version not the gui version.
Extract the zip

copy the executable somewhere (I made a folder C:/Users/UserName/Unison)

Add that folder to the path
System>Advanced Settings>Environmental Variables>Path
(something line ; pathtounisonfolder)  (don't forget the semicolon to denote a new entry)

I also renamed the executable to simply "unison.exe" so that I could invoke the keyword "unison" from command prompt.  You can check this now.

From Linux make sure unison can be invoked
ssh username@ipaddress unison -version
the result should match
unison -version
if it doesn't see about getting the same version of the software on both local and remote systems.

now setup a synchronization for instance syncing local (linux) dir1 to remote dir4
unison -auto ~/Desktop/dir1 ssh://username@ipaddress/Desktop/dir4

-auto so it doesn't require you to confirm that every single change exists.  It will still ask you to confirm before syncing...there's another command to make it just do it.

Lastly, if you need to access other harddrives on the remote machine, it can be done with symbolic links

for instance to make a link to My_Library on D drive ssh into the machine and
mklink /J C:\Users\UserName\Unison\My_Library D:\My_Library

/J for directory link
The first entry is the Location and name of the link and the second is the actual directory

now in unison use
unison -auto ~/media/mountpoint/My_Library ssh://username@ipaddress/Unison/My_Library

ignoring files can be done in the ~/.unison/default.prf file
ignore = Path _gsdata_
ignores my goodsync hidden files from before

that should be it!

https://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html#further

No comments: