Synchronizing 2 Ubuntu Systems with Unison

November 7, 2007
unison GTK+ screenshot

I recently got a laptop to use for web development work when I travel. I wanted a simple way to sync up the data between it and my Desktop computer so that they would both have the same bookmarks, emails, instant message logs, etc. Along comes unison to save the day. It ended up being MUCH easier than I expected.

Both computers are running Ubuntu 7.10 "Gutsy Gibbon" and are connected to my router--the Desktop is hard wired (Ethernet) and the laptop uses a WiFi connection. The desktop will be running an SSH server which will be used by Unison on the laptop to synchronize the folders of my choosing. The laptop will initialize the sync through a unison GUI: gtk-unison

  1. Configure Desktop Computer
  2. Configure Laptop Computer
  3. Synchronize Data

Configure Desktop Computer

The laptop will be connecting to the desktop over an SSH (secure shell) connection. Moreover, I'll be able to connect to the desktop from my laptop and browse/copy any files I need.

First, I changed the desktop computer's "Host Name" to something that makes sense in the 'Network Settings' dialog ('System' > 'Administration' > 'Network'). I used "Desktop".

Next, I installed the necessary software on the desktop:

sudo aptitude install openssh-server unison

Then, I configured the SSH server so that my user "micah" could log in over an SSH connection and that root login was NOT allowed. I did this by editing '/etc/ssh/sshd_config'. I changed:

AllowRootLogin yes
to:
AllowRootLogin no

And then I added:

AllowUsers micah

And finally, restarted the SSH service:

sudo /etc/init.d/ssh

The desktop computer already has all the data I need the computers to share. However, there is one "gotcha" for Mozilla products. They use a random folder name for you profile. I'm going to want this to be the same so that both computers versions of Firefox and Thunderbird share data.

For Firefox I renamed the profile folder in .mozilla/firefox to 'micah.default' and edited .mozilla/firefox/profiles.ini to reflect this change. I did the same thing in .mozilla-thunderbird/ for Thunderbird--my email client.

Configure Laptop Computer

On the laptop, I first installed all the software that will be sharing this data. For me, this was Firefox, Pidgin (formerly gaim), Thunderbird, MySQL Query Browser, and gFTP. Next, I renamed the profiles for Mozilla products as described in the previous section. Finally, I installed unison and it's graphical user interface:

sudo aptitude install unison unison-gtk

The unison program will now be available from 'Applications' > 'Internet' > 'Unison', however, we'll need to setup a profile to tell unison what to synchronize. We can do this with a profile file. I'm going to create one called "Desktop" by creating a text file in ~/.unison as follows:

mkdir ~/.unison
touch Desktop.prf
gedit Desktop.prf

There are numerous ways you can setup your profile. The easiest way would be to simply sync up the entire home folder, however, I have a LOT of data in my home directory and don't want it all synchronized. Furthermore, my desktop is an AMD64 architecture while my laptop is i386 which will cause problems with Firefox/Thunderbird if they share extensions and plugins. I need to share ONLY the data.

Here's my Desktop.prf file. The comments should let you know what's going on:

### ROOT SYNC PATHS ###

# first root is my home directory on this laptop
root = /home/micah/

# second directory is my desktop's home folder over SSH 
root = ssh://micah@192.168.1.2//home/micah/

### PATHS TO SYNCHRONIZE ###

# sync all of my email data (will ignore parts later)
path = .mozilla-thunderbird/micah.default/

# only sync up bookmarks for firefox
path = .mozilla/firefox/micah.default/bookmarks.html

# sync all gFTP for the bookmarks and cache
path = .gftp/

# gaim/pidgin IM client logs and settings
path = .purple/

# MySQL Query Browser information and history
path = .mysqlgui/

# Personal folders
path = finances/
path = websites/
path = projects/
path = robotics/
path = email_signature

### IGNORE RULES ###

