Hello,
i have written a script to Update my openHAB 2.0 instance to a new Snapshoot.
I looked at the unix update script as a starting point but my folder strukture is different.
Please be careful and make a Backup … its my first Version
I hope it will help or is good for the dokumentation? Feel free to use it.
I have a Intel NUC28xx with Windows 10 on a SSD and my Strukture under C:\ is
- Services
-
- openHAB2
-
-
- aktuell (for the current running)
-
-
-
- new (for the unziped Snapshoot Folder)
-
-
-
-
- openhab-2.1.0 (example of a new Snapshoot)
-
-
-
-
- backup (will be created during the Upgrade)
-
-
-
- tmp (will be created during the Upgrade for log and fallback)
-
-
-
- _archiv (vor old backups)
-
1.) You need to download a Snapshoot to the new folder and unzip it.
2.) Delete Backup and tmp …or move it to _Archiv
3.) Create a Batch “openHABupdate.bat” and copy the Script to it
4.) Stop openHAB
@echo off
set WorkingDir=%cd%
set TempDir=tmp
set NewDir=new
set BackupDir=backup
set CurrentDir=aktuell
set ErrorMsg=""
echo.
echo.#########################################
echo. Todos before start
echo.#########################################"
echo.
echo.Stop your running openHAB instance
echo.Make a Backup of your existing running instance. THIS IS IMPORTEND!!!
echo.Run the Script one step Before the openHAB Folder. So you can see a folder like .\openHAB-2.0.0
echo.Please copy the new Version to the %NewDir% folder and unzip it. Like .\new\openhab-2.1.0.
echo.When ready press a key ...
@pause > NUL
echo.
echo.Set the temporary directories.
echo.==============================
if exist %TempDir% rmdir %TempDir% /S /Q && echo.Old TempDir %TempDir% Removed || set ErrorMsg=Failed to delete old: %TempDir%
if ERRORLEVEL 1 goto error
mkdir %TempDir% && echo %time% - Start > .\tmp\LOG-%date%.txt || set ErrorMsg=Failed to make temporary directory: %TempDir%
if ERRORLEVEL 1 goto error
echo.New TempDir %TempDir% created
echo.
echo.Check if there is a new Version
echo.===============================
set newVersion=empty
for /F "delims=" %%i IN ('dir "%WorkingDir%\%NewDir%" /b /ad-h /t:c /od') do set newVersion=%%i
if newVersion==empty (
set ErrorMsg=No new Version found
goto error
) else (
echo %time% - New openHAB Verison found: %newVersion% >> .\tmp\LOG-%date%.txt
echo.New openHAB Verison found: %newVersion%
)
echo.
echo.Make a Backup of the Current Installation
echo.=========================================
if exist %BackupDir% (
set ErrorMsg=There is already a BackupDirectory!!!
goto error
) else (
@timeout 5
echo %time% - Backup openHAB current Directory: %CurrentDir% to %BackupDir% >> .\tmp\LOG-%date%.txt
echo.Backup openHAB current Directory: %CurrentDir% to %BackupDir%
robocopy %CurrentDir% %BackupDir% /E
echo %time% - Backup finished >> .\tmp\LOG-%date%.txt
)
echo.
echo.#########################################
echo. openHAB 2.x.x update script
echo.#########################################"
echo.
echo.The script will attempt to update openHAB to version %newVersion%
choice /c "YN" /M "Is this okay"
if errorlevel 1 echo %time% - Update accepted >> .\tmp\LOG-%date%.txt
if errorlevel 2 (
echo.Cancelling update...
rmdir %TempDir% /S /Q
goto exit
)
echo.Remove only the files that are to be replaced.
echo.==============================================
echo.Removing openHAB System Files...
echo %time% - Removing openHAB System Files... >> .\tmp\LOG-%date%.txt
mkdir "%TempDir%\userdata\etc"
move "%CurrentDir%\runtime" "%TempDir%\"
move "%CurrentDir%\userdata\etc\all.policy" "%TempDir%\userdata\etc\"
move "%CurrentDir%\userdata\etc\branding.properties" "%TempDir%\userdata\etc\"
move "%CurrentDir%\userdata\etc\branding-ssh.properties" "%TempDir%\userdata\etc\"
move "%CurrentDir%\userdata\etc\config.properties" "%TempDir%\userdata\etc\"
move "%CurrentDir%\userdata\etc\custom.properties" "%TempDir%\userdata\etc\"
move "%CurrentDir%\userdata\etc\version.properties" "%TempDir%\userdata\etc\"
move "%CurrentDir%\userdata\etc\distribution.info" "%TempDir%\userdata\etc\"
move "%CurrentDir%\userdata\etc\jre.properties" "%TempDir%\userdata\etc\"
move "%CurrentDir%\userdata\etc\profile.cfg" "%TempDir%\userdata\etc\"
move "%CurrentDir%\userdata\etc\startup.properties" "%TempDir%\userdata\etc\"
move "%CurrentDir%\userdata\etc\org.apache.karaf"* "%TempDir%\userdata\etc\"
move "%CurrentDir%\userdata\etc\org.ops4j.pax.url.mvn.cfg" "%TempDir%\userdata\etc\"
echo.Clearing the cache and tmp folders is necessary for upgrade.
echo.============================================================
echo.Clearing cache...
echo %time% - Clearing cache... >> .\tmp\LOG-%date%.txt
rmdir /s /q "%CurrentDir%\userdata\cache"
rmdir /s /q "%CurrentDir%\userdata\tmp"
echo.Copy the downloaded folder into openHAB's directory WITHOUT replacing any existing files.
echo.=========================================================================================
echo.Updating openHAB...
echo %time% - Updating openHAB... >> .\tmp\LOG-%date%.txt
@timeout 5
robocopy %NewDir%\%newVersion% %CurrentDir% /e /xc /xn /xo
goto exit
:error
echo.
echo ERROR: %ErrorMsg%
pause
quit
:exit
echo SUCCESS: openHAB updated to %newVersion%
echo %time% - USUCCESS: openHAB updated to %newVersion% >> .\tmp\LOG-%date%.txt
pause