Anyone use this Registry Backup script? (BackupBI5v2.cmd)

eeeeesh

BIT Beta Team
Joined
Jan 5, 2017
Messages
412
Reaction score
681
Found it on Backup Blue Iris 5 Settings - Blue Iris. You can manually run it to backup the registry settings or set up task scheduler to run it everyday. More info at that link I posted

Code:
@Echo off
REM ---------------------------------------------------------------------------
REM BackupBI5v2.CMD
REM     Version 2.3 - March 21, 2020
REM
REM     Backs up all Blue Iris' Settings stored in the registry using
REM     RegEdit.exe and save it in either a ZIP or REG format to include
REM     the version and bit architecture as part of the filename
REM     'BlueIris_v5.xx.xx_x64.zip'.
REM
REM History:
REM     v1.0 June 1, 2019
REM         + Initial release for Blue Iris 5 release.
REM     v2.0 July 5, 2019
REM         + Changed version detection to use WMIC instead of FILEVER.EXE.
REM         + Added check for Administrator privileges.
REM     v2.1 September 2, 2019
REM         + Added code to back up Blue Iris settings in HKEY_CURRENT_USER.
REM     v2.2 March 7, 2020
REM         + Changed version detection to use either Powershell and WMIC.
REM         + Added include configuration file for shared variables
REM     v2.3 March 21, 2020
REM         + Added code for compressing and storing REG settings into a ZIP file.
REM
REM Written by: RedDawg
REM
REM Compatible with Win7, Win8, Win8.1, Win10
REM ---------------------------------------------------------------------------

CALL :is_Admin || GOTO :EOF
PushD .

SET DEST=%USERPROFILE%\AppData\Local
SET DRV=C:
SET MAJORVER=5
SET ZIPFLG=1
SET DELAY_VAL=3

REM ----- Parse Command line arguments -----
IF NOT "%~1" == "" (
     IF /i "%1" == "-h" Goto :HELP
     IF /i "%1" == "/h" Goto :HELP
     IF /i "%1" == "/?" Goto :HELP

     IF /i "%~1" == "/Reg" SET ZIPFLG=0
)

REM ---[ Include external configuration file for variables ]---
CD %~dp0
IF EXIST "BI5_Config.txt" FOR /f "skip=4 delims=" %%x in (BI5_Config.txt) do (SET "%%x")

REM ---------------[ DO NOT CHANGE BELOW ]---------------

SET INSTALL=%~dp0
SET SOURCE=%DRV%\Program Files (x86)\Blue Iris %MAJORVER%
SET PROG=Blueiris
SET KEY=NONE
SET OSARCH=32
IF "%PROCESSOR_ARCHITECTURE%"=="AMD64" SET OSARCH=64

IF NOT EXIST "%SOURCE%\%PROG%.exe" SET SOURCE=%DRV%\Program Files\Blue Iris %MAJORVER%
IF NOT EXIST "%SOURCE%\%PROG%.exe" GOTO :NotFound

reg QUERY "HKLM\SOFTWARE\Wow6432Node\Perspective Software\Blue Iris" /ve > NUL 2>&1
if %ERRORLEVEL% == 0 (
     SET KEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Perspective Software
     SET KEYCU=HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Perspective Software
     SET BITS=32
)

reg QUERY "HKLM\SOFTWARE\Perspective Software\Blue Iris" /ve > NUL 2>&1
if %ERRORLEVEL% == 0 (
     SET KEY=HKEY_LOCAL_MACHINE\SOFTWARE\Perspective Software
     SET KEYCU=HKEY_CURRENT_USER\SOFTWARE\Perspective Software
     SET BITS=64
     IF "%OSARCH%"=="32" SET BITS=32
)

if "%KEY%" == "NONE" GOTO :NotFound

if NOT EXIST "%DEST%\Blue Iris" MD "%DEST%\Blue Iris" > NUL
if NOT EXIST "%DEST%\Blue Iris\Archives" MD "%DEST%\Blue Iris\Archives" > NUL
if NOT EXIST "%DEST%\Blue Iris\Archives\Temp" MD "%DEST%\Blue Iris\Archives\Temp" > NUL
SET DEST=%DEST%\Blue Iris\Archives

Echo Creating REGEDIT registry snapshot of Blue Iris %MAJORVER% settings...

CALL :GetVersion "%SOURCE%\%PROG%.exe"
SET BI_VER=%FILE_VER%

:ExportSettings
IF %ZIPFLG% == 0 (
     Echo    %DEST%\%PROG%_v%BI_VER%_x%BITS%.reg
     Echo    %DEST%\%PROG%_v%BI_VER%_x%BITS%_cu.reg
)
REM --- REGEDIT /E Export's BlueIris with unicode ---
REGEDIT /E "%DEST%\%PROG%_v%BI_VER%_x%BITS%.reg" "%KEY%"
REGEDIT /E "%DEST%\%PROG%_v%BI_VER%_x%BITS%_cu.reg" "%KEYCU%"