# ignore archived backups
ignore = Path websites/archive/*

# ignore the extensions folder in thunderbird as they are architecture-specific
ignore = Path .mozilla-thunderbird/micah.default/extensions/*

# I don't think these will break anything, but let's ignore anyway
ignore = Path .mozilla-thunderbird/micah.default/compatibility.ini
ignore = Path .mozilla-thunderbird/micah.default/install.log

Synchronize Data

Now, I can run Unison and select my "Desktop" profile. I do this before leaving on a trip with my laptop and then again when I return.

Categories: Linux

21 Comments about "Synchronizing 2 Ubuntu Systems with Unison"

Peter Murray
May 24, 2010 at 04:43 AM
Hi Again,
Problem solved:

# sync up firefox
path = .mozilla/firefox/peter.default/
ignore = Path .mozilla/firefox/peter.default/Cache/*


works a treat, still don't know why the bookmarks are not in the html though
Peter Murray
May 24, 2010 at 04:39 AM
Excellent tutorial, I have it working, its something I have been after for a long time.

unfortunately I am having some trouble syncing my bookmarks, I have bookmarks.html in the list but non appear on the other machine after sync. in fact, when I edit bookmarks.html, there is no bookmarks stored in it, so I am completely confused, there is only one profile on my firefox so its not a mix up with that.

Here's my section for backing up firefox (I used AMD64 on both machines so I sync the extentions)
# sync up firefox
path = .mozilla/firefox/peter.default/bookmarks.html
path = .mozilla/firefox/peter.default/blocklist.xml
path = .mozilla/firefox/peter.default/adblockplus/
path = .mozilla/firefox/peter.default/extentions
path = .mozilla/firefox/peter.default/bookmarkbackups/


I did try using path = ./mozilla/firefox/peter.default/ but it kept updating the Cache folder,
and when I did ignore = Path ./mozilla/firefox/peter.default/Cache/ it still tried to update the Cache, any idea why it's ignoring my ignore?

many thanks
Christian
September 20, 2009 at 12:02 PM
For those who think ''AllowUser'' is alittle bit too unsecure, that can take a look at this site http://sial.org/howto/openssh/publickey-auth/ . It explains, howot setup ssh with public key and ssh-agent. This is a more secure way, especially if the desktop pc is in a non trusted network.
icyj
September 16, 2009 at 02:17 PM
Thanks!
Patrick
July 9, 2009 at 05:31 PM
@ Clark
I know its a little late but ssh options can be enabled using sshargs. I think you can even enable x11 forwarding (for some reason i do not know of). I got it to work by adding the following to my profile

sshargs -p 2222

This uses port 2222 on my server. Hope this helps!
Victor
May 14, 2009 at 03:23 PM
Great How-to, thanks!
One thing was missed - one has to open a port on the desktop (default is 22) to allow SSH requests to go through the firewall.
thomas willis
March 30, 2009 at 07:51 PM
How does this work syncing two computers using evolution instead of thunderbird? Has anyone tried?
March 11, 2009 at 10:20 AM
I want to migrate about 1 terabyte of data from Windows to Ubuntu. What is the best way to do this? rsync doesn't run natively on Windows. And it sounds like Unison isn't good on really large data sets like this.
Mr. Garrison
November 13, 2008 at 06:55 AM
I am interested in your article especially for a project I want to make. I would like to make a car pc using ubuntu also. I have my home pc as my server and would like my car pc to sync like an Ipod, with playlists of mp3s, pictures, and videos, over the internet. Your idea seems to be the closest I can come to what I want to do, but I would like to make this more automatic, everytime the car pc turns on to sync. Also, if i'm on the road and I download a new song or upload new pictures, I'd like the car pc to automaticly sync with the server and upload the new pictures. Do you think this is something you could help me with?

dagyrox@gmail.com

Thanks
Reinaldo
August 4, 2008 at 06:08 AM
Great article. I have a couple of questions.
First, is there a log kept somewhere of all the files transfered or updated?
Second, the files that are copied from the laptop to the desktop show up on the desktop with the current date. Is it possible to keep the date of the file as it was on the laptop (kind of cp -p mode).
thanks

Reinaldo
Paul
July 29, 2008 at 12:21 PM
I really do like this! Quick and easy and very effective. I have been wanting to do this but put it off, since I figured that it'd be complicated. Thanks to your article, I got it done in less than one hour! Thanks a lot!
July 4, 2008 at 11:40 PM
This is VERY good.

I swore I've read your article before and I swore I've been wanting to do this for ages but it took me too many mistakes (esp. with rsync) to finally getting to try this.

I think I won't be mistaken again. :)
clark
July 3, 2008 at 03:28 PM
Any ideas on using a non-standard ssh port?
Ryman
May 18, 2008 at 10:03 AM
Absolutely smashing.

One question, Is there any way of tricking it into syncing identical files/folders that have different paths on each machine?

My desktop runs on one partition. My laptop has a separate /home partition with a whole bunch of links to folders on another partition (music, video, documents etc). The links and folders have the same pathname visually but when a folder syncs over from the desktop it just overwrites the link in laptop /home.

Any ideas that don't involve moving the desktop's /home to its own partition?
February 26, 2008 at 08:35 AM
Great point. Yes, thunderbird keeps a mailbox in a single file. I make sure to use this before leaving and when I come back otherwise I'll have to make a decision which one to overwrite.
guilf
February 24, 2008 at 10:23 PM
Sorry, not Firefox, Thunderbird mail, I meant.
guilf
February 24, 2008 at 10:19 PM
Isn't Firefox mailbox data kept in a large file, rather than as individual "letter" files? And if so, wouldn't it be possible to cause a conflict if you worked with mail in both computers before syncing.
In other words, this is just usable for trips where you sync immediately on returning.

It would not be suitable for keeping a laptop at the office while commuting, and then occasionally syncing with your home computer on those occasions when you brought the laptop home.

Resolving a conflict or trying to merge those big files would seem to be a big problem if you ever made a mistake or had to use the wrong computer in an emergency. It would be far easier to sync if the individual emails were separate files.

Please correct me if this is wrong, or there is a workaround.

Thanks.
January 5, 2008 at 09:17 AM
"Crimson_Fox" Thanks, I have made the fix.
Crimson_Fox
January 5, 2008 at 03:06 AM
Great article BTW! Just what I was looking for in order to get my laptop and desktop synced up.
Crimson_Fox
January 5, 2008 at 02:41 AM
First step on "Configure Laptop Computer" reads:

sudo aptitude install unison gtk-unison

It should be:

sudo aptitude install unison unison-gtk
Thomas
November 17, 2007 at 03:23 PM
Not that it matters much, but you don't need a the 'touch Desktop.prf' step. You can open a non-existent file with gedit.

Leave a Comment about "Synchronizing 2 Ubuntu Systems with Unison"

Your Name:
(Required)
Website URL:
(Optional)
Comment:
(No HTML. Newlines and URLs okay.)
Enter CAPTCHA:
 
 
 
 
Share