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.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix