Previous: Ubuntu 7.10 “Gutsy Gibbon” on a Dell Lattitude D830
Next: Gedit Symbol Browser Plugin

Synchronizing 2 Ubuntu Systems with Unison

November 7th, 2007

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.

unison GTK+ screenshot



Categories
Linux

Related Posts


Technorati Tags

9 Responses to “Synchronizing 2 Ubuntu Systems with Unison”

RSS Subscription Comments RSS Feed

  1. Thomas Says:

    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.

  2. Crimson_Fox Says:

    First step on "Configure Laptop Computer" reads:

    sudo aptitude install unison gtk-unison

    It should be:

    sudo aptitude install unison unison-gtk

  3. Crimson_Fox Says:

    Great article BTW! Just what I was looking for in order to get my laptop and desktop synced up.

  4. Micah Says:

    "Crimson_Fox" Thanks, I have made the fix.

  5. Linux T&T » Synchronizing 2 Ubuntu Systems with Unison Says:

    [...] Configure Desktop Computer [...]

  6. guilf Says:

    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.

  7. guilf Says:

    Sorry, not Firefox, Thunderbird mail, I meant.

  8. Micah Says:

    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.

  9. Ryman Says:

    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?

Leave a Reply