Synchronizing folders between Linux & Windows using unison /--evilbitz
Hi there,
Here is a common case, you have a linux webserver and you want to update all the files, you probably work locally on the files and want to send th update to the server without the trouble of manually selecting the files and upload them via FTP.
We’ll use unison for this task and we’ll send the files over an ssh connection. Unison works very similar to rsync but is really easier for use. My Linux server runs on Debian.
Setting up the server (Linux)
- apt-get install unison
This will install the latest stable version of unison for debian, you can use yum if you’re using a Red Hat flavour of Linux. - apt-get install ssh
If it’s not already there
Setting up the client (Windows)
- Install the text version of unison for Windows, make sure you’re getting the same version as you installed on your server – it wouldn’t work otherwise!
Useful links: Download Page, Unison for windows – Version 2.27
Copy the unison-text.exe file to c:\windows\unison.exe - Install ssh client, download OpenSSH for windows and install the client.
Performing a sync
Let’s say you want to synchronize C:\www with /home/guy/www, you’ll have to execute the followin command (go to windows cmd):
C:\> unison www ssh://guy@webserver-ip//home/guy/www
This will synchronize all files between both directories, it will ask you for an action, you can include files or ignore them, just type ? and press enter to see all available options. Ok, what if you want to ignore a certain directory, which contains all kinds of sources for graphic files for instance… you can just include the -ignore switch, like this:
C:\> unison -ignore “Path sources” ssh://guy@webserver-ip//home/guy/www
In case you know you are doing a one way sync and you don’t want to be asked for too many questions, you may go with:
C:\> unison -silent -ignore “Path sources” ssh://guy@webserver-ip//home/guy/www
Making a mirror
This is really what fits best to our scenario, the files are on a windows machine will be the source of our mirror and the webserver directory the mirror itself:
C:\> unison c:\www ssh://guy@webserver-ip//home/guy/www -force c:\www -auto
The last command tells unison to force a mirror when c:\www is the source, and the destination address is /home/guy/www
Final word
Well, that’s it… simple, isn’t it? ![]()
In case you have questions, you can comment below…
Thanks,
Guy.
Posted in linux | Be The First To Comment!