IF NOT EXIST "%DEST%\%PROG%_v%BI_VER%_x%BITS%.reg" (
     Echo. && echo ERROR: %PROG%_v%BI_VER%_x%BITS%.reg is missing from %DEST%.
     Echo Make sure to run BackupBI5v2.cmd as Administrator.
     GOTO :DONE
)

IF %ZIPFLG% == 0 GOTO :DONE
CALL :ZipIt "%PROG%_v%BI_VER%_x%BITS%.zip" "%DEST%\%PROG%_v%BI_VER%_x%BITS%*.reg" "%DEST%"
IF EXIST "%DEST%\%PROG%_v%BI_VER%_x%BITS%.zip" (
     DEL /Q "%DEST%\%PROG%_v%BI_VER%_x%BITS%*.reg" > NUL
)
GOTO :DONE

REM --------------------------------------------
REM ZipIt (ZipFile) (Filename) (Dest)
REM      where Filename is FQN
REM --------------------------------------------
:ZipIt <ZipFile> <Filename> <Destination>

SET BREAK=
For %%F in ("%~2") do IF NOT DEFINED BREAK (
    SET _Name=%%~nF
    SET _Ext=%%~xF
    SET BREAK=1
)
PUSHD .
CD "%~3"
ECHO.
ECHO Building zip file %~1...please wait...
FOR %%F in ("%~2") do ECHO    adding %%F
ECHO.
SET TEMPDIR=%~3\Temp-%random%
MD "%TEMPDIR%"
XCOPY "%~2" "%TEMPDIR%" /D /Y > NUL 2>&1

SET vbs=_zipIt.vbs

ECHO Dim fso, objShell, dirToZip, ZipFile, file, zip, d > %vbs%
ECHO.>> %vbs%
ECHO ' Get command-line arguments. >> %vbs%
ECHO Set objArgs = WScript.Arguments >> %vbs%
ECHO Set fso = CreateObject("Scripting.FileSystemObject") >> %vbs%
ECHO dirToZip = fso.GetAbsolutePathName(objArgs(0)) >> %vbs%
ECHO ZipFile = fso.GetAbsolutePathName(objArgs(1)) >> %vbs%
ECHO.>> %vbs%
ECHO ' Create an empty ZIP file. >> %vbs%
ECHO Set file = fso.CreateTextFile(ZipFile) >> %vbs%
ECHO file.Write Chr(80) ^& Chr(75) ^& Chr(5) ^& Chr(6) ^& String(18, 0) >> %vbs%
ECHO file.Close >> %vbs%
ECHO.>> %vbs%
ECHO Set objShell = CreateObject("Shell.Application") >> %vbs%
ECHO Set zip = objShell.NameSpace(ZipFile) >> %vbs%
ECHO Set d = objShell.NameSpace(dirToZip) >> %vbs%
ECHO zip.CopyHere d.items, 4 >> %vbs%
ECHO Do Until d.Items.Count ^<= zip.Items.Count >> %vbs%
ECHO     Wscript.Sleep(3000) >> %vbs%
ECHO Loop >> %vbs%
ECHO Set fso = Nothing >> %vbs%
ECHO Set file = Nothing >> %vbs%
ECHO Set objShell = Nothing >> %vbs%

CScript %vbs% "%TEMPDIR%" "%_Name%.zip" > NUL
ECHO Finished...Cleaning up...
IF EXIST %vbs% DEL %vbs%
IF EXIST "%TEMPDIR%" RD /S /Q "%TEMPDIR%"
POPD
GOTO :EOF

:NotFound
Echo.
Echo FATAL ERROR: Blue Iris %MAJORVER% is not installed or present in the Windows Registry
Echo.
GOTO :DONE

REM -------------------------------------
REM   GetVersion %1=path/file
REM -------------------------------------
:GetVersion

For %%F in ("%~1") do (
    Set Folder=%%~dpF
    Set Name=%%~nxF
)
REM ---------------------------------------------
REM   Get file version using Powershell
REM ---------------------------------------------
PUSHD .
CD "%Folder%"
FOR /F "USEBACKQ" %%F IN (`powershell -NoLogo -NoProfile -Command ^(Get-Item "%Name%"^).VersionInfo.FileVersion`) DO (SET FILE_VER=%%F)
POPD
IF NOT "%FILE_VER%" == "" GOTO :EOF
SET FILE_VER=

REM ---------------------------------------------
REM   Get file version using WMIC
REM ---------------------------------------------

SET WMICSRC=%Folder%%Name%
SET WMICSRC=%WMICSRC:\=\\%

SET FILEPATH=%DEST%\%random%.txt
wmic datafile where name="%WMICSRC%" get Version /value > "%FILEPATH%"

for /f "tokens=2 delims== " %%a in ('type ^"%FILEPATH%^"') do @(
    SET FILE_VER=%%a
)
IF EXIST "%FILEPATH%" Del "%FILEPATH%"
GOTO :EOF

