# Historian store API

> GET /api/historian/store (the check of the store file, the last set-aside and the restore command) and POST /api/historian/store/sign and /set-aside - the routes behind System Health's "Set the store aside…", for a signed-in administrator only, with the historian_store_set_aside e-signature, the 409 and 503 refusals and the HISTORIAN_STORE_SET_ASIDE audit records; and POST /api/historian/store/repair/check, /repair/sign and /repair, the repair of a file a checkpoint cut short (HISTORIAN_STORE_REPAIRED).

Product: eaxScada · Type: Reference · Editions: Starter, Pro, Enterprise
Source: https://eaxware.com/docs/eaxscada/reference/historian-store-api/
Verified against commit f6011fa.

The routes behind **System Health > Historian storage > Set the store aside…** and **How to restore…**. How to use them: [When the historian store file does not open](/docs/eaxscada/how-to/when-the-historian-store-file-does-not-open/).

## Who may call them

- **A signed-in Administrator, in a login session.** `401` without a session; `403` for a user who is not an Administrator, for an API token and for the AI co-pilot account.
- **Never over remote access.**
- **Builds with the embedded database**, stores without encryption at rest (an encrypted store that does not open stops the server).

| Method | Path | What it does |
|---|---|---|
| GET | `/api/historian/store` | Checks the store file now; the last set-aside; the newest snapshot and the restore command. |
| POST | `/api/historian/store/sign` | Signs a set-aside with the password and a reason: a one-time ticket. |
| POST | `/api/historian/store/set-aside` | Renames the broken store file aside and opens a new empty store. |
| POST | `/api/historian/store/repair/check`, `/repair/sign`, `/repair` | Repair a store file a checkpoint cut short, ahead of the set-aside: [below](#repair-a-file-a-checkpoint-cut-short). |

`GET /api/historian/storage` tells you when to look: its `status.spool` carries `set_aside_offered` (true while the store did not open at start and has not opened since) and `set_aside` (the last set-aside, until a snapshot restore).

## GET /api/historian/store

The check runs on each call. A file that opens when checked is taken back at once (state `opens_now`), and the points waiting are written to it.

```json
{
  "node": "node-scada-20601",
  "decision": "historian_store_set_aside",
  "repair_decision": "historian_store_repair",
  "diagnosis": {
    "state": "broken",
    "file": "scada_history.duckdb",
    "size": 3158016,
    "mod_time": "2026-11-10T19:54:09.20+01:00",
    "wal": true,
    "wal_size": 5370,
    "store_file": true,
    "error": "IO Error: Corrupt database file: computed checksum 7256887794307355693 does not match stored checksum 16225778114284398330 in block at location 4096",
    "why": "the store file is damaged: it does not open; it is not locked by another process and can be read",
    "hash": "ce94398ca03a...",
    "offered": true,
    "spool_points": 27,
    "spool_bytes": 2249,
    "checked_at": "2026-11-10T19:54:25.22+01:00"
  },
  "meaning": "Set the historian store file scada_history.duckdb (3.0 MB, a damaged store file; it does not open: IO Error: ...) and its .wal (5 kB) of node node-scada-20601 aside as scada_history.broken-.duckdb, kept and never deleted, and start a new empty store that the 27 points waiting are written to. The history before it is not in the new store until a snapshot is restored (diagnosis ce94398ca03a)",
  "set_aside": null,
  "latest_snapshot": "historian-20261110T185348Z.duckdb",
  "restore_command": "eaxscada historian-restore --snapshot \"G:\\eaxscada\\data\\backup\\historian\\historian-20261110T185348Z.duckdb\" --keep-current --confirm",
  "docs": "https://eaxware.com/docs/eaxscada/explanation/historian/#restore-from-a-snapshot"
}
```

| Member | Meaning |
|---|---|
| `node` | This server's node id. |
| `decision` | The set-aside's e-signature decision: always `historian_store_set_aside`. |
| `repair_decision` | The repair's e-signature decision: always `historian_store_repair` (new, an added member). |
| `diagnosis.state` | `broken` (not locked, readable, and it does not open: the only state a set-aside is offered in), `locked` (another process holds the file: not damaged), `unreadable` (eaxScada may not open it for reading and writing, or could not check it), `opens_now` (it opened: taken back), `missing` (no store file at the path), `not_offered` (the store did not fail to open at start), `ok` (the store is open). |
| `diagnosis.file`, `size`, `mod_time` | The store file's name (the folder is the install's), its size and modification time. |
| `diagnosis.wal`, `wal_size` | A write-ahead log (`.wal`) is next to it, and its size: it is set aside with the file. |
| `diagnosis.store_file` | The file's header is a store's: `true` for a store whose blocks are damaged, `false` for a file that is not a store file. |
| `diagnosis.error` | The store's open error, short. |
| `diagnosis.lock_pid` | Linux: the process holding the lock. |
| `diagnosis.why` | The explanation shown in the dialog. |
| `diagnosis.hash` | What a set-aside signs: the file, its size and time, the state and the open error. |
| `diagnosis.offered` | A set-aside may go ahead (state `broken`). |
| `diagnosis.spool_points`, `spool_bytes` | The points waiting in the spool, written to the new store, and their size on disk. |
| `diagnosis.checked_at` | When the check ran. |
| `diagnosis.repair` | Whether the file can be repaired instead: [below](#diagnosisrepair-in-get-apihistorianstore). |
| `meaning` | The text an administrator signs for a set-aside. Only when `offered`. |
| `repair_meaning` | The text an administrator signs for a repair. Only when `diagnosis.repair.state` is `verified`. |
| `set_aside` | The last set-aside, or `null`: `at`, `by`, `reason`, `broken_file`, `broken_wal`, `size`, `error`. It stays until a snapshot restore. |
| `latest_snapshot` | The newest nightly snapshot's file name ("" when none). After a set-aside, the newest made **before** it. |
| `restore_command` | `eaxscada historian-restore --snapshot "<full path of that snapshot>" --keep-current --confirm`. Run it with the server stopped, first without `--confirm` (a dry run). |
| `docs` | The documentation of the restore. |

## POST /api/historian/store/sign

```json
{"password": "<your password>", "reason": "store file damaged after a power cut", "hash": "<diagnosis.hash>"}
```

The file is checked again. The answer is a one-time ticket, valid 60 seconds, over the reference `historian-store:<node>:set-aside`, that check and the reason, and the decision `historian_store_set_aside` (which signs these references only, and they are signed with no other decision):

```json
{"ticket": {"ticket": "eso_...", "expires_at": "...", "object": "historian-store:<node>:set-aside", "hash": "...",
            "decision": "historian_store_set_aside", "meaning": "Set the historian store file scada_history.duckdb (...) aside ...; reason: ..."}}
```

## POST /api/historian/store/set-aside

```json
{"hash": "<diagnosis.hash>", "reason": "<the reason signed>", "signature_ticket": "<ticket.ticket>"}
```

1. The file is checked again: it must still be `broken` with the hash signed.
2. The ticket is redeemed for exactly that check and reason, by the administrator it was issued to.
3. Under the import's and the snapshot's locks, and with the store's writes held: the check runs once more, then the disk is checked.
4. `HISTORIAN_STORE_SET_ASIDE` is written to the audit trail, with the signature, the file, its size, time, write-ahead log, header and open error, and the new name. If it cannot be written, nothing changes (`503`).
5. The file is renamed to `scada_history.broken-.duckdb`, its `.wal` to `….duckdb.wal`. Nothing is deleted or overwritten; if the `.wal` cannot be renamed, the store file is put back.
6. A new empty store opens at the old place; the spool drains into it in order. The record `scada_history.set-aside.json` is written in the historian folder.

Answer:

```json
{
  "status": "set_aside",
  "set_aside": {
    "at": "2026-11-10T18:55:29.74Z",
    "by": "admin",
    "reason": "store file damaged after a power cut",
    "broken_file": "scada_history.broken-20261110T185529Z.duckdb",
    "broken_wal": "scada_history.broken-20261110T185529Z.duckdb.wal",
    "size": 3158016,
    "error": "IO Error: Corrupt database file: ..."
  },
  "latest_snapshot": "historian-20261110T185348Z.duckdb",
  "restore_command": "eaxscada historian-restore --snapshot \"G:\\eaxscada\\data\\backup\\historian\\historian-20261110T185348Z.duckdb\" --keep-current --confirm",
  "docs": "https://eaxware.com/docs/eaxscada/explanation/historian/#restore-from-a-snapshot"
}
```

## Refusals

| HTTP | `status` | When |
|---|---|---|
| `400` | `reason_required` | No reason, over 500 characters, or more than one line. |
| `400` | `signature_required` | set-aside without a `signature_ticket`. |
| `401`, `403` | | Not a signed-in administrator, an API token, the AI co-pilot. |
| `403` | `signature_refused` | A wrong password (sign); a ticket unknown, expired, used, made for another check or reason, or issued to another user (set-aside). `429` when the account is locked. |
| `409` | `locked` | The file is in use by another process: not damaged. The answer carries the `diagnosis`. |
| `409` | `unreadable` | eaxScada may not open the file for reading and writing, or could not check it. |
| `409` | `opens_now` | The file opened when checked: it is used again. |
| `409` | `missing` | No store file at the path. |
| `409` | `not_offered` | The store did not fail to open at start, or is open. |
| `409` | `changed` | The file or its check changed since it was shown (the answer carries the new `diagnosis`): review it and sign again. |
| `409` | `busy` | A CSV history import call or a historian snapshot is in progress. |
| `409` | `low_disk` | Free space is under about twice the spool's size plus 256 MB, plus `historian.disk.critical_free`. |
| `503` | `refused`, code `AUDIT_NOT_WRITTEN` | The audit record could not be written. Nothing changed. |
| `500` | `failed` | Another error, for example a rename that failed (nothing changed: the message says so). |

A signed set-aside that did not go ahead after its ticket was redeemed is recorded as `HISTORIAN_STORE_SET_ASIDE_REFUSED` with the error.

## Repair a file a checkpoint cut short

A store file a checkpoint cut short (a power loss or a killed process during a checkpoint) does not open although its data is intact: one metadata block's checksum is wrong. Ahead of the set-aside, such a file can be repaired: a copy is checked and verified, and an administrator, e-signed, puts it in place. The original is kept. Nothing is ever repaired automatically; an encrypted store is never repaired. System Health has no Repair button yet: it follows in a later release. How to use the routes: [Repair a file a checkpoint cut short](/docs/eaxscada/how-to/when-the-historian-store-file-does-not-open/#2a-repair-a-file-a-checkpoint-cut-short).

The same rules as the set-aside: a signed-in Administrator in a login session, never an API token, the AI co-pilot or remote access.

| Method | Path | What it does |
|---|---|---|
| POST | `/api/historian/store/repair/check` | Starts the check of a copy (`202`). Nothing is swapped, so it needs no signature. |
| POST | `/api/historian/store/repair/sign` | Signs the verified repair with the password and a reason: a one-time ticket. |
| POST | `/api/historian/store/repair` | Puts the verified copy in place of the store file, the original kept. |

### `diagnosis.repair` in GET /api/historian/store

Present while the diagnosis is `broken`:

| Member | Meaning |
|---|---|
| `state` | `candidate` (the quick rules hold on the file, only read: a check may be started), `checking` (a copy is being made, checked block by block and verified), `verified` (the copy verified: the repair is offered), `refused` (the copy did not pass or did not verify: only the set-aside), `not_repairable` (not a checkpoint cut short: only the set-aside). |
| `why` | The explanation, or the rule that refused. |
| `evidence` | The file's evidence: `location` and `block_id` of the block with the wrong checksum, `stored_checksum`, `computed_checksum`, the header in force, the block count and the metadata and free-list chains. |
| `verification` | Once checked: `tables` (each read to its end), `rows`, `checks` (the per-day row counts against the latest snapshot, or "no snapshot to compare with") and `summary`. |
| `diagnosis_hash` | The diagnosis the check was made for. A new diagnosis (a changed file) drops the check and its copy, as do a set-aside and the store opening. |
| `original_sha256`, `wal_sha256`, `repaired_sha256` | The SHA-256 of the original, its write-ahead log and the repaired copy. |
| `candidate` | The repaired copy's file name, next to the store (`scada_history.repair-.duckdb`). |
| `hash` | What a repair signs. Only when `verified`. |
| `started_at`, `finished_at` | When the check ran. |

When `repair.state` is `verified`, the answer adds **`repair_meaning`**, the text an administrator signs: the file, its size, the block's location, the node, the repaired copy's SHA-256 and verification, and the original's new name and SHA-256.

**The per-day comparison.** No day the latest snapshot holds may have fewer rows in the copy, except days older than the copy's first day (a retention purge since the snapshot) and that first day itself. With no snapshot, the comparison is skipped and `checks` says so.

### POST /api/historian/store/repair/check

```json
{"hash": "<diagnosis.hash>"}
```

The diagnosis must be `broken` with that hash and `repair.state` `candidate`. The store and its `.wal` are copied next to it, the copy is classified by every rule, its one checksum is recomputed, and the patched copy is opened read-only and verified. The answer is `202` with `{"status": "checking", "repair": {...}}`; read `GET /api/historian/store` for the result. A repair already `verified` is answered with its state. The copy needs free space for the file and its `.wal` plus 256 MB, above the disk guard's critical line.

The patched copy and the snapshot it is compared with are read in a separate process of the eaxScada program (a hidden subcommand the server starts itself, not for use by hand), read only, one file at a time, each for at most 6 hours. A crash, a hang past that bound, an error exit or an answer that is missing or about another file refuses the repair (`refused`, with the reason in `why`); the server keeps running.

A copy left by a restart during a check (`scada_history.repair-.duckdb` and its `.wal`) is deleted at the next start, by that exact name pattern and in the store's folder only, and each deletion is logged. The kept originals (`scada_history.torn-*`) and every other file stay.

At start, a store that does not open is classified by the quick rules at once: the log has a warning "historian store at start: may be repairable (a checkpoint cut short)" naming these routes, or an information line that it is not repairable.

### POST /api/historian/store/repair/sign

```json
{"password": "<your password>", "reason": "store file torn by a power cut", "hash": "<diagnosis.repair.hash>"}
```

The answer is a one-time ticket over the reference `historian-store:<node>:repair`, the verified repair and the reason, with its own decision `historian_store_repair`. The repair's ticket has its own decision, reference and hash domain: a set-aside ticket does not repair, and a repair ticket does not set aside. A ticket issued by an earlier release for a repair, under the set-aside's decision, is refused.

### POST /api/historian/store/repair

```json
{"hash": "<diagnosis.repair.hash>", "reason": "<the reason signed>", "signature_ticket": "<ticket.ticket>"}
```

1. The diagnosis must still be `broken` with a `verified` repair of that hash.
2. The ticket is redeemed for exactly that repair and reason, by the administrator it was issued to.
3. With the store's writes held: the original and the copy are checked again (size, time, the same wrong block), and nothing is overwritten.
4. The journal `scada_history.torn-.duckdb.repair.json` is written (both SHA-256, the block, the verification).
5. `HISTORIAN_STORE_REPAIRED` is written to the audit trail, with the signature, the file, its size, time and open error, the block's location, the verification, and the original's and the repaired copy's SHA-256 (and the `.wal`'s). If it cannot be written, the journal is removed and nothing changes (`503`).
6. The original and its `.wal` are renamed to `scada_history.torn-.duckdb` (`.wal`), kept, never deleted; the copy and its `.wal` take their place. The store opens (or at the next retry), its write-ahead log replays, and the spool drains into it.

