Skip to content

BrainAPI is a knowledge graph–powered AI memory layer that transforms unstructured data into structured knowledge, enabling intelligent search, recommendations, and contextual memory for AI agents and applications.

Let Neo4j dump as root so the host backup directory is writable.

Christian283fd73dde65
diff --git a/.github/workflows/heavy-validation.yaml b/.github/workflows/heavy-validation.yaml
index 1499396..9d94f19 100644
--- a/.github/workflows/heavy-validation.yaml
+++ b/.github/workflows/heavy-validation.yaml
@@ -168,7 +168,10 @@ jobs:
- name: Backup and verify
id: backup
run: |
+ set -euo pipefail
archive=$(deploy/brainapi-backup backup --profile heavy --project-name brainapi-heavy-ci --env-file deploy/env.heavy.example --compose-file deploy/docker-compose.ci.yaml --backup-dir "$BACKUP_DIR" | tail -1)
+ test -d "$archive"
+ test -f "$archive/manifest.json"
deploy/brainapi-backup verify --profile heavy --env-file deploy/env.heavy.example --archive "$archive"
cp "$archive/manifest.json" "$RELEASE_ARTIFACT_DIR/backup-heavy-manifest.json"
echo "archive=$archive" >> "$GITHUB_OUTPUT"
diff --git a/deploy/backup_restore.py b/deploy/backup_restore.py
index 95aa880..f29cc58 100755
--- a/deploy/backup_restore.py
+++ b/deploy/backup_restore.py
@@ -243,6 +243,35 @@ def _restore_postgres_brain_databases(
)
+def _neo4j_admin(stack: Stack, volume: str, args: list[str]) -> None:
+ result = stack.run(
+ [
+ "run",
+ "--rm",
+ "--no-deps",
+ "--user",
+ "0",
+ "--entrypoint",
+ "neo4j-admin",
+ "-v",
+ volume,
+ "neo4j",
+ *args,
+ ],
+ capture=True,
+ check=False,
+ )
+ output = ((result.stdout or "") + (result.stderr or "")).strip()
+ if output:
+ print(output, file=sys.stderr)
+ if stack.dry_run:
+ return
+ if result.returncode != 0:
+ raise RuntimeError(
+ f"neo4j-admin {' '.join(args)} failed ({result.returncode}): {output or 'no output'}"
+ )
+
+
def _archive_volume(stack: Stack, key: str, destination: Path) -> None:
if stack.dry_run:
stack.docker(["run", "--rm", "-v", f"{stack.volume_name(key)}:/source:ro", ARCHIVER_IMAGE, "tar", "-C", "/source", "-czf", "-", "."])
@@ -360,10 +389,18 @@ def backup(stack: Stack, backup_root: Path) -> Path:
stack.run(["exec", "-T", "redis", "sh", "-c", 'redis-cli -a "$REDIS_PASSWORD" SAVE'])
stack.run(["stop", "neo4j", "mongo", "milvus", "etcd", "minio", "redis"])
neo_dir = destination / "neo4j"
- neo_dir.mkdir(mode=0o700)
+ neo_dir.mkdir(mode=0o777)
for database in ("system", "neo4j"):
- stack.run(
- ["run", "--rm", "--no-deps", "-v", f"{neo_dir}:/backup", "neo4j", "neo4j-admin", "database", "dump", database, "--to-path=/backup", "--overwrite-destination=true"]
+ _neo4j_admin(
+ stack,
+ f"{neo_dir}:/backup",
+ [
+ "database",
+ "dump",
+ database,
+ "--to-path=/backup",
+ "--overwrite-destination=true",
+ ],
)
if not stack.dry_run:
subprocess.run(["tar", "-C", str(neo_dir), "-czf", str(destination / "neo4j.dumps.tar.gz"), "."], check=True)
@@ -444,7 +481,17 @@ def restore(stack: Stack, backup_dir: Path) -> None:
if not stack.dry_run:
subprocess.run(["tar", "-C", str(tmp_path), "-xzf", str(backup_dir / "neo4j.dumps.tar.gz")], check=True)
for database in ("system", "neo4j"):
- stack.run(["run", "--rm", "--no-deps", "-v", f"{tmp_path}:/backup:ro", "neo4j", "neo4j-admin", "database", "load", database, "--from-path=/backup", "--overwrite-destination=true"])
+ _neo4j_admin(
+ stack,
+ f"{tmp_path}:/backup:ro",
+ [
+ "database",
+ "load",
+ database,
+ "--from-path=/backup",
+ "--overwrite-destination=true",
+ ],
+ )
stack.run(["up", "-d", "--wait", "mongo"])
mongo_user = stack.env.get("MONGO_USERNAME", "brainapi")
if stack.dry_run:
diff --git a/tests/test_deploy_production_contract.py b/tests/test_deploy_production_contract.py
index 1720183..ba29387 100644
--- a/tests/test_deploy_production_contract.py
+++ b/tests/test_deploy_production_contract.py
@@ -129,6 +129,14 @@ def test_light_backup_includes_per_brain_postgres_databases():
assert "brain_*.dump" in source
+def test_heavy_neo4j_dump_runs_as_root_with_admin_entrypoint():
+ source = (DEPLOY / "backup_restore.py").read_text(encoding="utf-8")
+ assert '"--user"' in source
+ assert '"0"' in source
+ assert '"--entrypoint"' in source
+ assert '"neo4j-admin"' in source
+
+
def test_recommendation_openapi_surface_is_preview():
from src.services.api.app import app