• ARTICLES
SEARCH

How-To Geek

How to Easily Automate Your Firefox Profile Backup with Batch Files

Your Firefox profile houses some pretty important stuff such as bookmarks, saved passwords and preferences which would be quite inconvenient to lose. As with any valuable data, your Firefox profile should be backed up regularly.

While you can always perform the backup manually or use an external tool (such as MozBackup or FEBE), each of these options have their own shortcomings and none are a true “set it and forget it” method. Our geek oriented solution to Firefox profile backups is to use a batch script which can be run at any time. Regardless of whether or not you have Firefox open, this script will capture your current Firefox profile and store it in a zip file for easy recovery.

The Script

Overall, the script doesn’t do anything magical. It simply goes to the respective user’s Firefix profile folder and copies all the unlocked files to a temporary directory and finally creates a zip archive of the files. You will need to have the 7-Zip command line tool copied to a folder set in your Windows PATH variable in order for the zip process to complete.

@ECHO OFF
TITLE Firefox Profile Backup
ECHO Firefox Profile Backup
ECHO Written by: Jason Faulkner
ECHO SysadminGeek.com
ECHO.
ECHO.

SETLOCAL

REM Requires the 7-Zip command line tool (7za.exe) which can be downloaded at:
REM http://www.7-zip.org
REM This file should be placed in a folder in the PATH variable (i.e. C:Windows)

REM Full path the the storage archive file (do not put in quotes)
REM Make sure this directory path exists.
SET BackupFileName=%USERPROFILE%DocumentsBackupFirefoxProfile.zip

REM Leave everything below here alone

SET TempBackupDir=%TEMP%Firefox_Profile
SET TempBackupDirAction="%TempBackupDir%"
IF EXIST %TempBackupDirAction% RMDIR %TempBackupDirAction%

MKDIR %TempBackupDirAction%
XCOPY "%APPDATA%MozillaFirefoxProfiles*" %TempBackupDirAction% /E /V /C /H /Y

SET BackupFileName="%BackupFileName%"
IF EXIST %BackupFileName% DEL /F /Q %BackupFileName%
7ZA a %BackupFileName% "%TempBackupDir%*"

IF EXIST %TempBackupDirAction% RMDIR /S /Q %TempBackupDirAction%

ENDLOCAL

Scheduling the Backup

Once you have the script in place, you simply need to schedule it via the Windows Task Scheduler. You can use the graphical interface or via the command line tool, SchTasks, to easily set it to run daily for the current user:

SchTasks /Create /SC DAILY /TN BackupFirefoxProfile /TR %UserProfile%DocumentsScriptsBackupFirefoxProfile.bat /ST 09:00 /RU <UserName> /RP <Password>

Important Note: The script makes reference to profile specific locations (%USERPROFILE% and %APPDATA%), so it is important the scheduled task runs as the respective user account you want to backup the Firefox profile for.

Limitations

This script will pick up any unlocked file as part of the backup. When Firefox is open, a file named “parent.LOCK” is created and this file is not included in the backup. It is a zero byte, so bit-wise the profile backup can complete without including this file.

Certain add-ons may also lock files while Firefox is open, but our testing has not found any instances where this is the case.

Download the 7-Zip Command Line Tool

Manually Backup a Firefox Profile

FEBE Add-on for Firefox

Jason Faulkner is a developer and IT professional who never has a hot cup of coffee far away. Interact with him on Google+

  • Published 01/24/11