REM ---------------------------------------------------------------------------
REM is_Admin detects whether batch file was run with Administrative permissions
REM ---------------------------------------------------------------------------
:is_Admin

fsutil dirty query %systemdrive% >nul
if NOT %errorLevel% == 0 (
    echo.
    echo ######### ERROR: ADMINISTRATOR PRIVILEGES REQUIRED ###########
    echo This script must be run as administrator to work properly! 
    echo Right click on the shortcut and select "Run As Administrator".
    echo ##############################################################
    echo.
    TIMEOUT /T %DELAY_VAL%
    exit /b 1
)
goto :EOF

REM ----------------------
REM Help syntax
REM ----------------------
:HELP
Cls
Echo.
Echo BackupBI5v2.cmd
Echo ===============
Echo Backs up all Blue Iris' Settings stored in the registry using
Echo RegEdit.exe and save it in either a ZIP or REG format to include
Echo the version and bit architecture as part of the filename
Echo 'BlueIris_v5.xx.xx_x64.zip'. 
Echo.
Echo Syntax: BackupBI5v2.cmd [options]
Echo.
Echo         BackupBI5v2.cmd /? = help
Echo         BackupBI5v2.cmd /h = help
Echo         BackupBI5v2.cmd /Reg = Save backups in REG format instead of ZIP
Echo.
GOTO :DONE

:DONE
POPD
TIMEOUT /T %DELAY_VAL%
GOTO :EOF
 

SpacemanSpiff

Known around here
Joined
Apr 15, 2021
Messages
1,476
Reaction score
2,488
Location
USA
Doesn’t BI itself make a backup of settings each time you install an update?
Good question. Adding a part II.... If BI does back-up during update install, does it include the registry settings as well? Would like to think the BI script in the OP is included, but thought I'd pose the question anyway.

Regardless, it is a good tool to have for making your own copy copies. With all the things happening during an update install, it sucks to learn the update bombed... and the auto back-up of settings failed.
 

IAmATeaf

Known around here
Joined
Jan 13, 2019
Messages
3,313
Reaction score
3,302
Location
United Kingdom
It obviously wont include a 3rd party batch file.

On my system with each update it makes a backup, files are called backup.reg, backup2.reg and backup3.reg which it cycles through, so 2 becomes 3 and the first file becomes 2.

The files are in regf format so can be imported using the BI GUI or by using the reg.exe utility. I have in the past kicked off a manual backup which you do from the GUI to test something and then again restored using the GUI.
 

eeeeesh

BIT Beta Team
Joined
Jan 5, 2017
Messages
412
Reaction score
681

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,680
Reaction score
14,041
Location
USA
Something I noticed when developing BiUpdateHelper is that Blue Iris stores motion detection masks very inefficiently, making it important to compress your backups. It is not unheard of for your Blue Iris registry backup to be tens or hundreds of megabytes, so compression is important.

The script above apparently uses zip compression for the backups, but doesn't include the program that does the zipping. So I'm not sure how (or if) that works.

On my main system the raw size of one raw backup is 286,784 KB. Yes, over a quarter of a gigabyte. On most people's systems this should be much smaller, but I have had a lot of different cameras running at different resolutions over the years, so a lot of motion maps got built up and there's no way to automatically clear out those that are not used anymore.

Zip compression is pretty effective on this, yielding a file size of 2,731 KB.

But 7z compression is much better, yielding 147 KB file size. BiUpdateHelper uses 7z compression. That also means if you use BiUpdateHelper, you should install 7zip if you don't have it already, so you can extract the backup files.
 

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,680
Reaction score
14,041
Location
USA
Also noteworthy, Blue Iris's built-in registry backup function doesn't compress the backup archives. But it does back up to a non-human-readable binary format which is inherently somewhat less wasteful of disk space. Fortunately it does a rolling backup scheme where you only keep the last 3 or something backups, so it isn't going to fill up your disk.
 

IAmATeaf

Known around here
Joined
Jan 13, 2019
Messages
3,313
Reaction score
3,302
Location
United Kingdom
Also noteworthy, Blue Iris's built-in registry backup function doesn't compress the backup archives. But it does back up to a non-human-readable binary format which is inherently somewhat less wasteful of disk space. Fortunately it does a rolling backup scheme where you only keep the last 3 or something backups, so it isn't going to fill up your disk.
As I said above it backups to regf format, the util reg.exe can be used to import the file if need be outside of the BI GUI.
 

Boyturtle

n3wb
Joined
May 22, 2019
Messages
17
Reaction score
8
Location
United Kingdom
I found this post while searching for information about BI config backup as I wasn't satisfied with the way BI handled it. I wasn't aware of BiUpdateHelper, but now I am and I have it running on my Blue Iris server. Thanks @bp2008 for a very functional and lightweight product that does what it says on the tin :)
 
Top