For H2 there are several ways to backup the database. The easiest is to stop QIE, copy the h2 database files, restart QIE. Doing it this way requires QIE to be stopped.
@echo off
REM "The name of the QIE service"
set qieServiceName="QIEService"
REM "Install directory location for QIE H2 database"
SET qieH2DatabaseSourceDir="C:\ProgramData\QIE\h2"
REM "Backup directory location root"
SET backupDir="C:\ProgramData\QIE\h2backup"
REM Check if the QIE service is running then stop it.
for /F "tokens=3 delims=: " %%H in ('sc query %qieServiceName% ^| findstr " STATE"') do (
if /I x"%%H" == x"RUNNING" (
REM stop the QIE service
net stop %qieServiceName%
)
)
REM Check again for the stopped QIE service before continuing
for /F "tokens=3 delims=: " %%H in ('sc query %qieServiceName% ^| findstr " STATE"') do (
if /I x"%%H" == x"STOPPED" (
REM Get backup subfolder name using the day name for the day of the week
for /f %%d in ('"powershell Get-Date -format ddd"') do @SET rotationFolderName=%%d
REM use the next line as an alternate for the above for a monthly rotation
REM for /f %%d in ('"powershell (Get-Date).Day"') do @SET rotationFolderName=%%d
REM Copy the H2 database files for a 7 day rotation by placing them in a folder by the day of the week.
xcopy /I /Y %qieH2DatabaseSourceDir%\* %backupDir%\%rotationFolderName%
REM Start the QIE service after copy
net start %qieServiceName%
)
)