Standalone Java service that migrates H2 databases from 1.4.x to 2.x, addressing critical CVEs (CVE-2021-42392, CVE-2022-23221, CVE-2021-23463, CVE-2022-45868).
Licensed under the Apache License 2.0.
Designed to run before upgrading Semoss
to a version built against H2 2.x. Local migration is intentionally aware of
the SEMOSS db/, project/, and InsightCache/ layouts. Files outside a known
SEMOSS target class fail closed instead of being opened with guessed credentials.
Files directly under db/ share a directory with many engine profiles. The
utility requires exactly one H2 profile whose URL identifies that root-level
database (preserving db/<basename> when the home has been copied). Missing
or ambiguous matches require manual review; an unrelated profile is never
selected merely because its name sorts first.
- Local mode: Scans a directory tree for
.mv.db/.h2.dbfiles and migrates each one into a verified temp file that atomically replaces the original - Cloud mode: Uses RClone to discover, download, migrate, and re-upload H2 databases from S3, Azure Blob, GCS, or MinIO
- Classloader isolation: Loads H2 1.4.200 and 2.4.240 simultaneously via separate URLClassLoaders
- Automatic backups: Backs up every database before migration; a file is restored only if it
was already replaced. The backup directory (default
<db-dir>/.h2-backup) is never scanned - Safe reruns: Locked files are refused untouched; a run that was killed mid-file leaves an in-progress marker, and the next run restores that file from its backup and migrates it again
- SQL script preservation: Export scripts are copied to the backup directory for post-mortem analysis
- SMSS credential validation: Reads primary-database credentials only from a
profile whose type, driver, or URL confirms that it is H2. A missing username
defaults to empty, matching H2/SEMOSS; an explicit blank stays blank.
--default-useroverrides only a missing username, not a configured one - Text LOB preservation: Legacy
TEXT,LONGTEXT,MEDIUMTEXT,TINYTEXT, andNTEXTcolumn declarations become explicitCLOB, preserving their H2 1.4 storage type. OrdinaryVARCHARcolumns remain unchanged - ENUM and NULL-type repair: H2 1.4
SCRIPTwrites ENUM values as 0-based ordinals that 2.x reads as 1-based; each ordinal becomes its label so values never shift. Indexes onNULL-typed columns (always NULL; 2.x cannot index them) are stripped. A never-initialized file is exported from a scratch copy - macOS metadata skip: AppleDouble sidecars (
._*.mv.db, anything under__MACOSX/, or content starting00 05 16 07) are reportedSKIPPEDasMACOS_METADATAand left in place instead of failing their engine/project - Project type filter (cloud default): a project scope migrates projects
whose
.smsstype isINSIGHTS, blank or missing, plus any project with saved insights (*.mosfet); BLOCKS/CODE/WORKSPACE/SKILL/NOTEBOOK/AUTOMATION projects without them areSKIPPED, for SEMOSS builds that recreate their insights DB.--migrate-all-project-typesor an explicitsemoss-project/<id>scope migrates everything - SEMOSS target classification: Distinguishes system stores, user engines,
generated audit/insight databases, persisted insight-frame stores, and live
InsightCachefiles before credentials are selected - Generated database profiles: Uses the SEMOSS runtime
sa/empty profile for audit, project-insight, and savedH2_Store_*.mv.dbframe databases instead of borrowing a neighboring project/engine.smss - Backend-aware primary handling: User-engine files require a confirmed H2
.smss; base system files whose active.smssis confirmed PostgreSQL or SQLite have their retained H2 file migrated with the default system credentials (--default-user/--default-password), and the non-H2.smssis left unchanged. If the defaults cannot open the file it is reported asSKIPPEDand left untouched. Non-H2 credentials are never used to open a physical H2 file - Version detection: Skips databases already in H2 2.x format (MVStore format ≥ 2)
- Dry-run support: Preview what would be migrated without changes
- JSON report: Writes a migration report with per-database status, sorted by outcome
- Java 21+
- Maven 3.9+ (for building)
- RClone (for cloud mode only)
Each tagged version is published as a
GitHub Release with the
runnable h2-migration-service.jar and its SHA-256 checksum:
gh release download --repo SEMOSS/h2-update-utility --pattern 'h2-migration-service.jar*'
shasum -a 256 -c h2-migration-service.jar.sha256Without a tag, gh release download takes the latest release; add one such as
v1.2.0 to pin a version. The same JAR is also published to GitHub Packages
as the Maven artifact org.semoss:h2-migration-service (repository
https://maven.pkg.github.com/SEMOSS/h2-update-utility; Maven needs a token
with read:packages).
mvn clean packageProduces target/h2-migration-service.jar — a fat JAR containing both H2 versions.
For a step-by-step local upgrade (including one driven by an AI assistant), follow the Local upgrade runbook.
java -jar target/h2-migration-service.jar \
--mode=local \
--db-dir=/path/to/semoss/db \
--backup-dir=/path/to/backupsRun local SEMOSS homes as two maintenance passes while every SEMOSS process is stopped:
# System stores, user engines, and per-engine audit databases
java -jar target/h2-migration-service.jar \
--mode=local --db-dir=/path/to/semoss/db --backup-dir=/path/to/backups/db
# Project insight metadata and persisted saved-insight H2 frames
java -jar target/h2-migration-service.jar \
--mode=local --db-dir=/path/to/semoss/project --backup-dir=/path/to/backups/projectInsightCache/** databases are reported as SKIPPED. Saved
project/*/app_root/version/*/H2_Store_*.mv.db files remain migration targets.
Unknown locations or primary databases without a confirmed H2 .smss are
reported as failures and produce a nonzero exit code, including during dry-run.
For confirmed H2 profiles, the utility removes the H2 1.x URL settings that
H2 2.4.240 rejects (for example MVCC, MULTI_THREADED, MV_STORE=FALSE,
EARLY_FILTER, LOG, UNDO_LOG, ALIAS_COLUMN_NAME, COMPRESS_LOB,
ACCESS_MODE_LOG; full list in RuntimeConnectionUrlBuilder) from the
persisted .smss after a successful database import. The .smss is backed up
first and restored with the database if the update or runtime-open validation
fails. A database that is already 2.x still gets its .smss URL repaired.
Dry-run reports the planned settings removal without editing the file.
.smss files are parsed like SEMOSS parses them (java.util.Properties,
ISO-8859-1), and rewritten byte for byte outside the URL.
A .h2.db that has a .mv.db with the same base name next to it is reported as
FAILED and neither file is touched.
S3, MinIO, and GCS use the same object layout inside one bucket:
<bucket>/
├── semoss-db/
│ ├── <engineId>/
│ │ ├── database.mv.db
│ │ └── audit_log_database.mv.db
│ └── <engineId>-smss/
│ └── <engine-name>__<engineId>.smss
└── semoss-project/
├── <projectId>/
│ ├── insights_database.mv.db
│ └── app_root/version/<insightId>/H2_Store_<id>.mv.db
└── <projectId>-smss/
└── <project-name>__<projectId>.smss
The engine's -smss prefix is required when its primary database.mv.db is
present. The project -smss prefix is part of the SEMOSS storage layout, but
project insight and persisted-frame databases use generated H2 runtime profiles,
so the utility does not download that SMSS object for those migrations.
Azure uses one container for each engine/project and separate SMSS containers:
container: db-<engineId>
├── database.mv.db
└── audit_log_database.mv.db
container: db-<engineId>-smss
└── <engine-name>__<engineId>.smss
container: project-<projectId>
├── insights_database.mv.db
└── app_root/version/<insightId>/H2_Store_<id>.mv.db
container: project-<projectId>-smss
└── <project-name>__<projectId>.smss
For S3, MinIO, and GCS, SEARCH_PATH must be semoss-db,
semoss-db/<engineId>, semoss-project, or semoss-project/<projectId>.
On Azure, semoss-db covers every db-<engineId> container and
semoss-project every project-<projectId> container in the account (the
connection must be allowed to list containers); db-<engineId> or
project-<projectId> runs one container.
Use the utility's S3_* variables for injected credentials. S3_SESSION_TOKEN
is required only for temporary STS credentials.
export MODE=cloud
export BACKUP_DIR=/tmp/h2-backups/s3
export SEMOSS_STORAGE_PROVIDER=s3
export S3_REGION=us-east-1
export S3_BUCKET=my-semoss-bucket
export S3_ACCESS_KEY='<access-key>'
export S3_SECRET_KEY='<secret-key>'
# export S3_SESSION_TOKEN='<session-token>'
export SEARCH_PATH=semoss-db
export DRY_RUN=true
java -jar target/h2-migration-service.jarIf S3_ACCESS_KEY and S3_SECRET_KEY are omitted, rclone uses the inherited
AWS default credential chain, including EKS/ECS/EC2 role credentials and the
standard AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN
variables.
export MODE=cloud
export BACKUP_DIR=/tmp/h2-backups/minio
export SEMOSS_STORAGE_PROVIDER=minio
export MINIO_ENDPOINT='https://minio.example.com'
export MINIO_REGION=us-east-1
export MINIO_BUCKET=semoss
export MINIO_ACCESS_KEY='<access-key>'
export MINIO_SECRET_KEY='<secret-key>'
export SEARCH_PATH=semoss-db
export DRY_RUN=true
java -jar target/h2-migration-service.jarFor a private CA, mount the certificate and set, for example,
ADDITIONAL_RCLONE_PARAMETERS='--ca-cert /var/run/secrets/minio/ca.crt'.
Mount the service-account JSON as a read-only file and pass its path:
export MODE=cloud
export BACKUP_DIR=/tmp/h2-backups/gcs
export SEMOSS_STORAGE_PROVIDER=gcs
export GCS_BUCKET=my-semoss-bucket
export GCS_REGION=us-east1
export GCS_TRANSFER_BACKEND=gcloud
export GCS_SERVICE_ACCOUNT_FILE=/var/run/secrets/gcp/service-account.json
export SEARCH_PATH=semoss-project
export DRY_RUN=true
java -jar target/h2-migration-service.jarThe gcloud backend uses gcloud storage for listing, metadata, downloads,
uploads, and deletes. The mounted credential path is passed to the child process
through CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE; the JSON contents are never
placed in command arguments, logs, or reports. GOOGLE_APPLICATION_CREDENTIALS
is mapped to the same override when GCS_SERVICE_ACCOUNT_FILE is omitted.
GCS_TRANSFER_BACKEND defaults to rclone for backward compatibility. Set it
to gcloud to avoid rclone entirely for GCS. GCLOUD can override the binary
path and defaults to gcloud. The injected GCS_SERVICE_ACCOUNT_JSON value is
supported only by the rclone backend; use a read-only mounted file with the
gcloud backend.
The normal Azure setup uses a storage connection string:
export MODE=cloud
export BACKUP_DIR=/tmp/h2-backups/azure
export SEMOSS_STORAGE_PROVIDER=azure
export AZ_CONN_STRING='<azure-storage-connection-string>'
export SEARCH_PATH=db-ENGINE_ID
export DRY_RUN=true
java -jar target/h2-migration-service.jarDo not also set AZ_USE_MSI, AZ_ACCOUNT_NAME, or AZ_PRIMARY_KEY; Azure
requires exactly one authentication mode. The connection string is passed to
rclone only through its child-process environment. It is never converted into a
different credential or placed in command arguments, logs, or reports.
The bundled migration image pins rclone v1.75.2, which supports Azure Blob's
direct connection_string configuration. When running the JAR outside the
image, use a connection-string-capable rclone release rather than the older
v1.71.0 client.
Every provider example above is intentionally a read-only dry run. Review
$BACKUP_DIR/migration-report.json, stop every SEMOSS node that can access the
selected storage scope, and then run:
export DRY_RUN=false
export CONFIRM_SEMOSS_STOPPED=true
java -jar target/h2-migration-service.jarRun a separate invocation for semoss-db and semoss-project (on every provider).
Add --dry-run to preview without remote writes. Cloud dry-run still downloads
the selected databases and exact SMSS objects so it can verify H2 headers,
versions, credentials, target classifications, hashes, and planned URL changes.
The JSON report includes each database's targetType, disposition,
credentialSource, runtimeProfile, companion SMSS/backend when applicable,
and configuration warnings. Passwords and concrete runtime URLs are never
written to the report.
Actual cloud runs create a verified remote backup before replacing any source
object. S3, MinIO, and GCS retain backups under
_semoss-h2-migration/<runId>/backup/<semoss-db|semoss-project>/<id>; Azure retains them in the
semoss-h2-migration container. Candidate objects are removed after successful
scope verification, while backups remain until an operator deliberately removes
them. If publication fails after promotion begins, every changed object in that
engine/project scope is restored and hash-verified from the remote backup.
All CLI flags can be set via environment variables (matching Semoss conventions):
| Variable | Description |
|---|---|
MODE |
local or cloud |
DB_DIR |
Local database directory |
BACKUP_DIR |
Backup directory |
DRY_RUN |
true/false |
DEFAULT_USER |
Override for an absent primary SMSS username (default: empty); retained system files without an H2 profile default to sa. Explicit blank SMSS usernames are preserved |
DEFAULT_PASSWORD |
Fallback DB password (default: empty) |
SEARCH_PATH |
Subdirectory within storage root to search |
CONFIRM_SEMOSS_STOPPED |
Required acknowledgement for actual cloud migration |
SEMOSS_STORAGE_PROVIDER |
Cloud provider: s3, azure (also accepts azure_blob), gcs, minio, local_file_system |
S3_REGION, S3_BUCKET, S3_ACCESS_KEY, S3_SECRET_KEY, S3_SESSION_TOKEN |
AWS S3 config; static values are optional when workload identity is available |
AZ_ACCOUNT_NAME, AZ_PRIMARY_KEY, AZ_CONN_STRING |
Azure account/key or connection-string authentication |
AZ_USE_MSI |
Enable Azure managed-identity authentication instead of connection-string or account/key authentication |
GCS_SERVICE_ACCOUNT_FILE, GCS_SERVICE_ACCOUNT_JSON, GCS_BUCKET, GCS_REGION |
GCS credentials and bucket configuration |
GCS_TRANSFER_BACKEND |
GCS transfer implementation: rclone (default) or gcloud |
GCLOUD |
Path to the gcloud binary (default: gcloud) |
MINIO_ENDPOINT, MINIO_REGION, MINIO_ACCESS_KEY, MINIO_SECRET_KEY, MINIO_BUCKET |
MinIO config |
RCLONE |
Path to rclone binary (default: rclone) |
ADDITIONAL_RCLONE_PARAMETERS |
Restricted transport options such as timeouts, retries, and CA certificate configuration |
The container image is meant for cloud mode: a Kubernetes Job that migrates the H2 objects in remote storage before the 6.0.0 rollout. For a local SEMOSS home, use the JAR directly; see Local upgrade runbook.
The image pins its base images (maven:3.9.16-amazoncorretto-21-debian to build,
eclipse-temurin:21.0.12.1_1-jre-resolute (Ubuntu 26.04) to run), bundles rclone
v1.75.2 and gcloud 590.0.1 (on its bundled Python; no system python3),
upgrades the base OS packages at build time, and runs as uid/gid 10001. Override the bases with
--build-arg BUILD_IMAGE=... / RUNTIME_IMAGE=..., keeping both on the Java
release set by maven.compiler.release in pom.xml (21). Any Java 21+ runtime
produces identical files, since the conversion is done by the bundled H2 drivers.
docker build -t h2-migration-service:latest .
# TODO: instructions to pull from the published registryManifests and the step-by-step run order are in deploy/k8s/.
One Job runs every scope in order (SCOPES, default semoss-db semoss-project)
through /app/migrate-all.sh:
- Start with
DRY_RUN=true, read the reports, scale SEMOSS to zero, then rerun withDRY_RUN=falseandCONFIRM_SEMOSS_STOPPED=true. - A scratch
emptyDirat/work(a PVC option is commented injob.yaml) holds download staging (java.io.tmpdir), local backups and one report per scope under/work/<runId>/<scope>/. Staging and local backups are deleted per engine/project once it finishes; a failed one keeps its local backups. Each report is also printed to the Job log between=== BEGIN REPORT <scope>and=== END REPORT <scope>. Durable backups live in the bucket under_semoss-h2-migration/<runId>/backup/<semoss-db|semoss-project>/<id>(Azure:semoss-h2-migration). - A dry run checks every scope; a real run stops at the first failed scope.
Exit code
1(JobFailed) means at least one target failed.
.github/workflows/docker-image.yml runs the unit tests, builds the image,
smoke-tests it (uid, Java 21 JRE, rclone, gcloud, runner script) and pushes
linux/amd64 + linux/arm64 to quay.io/semoss/h2-update-utility (repo
variable IMAGE_NAME overrides). Only main pushes, tagged latest and the
UTC build date (YYYY-MM-DD; a second push that day moves the date tag); pull
requests build without pushing. Needs the QUAY_ROBOT_USERNAME / QUAY_ROBOT_PASSWORD
secrets.
.github/workflows/release.yml runs on a pushed vMAJOR.MINOR.PATCH tag. It
sets the POM version from the tag, runs the unit and integration tests, deploys
the shaded JAR to GitHub Packages, checks that it runs, and creates a GitHub
Release with h2-migration-service.jar and h2-migration-service.jar.sha256.
It uses the built-in GITHUB_TOKEN only. To release, tag a commit on main:
git tag v1.2.0 origin/main
git push origin v1.2.0The pom.xml version on main stays a -SNAPSHOT; bump it after a release.
The image can also migrate a mounted SEMOSS home, though the JAR is the usual
path. Stop SEMOSS first, mount db/ at /data/db and project/ at
/data/project (engines are classified by the folder name, so a db/ mounted
directly at /data reports every user engine as unrecognized), keep the backup
mount outside the database folder, and run as the owner of the files:
docker run --rm --user "$(id -u semoss):$(id -g semoss)" \
-v /opt/semosshome/db:/data/db -v /path/to/backups/db:/backup \
h2-migration-service:latest --mode=local --db-dir=/data/db --backup-dir=/backup --dry-runMigrationConfig ← CLI/env/properties parsing
↓
H2MigrationService ← Orchestrator
├── DatabaseDiscovery ← Local file scan
├── CloudDatabaseDiscovery ← Provider-neutral cloud scan
├── CloudStorageLayout ← Provider-aware SEMOSS scope mapping
├── CloudMigrationCoordinator ← Scope backup/candidate/promotion/rollback
├── H2VersionDetector ← Skip already-migrated DBs
├── SmssCredentialReader ← Read DB credentials from .smss
├── BackupManager ← Backup/restore
├── DatabaseLockProbe ← Refuse files another process holds open
├── MigrationMarker ← In-progress marker for interrupted-run recovery
├── IsolatedH2Driver ← Classloader isolation
│ ├── DatabaseExporter ← SCRIPT TO (H2 1.4.200)
│ └── DatabaseImporter ← RUNSCRIPT FROM (H2 2.4.240)
├── CloudObjectStore ← Provider-neutral storage operations
│ ├── RCloneClient ← S3, MinIO, Azure, and optional GCS transport
│ └── GcloudStorageClient ← GCS-specific gcloud storage transport
└── MigrationReport ← JSON report output
mvn testFor help diagnosing and resolving migration issues, see the H2 Migration Support Guide. It explains common errors, why they occur, how to diagnose them, and how to resolve each issue.
H2 databases hold file locks during operation. All Semoss instances must be stopped before running the migration tool to avoid corruption or lock conflicts. The utility checks each file for a lock just before migrating it and reports a locked file as FAILED without changing it, but it cannot detect a process that opens a file after that check.
Run the tool once against the Semoss db/ directory:
java -jar h2-migration-service.jar \
--mode=local \
--db-dir=/opt/semoss/db \
--backup-dir=/opt/semoss/h2-backupsAll nodes mount the same db/ directory (NFS, shared volume, SAN). Since there is only one copy of each database file, run the migration once from any node:
- Stop all Semoss nodes
- Run the migration from any node with access to the shared filesystem
- Upgrade all nodes to the Semoss version built against H2 2.x
- Start all nodes
Each node has its own db/ directory (e.g. separate Docker volumes). Run the migration on every node:
- Stop Semoss on all nodes
- Run the migration on each node:
This can be automated via Ansible, a Kubernetes Job (one per PV), or an init container that runs before Semoss boots.
# On each node java -jar h2-migration-service.jar \ --mode=local \ --db-dir=/opt/semoss/db \ --backup-dir=/opt/semoss/h2-backups - Upgrade and start all nodes
Semoss cloud clusters can store durable user-engine and project databases in cloud storage (S3/MinIO/Azure/GCS). System databases (security, scheduler, LocalMasterDatabase, UserTrackingDatabase, Notification, etc.) are not cloud migration targets; migrate any local system H2 files with local mode.
This means cloud migration requires two steps:
-
Cloud mode — migrate user engine databases in the bucket:
java -jar h2-migration-service.jar \ --mode=cloud \ --backup-dir=/tmp/h2-backups \ --semoss-storage-provider=s3 \ --s3-region=us-east-1 \ --s3-bucket=my-semoss-bucket \ --search-path=semoss-db \ --confirm-semoss-stopped
-
Local mode on each pod — migrate system databases that only exist locally:
java -jar h2-migration-service.jar \ --mode=local \ --db-dir=/opt/semoss/db \ --backup-dir=/opt/semoss/h2-backups
Use a Kubernetes init container or Job to run this on every pod before Semoss starts.
Full procedure:
- Stop all Semoss pods
- Run separate cloud passes for
semoss-dbandsemoss-projectas applicable; each actual pass requires--confirm-semoss-stopped - Run
--mode=localon each pod to migrate system databases - Upgrade all pods to the Semoss version built against H2 2.x
- Start all pods — each will pull the migrated user engines from cloud storage on boot
After migration, a JSON report is written to {backup-dir}/migration-report.json:
{
"summary": {
"total": 5,
"success": 4,
"failed": 0,
"skipped": 1,
"durationMs": 12345
},
"databases": [...]
}