Synchronizing 2 Ubuntu Systems with Unison
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
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 yesto:
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.
21 Comments about "Synchronizing 2 Ubuntu Systems with Unison"
RSS Feed
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
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
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!
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.
dagyrox@gmail.com
Thanks
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
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. :)
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?
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.
sudo aptitude install unison gtk-unison
It should be:
sudo aptitude install unison unison-gtk
Leave a Comment about "Synchronizing 2 Ubuntu Systems with Unison"