Comments (24)

  1. Thijs

    idd edit this to run with winrar but still nice and easy copy paste tutor ;)
    shame on ms, this should be doable with the shell with windows built in zip function!!!
    take linux; you can just call gzip {file/folder-name} or gunzip {filename} function for this.

  2. UniversalMonster

    I’m surprised you haven’t mentioned Firefox Sync (https://services.mozilla.com/). Granted it’s still in beta, but it certainly does the job.

  3. trm96

    You can back up your profile (just not zip it) using a MS app: SyncToy (http://www.microsoft.com/downloads/en/details.aspx?familyid=c26efa36-98e0-4ee9-a7c5-98d0592d8c52&displaylang=en). With this app you can setup automatic backups to another folder or even to your Dropbox. Not that I don’t like batch files…

  4. Lucky Man

    thanks so much for article. it should be one of useful resource about firefox :)

  5. tn-man

    Thanks for the code. Is there a similar batch for Thunderbird?

  6. bluenaho

    Simply change: %APPDATA%MozillaFirefoxProfiles*
    to
    %APPDATA%ThunderbirdProfiles

    and %USERPROFILE%DocumentsBackupFirefoxProfile.zip
    to
    %USERPROFILE%DocumentsBackupThunderbirdProfile.zip

  7. Amit

    Well Firefox now has Firefox Sync Extension .. so no need to write backup scripts .. you can open your tabs on some other computer too … and it stores all your profile data secured online .. so on a new computer … just download your entire profile . Before sync .. I was using FEBE .. does the job pretty well .. even backs up your extensions .. and you can schedule the backup in it ..

  8. Jason Faulkner

    @tn-man – bluenaho’s post shows exactly what you need to know. I am not sure if you can do a backup of your Thunderbird profile while it is open, so you may want to test that.

    @Amit – A lot of people (including myself) don’t like the idea of this information being stored online. It definitely can be convenient but at a potential privacy and/or security risk.
    Regarding FEBE, I used to use it but I didn’t like how it would freeze Firefox and continually remind you if you didn’t backup right on schedule.

  9. blob

    Hi there, I’m not that great at scripting sooo basically where is my backup file? and when I run it it comes up with 7ZA is not a recognised command… And do i need to change anything in it to get it to work?

  10. Jason Faulkner

    @blob – Please read the information in the article regarding the requirements:

    “You will need to have the 7-Zip command line tool copied to a folder set in your Windows PATH variable in order for the zip process to complete.”

    This is also reiterated in the script:
    REM Requires the 7-Zip command line tool (7za.exe) which can be downloaded at:
    REM http://www.7-zip.org
    REM This file should be placed in a folder in the PATH variable (i.e. C:Windows)

  11. blob

    Yes I read that, it’s installed both in the windows directory
    “REM This file should be placed in a folder in the PATH variable (i.e. C:Windows)”
    and in the default place it comes up with when I click install on the 7-zip.
    Why isn’t it recognizing the command? Thanks :)

  12. Jason Faulkner

    @blob – You need the command line version, not the full install program. There is an option on the 7-Zip download page for this. It is simply a file named “7za.exe” (in the download zip file) which you need to put in your Windows directory.

  13. vaibhav

    The line towards the end:
    IF EXIST %TempBackupDirAction% RMDIR /S %TempBackupDirAction%

    Its missing /Q for Quiet mode when deleting files/folders.
    IF EXIST %TempBackupDirAction% RMDIR /S /Q %TempBackupDirAction%

  14. terryp

    To set up the script to select between multiple profiles:

    SETLOCAL

    REM Requires the 7-Zip command line tool (7za.exe) which can be downloaded at:
    REM http://www.7-zip.org
    REM This file should be placed in a folder in the PATH variable (i.e. C:Windows)

    ECHO Select profile backup
    set /P PROFILE=Select Profile to backup. Use Caps! (F=Firefox, S=Seamonkey, T=ThunderBird):
    if “%PROFILE%”==”F” goto FIREFOXP
    if “%PROFILE%”==”S” goto SEAMONKEYP
    if “%PROFILE%”==”T” goto THUNDERBIRD

    REM Full path the the storage archive file (do not put in quotes)
    REM Make sure this directory path exists.

    :FIREFOXP
    ECHO RUNIT
    SET BackupFileName=%USERPROFILE%My DocumentsBackupFirefoxProfile.zip
    GOTO RUNIT

    :SEAMONKEYP
    SET BackupFileName=%USERPROFILE%My DocumentsBackupSeaMonkeyProfile.zip
    GOTO RUNIT

    :THUNDERBIRD
    SET BackupFileName=%USERPROFILE%My DocumentsBackupThunderBirdProfile.zip

    :RUNIT
    REM Leave everything below here alone
    SET TempBackupDir=%TEMP%Firefox_Profile
    SET TempBackupDirAction=”%TempBackupDir%”
    IF EXIST %TempBackupDirAction% RMDIR %TempBackupDirAction%

    MKDIR %TempBackupDirAction%
    if “%PROFILE%”==”F” XCOPY “%APPDATA%MozillaFirefoxProfiles*” %TempBackupDirAction% /E /V /C /H /Y
    if “%PROFILE%”==”S” XCOPY “%APPDATA%MozillaSeaMonkeyProfiles*” %TempBackupDirAction% /E /V /C /H /Y
    if “%PROFILE%”==”T” XCOPY “%APPDATA%ThunderbirdProfiles*” %TempBackupDirAction% /E /V /C /H /Y

    SET BackupFileName=”%BackupFileName%”
    IF EXIST %BackupFileName% DEL /F /Q %BackupFileName%
    7ZA a -tzip %BackupFileName% “%TempBackupDir%*”

    IF EXIST %TempBackupDirAction% RMDIR /S /Q %TempBackupDirAction%

    ENDLOCAL

  15. Meena

    I had one in my blog but using winrar
    It’s also missing the scheduling thing , cuz i do it manually
    here it is
    http://meena-tech.blogspot.com/2010/10/how-to-backup-firefox-profile-with_12.html

  16. Hannah

    I like this, only it asks me “are you sure” every time, so it’s not really 100% automatic. Am I doing something wrong?

  17. Jason Faulkner

    @vaibhav – Good catch, I have updated the script.

  18. blob

    It’s good :D but where is my mozilla profile bnacked up to? :L

  19. blob

    backed*

  20. GeezerAl

    Well, to those who suggested using one of the syncing routines, I use Goodsynch because I am a Roboform user. However, neither of these solutions is really a “backup” because there is no history.

    Before I was regularly using a good backup program (Acronis or StorageCraft) I once had a problem that I failed to diagnose as a corrupted file. Therefore, when I had to restore a specific file, I had to go back several weeks. That would not be possible with either the very nicely done bat file or with one of the syncing programs.

    However, if you wanted to be extra careful in this regard, you would preappend the date and time to the zip file created. If the date were in yyyy/mm/dd format, they could be sorted by name and older files could be automatically deleted on whatever cycle you deemed appropriate, say 30 days. Then, the bat file will be far superior to any of the syncing programs!

    I am interested in your response.

    Albert

  21. Jason Faulkner

    @GeezerAl – Good points. You can easily add the date the backup was made by using this line:
    REM Get date in format YYYY-MM-DD (assumes the locale is the United States)
    FOR /F “tokens=1,2,3,4 delims=/ ” %%A IN (‘Date /T’) DO SET NowDate=%%D-%%B-%%C

    Then you will have a %NowDate% variable you can use when creating your filename:
    SET BackupFileName=%USERPROFILE%DocumentsBackup%NowDate%_FirefoxProfile.zip

    As for only keeping a certain amount of backup files based on a date, I have already covered how to automate this process in a previous article:
    http://sysadmingeek.com/articles/automating-the-process-of-deleting-old-log-files/

  22. Stanton

    @GeezerAl

    good date routine
    how about this……. shorter and to the point DDMMYY

    %DATE:/=%

  23. Gabriela

    I don’t know, but for me doesn’t work :(
    My profile is: C:\Documents and Settings\Gabriela
    I have the batch file and 7za.exe in C:\Windows, but when I run the batch file… nothing happens.
    What’s wrong? Should I change something in the batch file?

  24. Jason Faulkner

    @Gabriela – For some reason, when a batch script is posted in the article text, it strips out the backslashes (\)

    Make sure your script has the following lines as they are shown below (instead of what is shown in the article). Note: Replace the forward slash with a backslash in your script.

    SET BackupFileName=%USERPROFILE%/Documents/BackupFirefoxProfile.zip
    ……

    XCOPY “%APPDATA%/Mozilla/Firefox/Profiles*” %TempBackupDirAction% /E /V /C /H /Y

Enter Your Email Here to Get Access for Free:

Go check your email!