Transfer existing SIHub data to MariaDB
A new SIHub installation does not require an SQLite file. For an existing installation, the migration helper reads an unchanged SQLite backup once and transfers accounts, password/API key hashes, agents, knowledge, conversations and configuration to MariaDB. The production system then uses only DATABASE_URL for MariaDB.
For a new installation, do not run any of the SQLite backup, copy or import commands on this page. Use the Apache initial installation. A missing or invalid DATABASE_URL in /etc/sihub/sihub.env is corrected; no SQLite file is required for this. The interactive helper apache2/configure-database.py checks your existing MariaDB connection and writes the address with a correctly encoded password without changing database accounts or data.
Schedule a maintenance window and stop the existing SIHub service as well as your own maintenance/voice writers. Note their old startup method. Do not transfer a running SQLite main file on its own; use a consistent backup. The following backup uses the Python standard library directly and works independently of the new SIHub startup check. Replace ALT_DB_PFAD with the actual path, for example /var/www/SIHub/instance/aihub.sqlite3 or /var/lib/sihub/sihub.sqlite3.
sudo install -d -m 0700 /var/backups/sihub-migration
sudo python3 - <<'PY'
import os, sqlite3
from pathlib import Path
source = Path('ALT_DB_PFAD')
destination = Path('/var/backups/sihub-migration/source.sqlite3')
if not source.is_file():
raise SystemExit('Tatsächlichen alten DB-Pfad eintragen.')
fd = os.open(destination, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600)
os.close(fd)
with sqlite3.connect(source.as_uri() + '?mode=ro', uri=True) as old:
with sqlite3.connect(destination) as copy:
old.backup(copy)
if copy.execute('PRAGMA integrity_check').fetchone()[0] != 'ok':
raise SystemExit('Integritätsprüfung fehlgeschlagen; Migration nicht starten.')
print('Geschützte Quelldatenbanksicherung erstellt.')
PY
An existing backup is not overwritten. Keep the old DB and operator file protected and separate. The following two paths are alternatives.
Direct operation with Apache2
MariaDB 10.6+ and the Python requirements from apache2/README.md are needed; an existing MariaDB 10.6 server can be used. The template for new servers selects MariaDB 10.11. Stop the old SIHub service, for example sudo systemctl stop sihub, and confirm that port 5090 is free.
If the previous operator file is already /etc/sihub/sihub.env then it stays in this location. If your old installation uses a .env in the checkout instead, copy it only if the target file does not yet exist with protected permissions to /etc/sihub/sihub.env; session keys and provider credentials must be carried over.
cd /var/www/SIHub
sudo install -d -m 0700 /etc/sihub
# Nur beim Wechsel von einer bisherigen .env und nur bei fehlender Zieldatei:
sudo sh -c 'test ! -e /etc/sihub/sihub.env && install -m 0600 -o root -g root /var/www/SIHub/.env /etc/sihub/sihub.env'
If the target file already exists, skip the copy command. Check the owner and mode; the file must be owned by root and have mode 0600. The next call automatically backs up the previous operator file, creates the new local MariaDB DSN and keeps existing session/provider keys. Live operation remains disabled during the migration.
sudo python3 apache2/prepare-env.py --mariadb-upgrade
sudo bash apache2/install.sh prepare --no-start
sudo install -o sihub -g sihub -m 0400 /var/backups/sihub-migration/source.sqlite3 /var/lib/sihub/legacy-import.sqlite3
sudo bash apache2/install.sh manage migrate-mariadb --sqlite /var/lib/sihub/legacy-import.sqlite3
sudo bash apache2/install.sh manage check-config
sudo systemctl enable --now sihub
curl --fail http://127.0.0.1:5090/health
prepare --no-start installs dependencies, creates the local MariaDB and prepares empty tables. The app only starts after the import. For an existing self-managed or remote MariaDB, enter its DSN using sudoedit /etc/sihub/sihub.env instead; the target tables must be empty. Do not create a new administrator account before the import. The CLI only prints verified row counts, no credentials.
Then sign in at https://sihub.at/login with the migrated account. Check agents, knowledge, versions, conversation histories and exports. Remove the separate legacy-import.sqlite3 only after the migration has been confirmed; the protected source backup remains available for your rollback. Apache and the certificate do not change because of the database switch.
Docker operation with telephony stack
Prepare deploy/.env.production, the app image and the services mariadb/redis according to Server setup first. Transfer old session/provider/Redis/telephony keys securely into the new operator file. The new database is called SIHub; MARIADB_PASSWORD must match the password in DATABASE_URL=mariadb+pymysql://sihub:...@mariadb:3306/SIHub exactly. MARIADB_ROOT_PASSWORD is a separate admin key. An existing Redis ACL must still match the configured Redis password.
cd /var/www/SIHub
sudo install -o 10001 -g 10001 -m 0400 /var/backups/sihub-migration/source.sqlite3 /var/backups/sihub-migration/legacy-container.sqlite3
sudo docker compose --env-file deploy/.env.production -f deploy/compose.yml run --rm --no-deps --volume /var/backups/sihub-migration/legacy-container.sqlite3:/restore/legacy.sqlite3:ro app python scripts/migrate_to_mariadb.py --sqlite /restore/legacy.sqlite3
sudo docker compose --env-file deploy/.env.production -f deploy/compose.yml run --rm --no-deps app python manage.py check-config
sudo docker compose --env-file deploy/.env.production -f deploy/compose.yml up -d --wait app
curl --fail http://127.0.0.1:5090/health
The app and the direct service must not use port 5090 at the same time. The migration expects empty target tables, checks schema/foreign keys/row counts and writes the data import in one transaction. If an error occurs, the source remains unchanged; no partially imported data is released. MariaDB DDL runs before the data transaction and may leave empty target tables. A populated target database is rejected and not deleted.
Rollback and subsequent backup
Before any new writes, a failed switchover can be rolled back by stopping the new SIHub app and starting the noted old software/configuration state with the unchanged source. Once new data has been written to MariaDB, a rollback requires a planned reverse migration; the old SQLite file does not contain this data. Therefore, do not delete the source or the old operator file during the migration.
After a successful check, create a fresh MariaDB backup with sudo bash apache2/backup-mariadb.sh or sudo bash deploy/backup-mariadb.sh. Test restoring it as described in Operation and restore. The migration does not replace a live check of telephony or providers.