Synchronizing 2 Ubuntu Systems with Unison
November 7th, 2007I 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
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.
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
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
Popular Posts
RSS Feeds
Archives
November 17th, 2007 at 3: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.
January 5th, 2008 at 2:41 am
First step on "Configure Laptop Computer" reads:
sudo aptitude install unison gtk-unison
It should be:
sudo aptitude install unison unison-gtk
January 5th, 2008 at 3:06 am
Great article BTW! Just what I was looking for in order to get my laptop and desktop synced up.
January 5th, 2008 at 9:17 am
"Crimson_Fox" Thanks, I have made the fix.
February 19th, 2008 at 4:41 am
[...] Configure Desktop Computer [...]
February 24th, 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.
February 24th, 2008 at 10:23 pm
Sorry, not Firefox, Thunderbird mail, I meant.
February 26th, 2008 at 8: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.
May 18th, 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?
July 3rd, 2008 at 3:28 pm
Any ideas on using a non-standard ssh port?
July 4th, 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. :)
July 29th, 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!
August 4th, 2008 at 6: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
November 13th, 2008 at 6: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
December 1st, 2008 at 5:04 pm
[...] Synchronizing 2 Ubuntu Systems with Unison 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 (tags: linux rsync sync ubuntu unison synchronize) [...]
January 15th, 2009 at 1:48 am
[...] synchronize two computers using this wonderful program called Unison. For more info take a look at this site. I use this method to sync together my firefox bookmarked pages and my sunbird calendar. As was [...]
March 11th, 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.
March 30th, 2009 at 7:51 pm
How does this work syncing two computers using evolution instead of thunderbird? Has anyone tried?
May 14th, 2009 at 3: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.
July 9th, 2009 at 5: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!
September 16th, 2009 at 2:17 pm
Thanks!
September 20th, 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.