I know OMG is a bat file maven as, perhaps, are others of you. Would one of you kind people please point me to a good tutorial to refresh my aging (and decrepit) memory? Please and thank you!



(1/2)(1+√5) |
(1/2)(1+√5) |
(1/2)(1+√5) |
Code: Select all
robocopy "%AppData%\Mozilla\Firefox\Profiles" "D:\Firefox Profiles" /S
Code: Select all
@echo off
:: +----------------------+
:: I FirefoxProfileCopier I copy the Firefox Profile while Firefox is not active
:: +----------------------+
:: this BATch file may be task scheduled at regular intervals,
:: and/or run as a Logoff script
:: it checks whether or not Firefox is running
:: and copies it ONLY if Firefox is not running (just in case)
:: we keep five backup copies of the Firefox Profile, suffixed .#1 to .#5
:: the format is BlueYonder account.pst.#1 up to #5
:: the number has no function except to differentiate the filenames
:: for the latest copy, simply refer to the dates and times of the files
:: an interesting and unexpected side-effect is that if the PST file does
:: NOT change between backups, then the same backup file number is used
:: until there IS a change to the PST file!
setlocal
:: obtain timestamp as yyyymmdd_hhmm yyyy mm dd_ hh mm
for /f "tokens=1-5 delims=/;:." %%a in ("%date%;%time: =0%") do set "dt=%%c%%b%%a_%%d%%e"
:: cumulative file
set cumulog=%~dp0Logs\%computername%_%~n0_cumulative.log
:: if Firefox is running, we don't do a backup, and leave immediately
tasklist /fi "imagename eq firefox.exe" ^
| findstr /b /i /c:"firefox.exe" > nul && (
echo %dt% Firefox running; no profile copy performed >> %cumulog%
goto sorter
)
)
:: source folder and the (newest) profile name folder
set source=%APPDATA%\Mozilla\Firefox\Profiles
for /f %%a in ('dir /ad /od /b %source%') do set profilename=%%a
if not defined profilename (
echo %dt% unable to find a source Firefox profile >> %cumulog%
endlocal
exit /b 1
)
:: target folder - ensure it is set up
set target=D:\Backup\Firefox Profiles
md "%target%" 2>nul
:: set up the source folder name, which will have .#n added for the target folder name
set folder=Firefox Profile
:: Step 1 - examine any backups in the target directory
:: initially assume that there have been no backups, so set newest to 0
set newest=0
:: obtain the newest backup folder number, if any, from the target folder directory
:: the 2>nul avoids an error message from DIR if there is no backup file yet,
:: in which instance the contents of %newest% are not altered
for /f "tokens=*" %%a in ('dir "%target%\%folder%.#?" /b /od 2^>nul') do set newest=%%a
:: obtain the suffix number of the most recent backup file
:: if this is 5 [or above!] then revert to 1, else increment it
set sfx=%newest:~-1%
if %sfx% geq 5 (set sfx=1) else (set /a sfx+=1)
:: Step 2 : perform the copy
:: construct the robocopy parameters and the upper-level folder name
set source=%source%\%profilename%
set ulf=%target%\%folder%.#%sfx%
set target="%target%\%folder%.#%sfx%\%profilename%"
set parms=/copy:dat /mir /s /dcopy:t /np /ndl /nfl /r:0 /w:0
set log=%~dp0Logs\%computername%_%~n0.profile#%sfx%.log
robocopy %source% %target% %parms% > %log%
:: change timestamp of the upper-level folder to the current date and time
type nul > "%ulf%\$dummy$" & del "%ulf%\$dummy$"
:: one line is written to the cumulative log for this backup
echo %dt% Firefox profile copied to backup #%sfx% >> %cumulog%
:sorter
:: sort the cumulative log into reverse order
sort /r %cumulog% /o %cumulog%
endlocal
I use SyncBackFree:
I endorse this simple approach, but would expand it, thereby Keeping It Simple while Making It Complex:-Jay Freedman wrote: ↑22 Sep 2021, 00:09For this specific job -- copying your Firefox profile from its operating location to a backup on another drive -- you need only one statement in a batch file that runs the RoboCopy program with the appropriate arguments:Code: Select all
RoboCopy "%AppData%\Mozilla\Firefox\Profiles" "D:\Firefox Profiles" /S
Code: Select all
RoboCopy "%AppData%\Roaming" "D:\AppData" /S
(1/2)(1+√5) |
(1/2)(1+√5) |
(1/2)(1+√5) |
You followed Chris's instruction to the letter.
Code: Select all
robocopy %appdata% t:\appdata /s
(1/2)(1+√5) |
What John Gray says.
(1/2)(1+√5) |
Yes!
Code: Select all
T:\BATLap\Sync2021.bat
Code: Select all
C:\Windows\System32\cmd.exe /c T:\BATLap\Sync2021.bat