Sync Firefox from the Command Line
March 6th, 2009 by Mitch Frazier in
There are lots of solutions for syncing Firefox, and I must confess I haven't used any of them. As I've read the descriptions, I've always gotten the sense that they wouldn't do what I wanted, the way I wanted it, when I wanted it. Necessity being the mother of invention, I wrote my own shell script to do what I needed.
I have Firefox running on four Linux systems and one Windows system, and all of them have the same extensions installed. My sync is a simple rsync of the Firefox settings directory from another system. This copies bookmarks and passwords, and I have used it for quite some time without any ill effects:
#!/bin/bash
user_name=mitch
if [[ ! "$1" ]]; then
echo "Usage: $0 FROM-HOST"
exit 1
fi
# Check for cygwin.
if [[ -d /cygdrive/c ]]; then
rpath=/home/$user_name/.mozilla/firefox/default.enr
lpath="$(find /cygdrive/c/Documents\ and\ Settings/$user_name/Application\ Data/Mozilla/Firefox/Profiles/ -iname '*.default')"
else
rpath=~/.mozilla
lpath=~/.mozilla
fi
rsync -av --delete --exclude=Cache --exclude=lock "$1":"$rpath/" "$lpath"
If you have Cygwin installed, the script will work from Windows systems also. Its usage is simple: first shut down Firefox, then invoke the script and give it a hostname or IP address to sync from:
$ syncff my-other-system
Obviously, you will need to modify the script to make sure that the paths it uses are valid for your installation.
One shortcoming is that this script will not work with a Cygwin system as the other system. That should be possible, but the script will need modifications and testing to accomplish it. When syncing Linux systems, I sync the entire .mozilla directory, which should probably work even if you use Seamonkey or have the Eclipse browser component installed, but test it to be sure, and shut them down before syncing also.
You may notice the rsync command excludes not only the Cache directory but a file named lock. If you don't exclude the lock file, Firefox will think that another instance is already running when it starts up.
__________________________Mitch Frazier is an Associate Editor for Linux Journal and the Web Editor for linuxjournal.com.
Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer
Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.
Subscribe now!
The Latest
Newsletter
Tech Tip Videos
- Nov-04-09
- Oct-29-09
- Oct-26-09
Recently Popular
From the Magazine
December 2009, #188
If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.
Delicious
Digg
StumbleUpon
Reddit
Facebook








Check out the plugin for
On March 12th, 2009 Sam M. (not verified) says:
Check out the plugin for firefox called foxmark. It will sync your bookmarks and optionally your login/password info up into the cloud where all your firefoxes can then push/pull from. It's completely secure. Check it out here: http://www.foxmarks.com/
Firefox sync
On March 12th, 2009 desQEDo (not verified) says:
Thanks for the confirmation Sam M.
See my 10 cents of the 8th and subsequent responses.
Excludes, rsync+Cygwin
On March 10th, 2009 RichS (not verified) says:
You should also exclude ".parentlock".
To have the Cygwin system as the remote system, you need to have rsync running as a daemon -- read the man page, but it's basically "rsync --daemon". (Linux boxes have xinetd to fire up insecure daemons when they're needed.)
It would be trivial to add a backup to this, and that's where version control comes in. For automation, RCS is sufficient. Of course, you'd need a restore script too.
To whoever "desQEDo" thinks he is, this is significant, because it's straightforward and it's scriptable. You can't run a UI application from cron. However, you can add a UI to a script. Sheesh.
Firefox
On March 11th, 2009 desQEDo (not verified) says:
OK, side-stepping the indignant response, and hoping it triggered more than that because I'm always very grateful for good and usable solutions. Just thinking a little further: if the scripts are so very trivial and significant, then could they not be developed the few steps further to create a solution, including UI, to help promote and further the usefulness of the operating system as a whole to a wider audience?
I don't pretend to be a command-line expert, my point was simply that there are so many good ideas out there, and here, in such tech fora that don't see the light of day although they may well be more useful than current solutions. Perhaps this one needs just a little more to become useful to more than the cron-ies who, although in the minority, are the only ones able to contribute useful code and in so doing support Linux advancement.
I love this OS, use it as far as possible, promote it whenever I can and point to the number and usefulness of the applications and also the generally helpful response of the community when looking for solutions. Sorry to spoil your fun. Sheesh indeed!
sync firefox
On March 8th, 2009 desQEDo (not verified) says:
Come on Mitch/Linux Journal, what is the real how-to value here considering the caveats mentioned? Whereas the command line may be interesting the exercise seems a bit of a waste of time and space when cross-platform utilities like Foxmarks/Xmarks are available for exactly the purpose outlined here. I use it and it just works.
Let's stop jerking around about how good we are with terminal and use this expertise to make the Linux world more useful and productive for real work - but maybe I missed the point...
Disappointed, and a reason why I cancelled my subscription...
Firefox
On March 8th, 2009 Adse (not verified) says:
That's worth trying. So simple why didn't I think of that? ...
:)
sync firefox
On March 6th, 2009 Bhaskar Chowdhury (not verified) says:
Hey Mitch,
Wonderful approach to it. I like the way you did it.
Thanks
Bhaskar
Version control
On March 6th, 2009 Brian11 (not verified) says:
I've recently started thinking you could do something like this with a version control system, like bzr or git. That might help get around some of the problems when using rsync.
Post new comment