Answer:

```json
{
  "status": "repaired",
  "repaired": {
    "at": "...",
    "by": "admin",
    "reason": "store file torn by a power cut",
    "kept": "scada_history.torn-.duckdb",
    "journal": "scada_history.torn-.duckdb.repair.json",
    "original_sha256": "...",
    "repaired_sha256": "...",
    "location": 4096,
    "verification": "<the verification summary>"
  },
  "docs": "..."
}
```

### Refusals of the repair

| HTTP | `status` | When |
|---|---|---|
| `400` | `reason_required` | No reason, over 500 characters, or more than one line (sign, repair). |
| `400` | `signature_required` | repair without a `signature_ticket`. |
| `401`, `403` | | Not a signed-in administrator, an API token, the AI co-pilot. |
| `403` | `signature_refused` | A wrong password (sign); a ticket unknown, expired, used, made for another repair or reason, or issued to another user (repair). |
| `409` | `locked`, `unreadable`, `opens_now`, `missing` | As for the set-aside: the file is not `broken` now. |
| `409` | `not_offered` | The store did not fail to open at start, or the repair is `not_repairable` or `refused` (check). |
| `409` | `not_verified` | No verified repair for this file: check a copy first (sign, repair). |
| `409` | `changed` | The file, the copy or the hash changed since it was shown (the answer carries the new `diagnosis` where there is one): check again and sign again. |
| `409` | `busy` | A check of a copy is running, a CSV history import call or a historian snapshot is in progress. |
| `409` | `low_disk` | Not enough free space for the copy (check). |
| `503` | `refused`, code `AUDIT_NOT_WRITTEN` | The audit record could not be written, or there is no audit trail. Nothing changed. |
| `500` | `failed` | Another error (the message says what). |

A signed repair that did not go ahead after its ticket was redeemed is recorded as `HISTORIAN_STORE_REPAIR_REFUSED` with the error.
