How to backup Firefox to recover a potentially lost session

0


If you’ve ever lost all of your pinned and open tabs in Firefox, you know how frustrating it can be. Jack Wallen shows you how he saves his session to recover the tabs from the previous instance.

Image: Mozilla

Here’s how my Firefox web browser workflow goes.

Every morning, when I’m ready to start my first writing session, I log into my desktop PC and launch Firefox. When the browser opens, it starts from my previous session (with all my tabs pinned and other tabs I might have opened for search). I write and I write and I write. This continues throughout the day. When it comes time to turn off the lights in my office, I close Firefox (because I’m using the Nightly version and want to apply the latest additions the next morning) and say goodnight.

SEE: Checklist: Server Inventory (TechRepublic Premium)

The next day, I start again.

I rarely miss this workflow.

But occasionally it does. You see, Firefox is set to restore the previous session (in settings), so it always picks up where I left off. This is where it can become problematic. Say, for example, I forget I had a second Firefox window open with only one tab. If I don’t close this secondary window first when I reopen Firefox the next day, it will remember the state it was in when it was last closed. If I close this single window last … you see where it leads.

So what do I do?

One way to avoid such frustration is to regularly back up a specific directory that hosts the session state. It’s not 100% foolproof, but it has helped me in the past.

I’ll show you how to do just that. I’ll do the demonstration on Linux, but it can also be done on macOS and Windows (just adjust the directories and tools used).

What you will need

All you will need is a running instance of Firefox. That’s it. Let’s get to work.

How to locate your Firefox profile directory

The first thing we need to do is locate our Firefox profile directory. To do this, open Firefox and type about: support in the address bar. In the resulting window (Figure A), find the Profile Directory line.

Figure A

firefoxrecovera.jpg

This page gives you more information about Firefox than you’ve probably ever needed.

Your profile directory will be in /home/USER/.mozilla/firefox/STRING.default.

Where USER is your Linux username and STRING is a random string.

Copy this full path.

How to create the backup in Firefox

What we’re going to do is use cron to create a daily backup that will happen before Firefox closes at the end of the day. Suppose, for example, that you close Firefox at 10:00 PM. We’ll run the backup at 9:00 p.m. (this way we know we’re backing up all of our open tabs).

We will create a script that will run the backup and then create a cron job that will run the script every night at 9 p.m.

Create the script with the command:

nano firefoxbackup.sh

In this script, add the following:

#!/bin/bash

BDIR="/home/USER/.mozilla/firefox/STRING.default/sessionstore-backups"
BLOC="/home/USER/Documents"

tar -czvf $BLOC/firefoxbackup.tar.gz $BDIR

Where USER is your Linux username and STRING is the random string of characters for your Firefox profile directory.

Save and close the file.

Give the file executable permissions with:

chmod u+x firefoxbackup.sh

Test the file to make sure it works with:

./firefoxbackup.sh

When finished, you should see the firefoxbackup.tar.gz file in your ~ / Documents directory.

How to create the cron job in Firefox

We will now create the cron job. Open the crontab editor with:

crontab -e

At the bottom of this file we will add:

0 21 * * * /home/USER/firefoxbackup.sh >/dev/null 2>&1

You can change the location of the backup script to be where you prefer. Just make sure that if you change the location of the script that change is reflected in the cron job.

Now, at 9 p.m. every night, your sessionstore-backups directory (the directory that actually hosts your session information) will be backed up to ~ / Documents. If something goes wrong that day, you can restore Firefox to the previous night’s session and get all those open tabs back.

No, this won’t restore the tabs you opened when the problem arose, but it will save you from having to reopen and re-pin all of those tabs. This little trick has saved me a lot of time a few times. Set it up and hope you never have to rely on backup.

Also look


Leave A Reply

Your email address will not be published.