Sync Firefox from the Command Line

 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.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Check out the plugin for

Sam M.'s picture

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

desQEDo's picture

Thanks for the confirmation Sam M.
See my 10 cents of the 8th and subsequent responses.

Excludes, rsync+Cygwin

RichS's picture

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

desQEDo's picture

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

desQEDo's picture

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

Adse's picture

That's worth trying. So simple why didn't I think of that? ...
:)

sync firefox

Bhaskar Chowdhury's picture

Hey Mitch,

Wonderful approach to it. I like the way you did it.

Thanks
Bhaskar

Version control

Brian11's picture

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.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState