Here’s how my Firefox web browser workflow goes.
Each 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 at my previous session (with all of my pinned tabs and other tabs I might have had open for research). I write and I write and I write. That goes on throughout the day. When it comes time to turn the lights out in my office, I close Firefox (because I use the Nightly release and want to apply the latest additions upon starting the next morning) and say goodnight.
SEE: Checklist: Server inventory (TechRepublic Premium)
The next day, I start it all over again.
That workflow rarely fails me.
But on occasion, it does. You see, I have Firefox set to Restore previous session (in Settings), so it always picks up where I left off. This is where it can become problematic. Let’s say, for example, I forget that I had a second Firefox window open with a single tab. If I don’t close that secondary window first when I reopen Firefox the next day, it will remember whatever state it was in when it was last closed. If I close that single window last … you see where that’s going.
So what do I do?
One way to avoid such frustration is to regularly back up a specific directory which houses the session state. It’s not 100% foolproof, but it has helped me in the past.
I’m going to show you how to do just that. I’ll be demonstrating on Linux, but this can be done on macOS and Windows as well (you just have to adjust the directories and tools used).
What you’ll need
The only thing you’ll 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 must 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), look for the line Profile Directory.
Your Profile Directory will be in /home/USER/.mozilla/firefox/STRING.default
Where USER is your Linux username and STRING is a random string of characters.
Copy that 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 occur before Firefox is closed at the end of the day. Say, for instance, you close Firefox at 10 p.m. We’ll run the backup at 9 p.m. (that way we know we’re saving all of our open tabs).
We’re going to 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:
In that script add the following:
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:
After it completes, you should see the file firefoxbackup.tar.gz in your ~/Documents directory.
How to create the cron job in Firefox
Now we’re going to create the cron job. Open the crontab editor with:
At the bottom of that file, we’ll add:
0 21 * * * /home/USER/firefoxbackup.sh >/dev/null 2>&1
You can change the location of the backupscript to be where you prefer. Just make sure, if you change the location of the script, that change is reflected in the cronjob.
Now, at 9 p.m. every night, your sessionstore-backups directory (the directory that actually houses the information for your sessions) will be backed up to ~/Documents. Should anything go wrong that day, you can restore Firefox to the previous night’s session and reclaim all of those open tabs.
No, this won’t restore the tabs you have open at the moment the problem occurs, but it will save you from having to reopen and re-pin all of those tabs. This little trick has saved me a good amount of time on a few occasions. Set it up and hope you never have to depend on the backup.