REM Version 2025-08-22 17:30

REM Backup Firefox profiles from source folder to destination folder, with naming year-month-day
REM then delete the oldest files if more than max number 
REM The batch must be in the folder where the backup is going, 1 level higher
REM program folder: ....\Backup profiles\Program 
REM file folder: ....\Backup profiles\Profiles

REM Declaraties tbv backup profielen
set bronmap=%UserProfile%\AppData\Roaming\Mozilla\Firefox\profiles\default
set bestandsnaam=Firefox [name of the PC]
set extensie=zip
set doelmap=..\Profiles
set tempnaam=TEMP
set maxaantal=7
set zip-programma=C:\Program Files Portable\7ZIP\7za.exe

REM Delay of 1 sec due to computer startup (if necessary) 
rem timeout 1 /NOBREAK

REM Remove the entire chrome_debugger_profile folder from the profile if present
REM That folder is created during Remote debugging and is completely unnecessary for
REM normal use. He takes at least 16 MByte
if exist %bronmap%\chrome_debugger_profile del %bronmap%\chrome_debugger_profile /s /q
if exist %bronmap%\chrome_debugger_profile rd %bronmap%\chrome_debugger_profile /s /q


REM Next batch part gets directly from %DATE% the separate day, month, year
REM And adds that together in the correct order

set Year=%date:~9,4%
set Month=%date:~6,2%
set Day=%date:~3,2%

@echo on
@echo.  
@Echo Date today is %Year%-%Month%-%Day% 
@echo.
@echo off

REM Create target folder if it doesn't already exist
if not exist %doelmap% md %doelmap%

REM Compress (ZIP) the entire source folder to a temporary ZIP file
set tempbestand="%doelmap%\%bestandsnaam% %tempnaam%.%extensie%"
if exist %tempbestand% del %tempbestand%
"%zip-programma%" a -r -tzip %tempbestand% "%bronmap%\*"

if not errorlevel 1 goto SUCCESS

echo ***
echo ***
echo ***
echo ***
echo *** Error creating Zip file, presumably Firefox in use! ***echo ***
echo ***
echo ***
echo ***

pause

goto END

:SUCCESS

REM Rename temporary file to file name with current date
REM But first delete the existing file if with the same date
set doelbestandnaam="%bestandsnaam% %Year%-%Month%-%Day%.%extensie%"
set doelbestand="%doelmap%\%bestandsnaam% %Year%-%Month%-%Day%.%extensie%"

if exist %doelbestand% del %doelbestand%
ren %tempbestand% %doelbestandnaam%

REM Delete oldest files if more than 7 pieces (or the maximum number as specified above)

for /f "skip=%maxaantal% eol=: delims=" %%F in ('dir /b /o-d "%doelmap%\"*.%extensie%') do @del "%doelmap%\""%%F"

REM see: http://stackoverflow.com/questions/13367746/batch-file-that-keeps-the-7-latest-files-in-a-folder

:END

REM Clear temporary file again if it still exists
if exist %tempbestand% del %tempbestand%

start "Firefox" /I "C:\Program Files Portable\Mozilla Firefox\firefox.exe"
EXIT

 

