# The store on disk

The record that reports read is kept by the server itself, in plain files of its own in one folder. Nothing has to be installed or looked after for it: no database, no service. This page describes that folder, for whoever backs the server up, plans its disk, or runs a cluster.

This is how every new server keeps its record. For the option of a database of your own, see [The store in your database](Reports-Store-SQL.md).

## Where it is

The folder `activity` in the server's folder, unless **Folder** in [Preferences, Reporting](Prefs-Reporting.md#storage) names another. The [Data](Reports-Data.md) section of the Reports app shows the folder in use.

```
activity/
  node-0/
    LOCK
    manifest.json
    journal/     the newest events, as they arrive
    l0/          events of days that are not closed yet
    seg/         closed days, a folder per kind of data and year
    cube/        the hourly and daily totals
    state/       the counters of the transfer limits
    tmp/         work files, emptied at every start
```

A server writes only inside its own `node-` folder.

## How an event gets there

1. **The journal.** An event is written to the journal first, within a second of happening. This is what survives a power cut.
2. **Memory.** The newest events are also held in memory, so that a report sees them at once.
3. **The day's files.** Every five minutes, or every 100,000 events, what is waiting is written into compact files of the current day, and the part of the journal that is now covered is deleted.
4. **Sealing.** A day that ended more than an hour ago is closed: its files are merged into one set, the totals of the day are merged into the day's and month's totals, and the day is fingerprinted into the integrity chain.

So the newest events are safe after a second, and visible to reports at once.

How much a power cut can lose is the setting **Force to disk**: every second (the usual), after every event, or when the operating system decides.

## What makes it fast

- **Columns, not lines.** A day's file keeps each column together: all user names, then all sizes. A report that counts uploads per user reads two columns and skips the rest.
- **Totals worked out in advance.** Counts and sums per hour and day, by user, folder, protocol and so on, are kept beside the events. A chart over a year reads 365 small totals and not millions of events.
- **Knowing where not to look.** Each file knows which values it holds, so a search for one file name opens only the days that have it.

On a measured server, the top users of all time came back in under a fifth of a second.

## How much room

The Data section lists the room per kind of data. As a rule of thumb from the test server: a login takes under 300 bytes, a file event under 500, a minute's health sample about 200. A server with 100,000 transfers a day so needs some tens of megabytes a day for its events, before the retention removes old days.

Retention works on whole files: a day that is older than its limit is deleted as a file, so removing old data costs nothing.

## Backing it up

- Back the folder up with the rest of the server. It can be copied while the server runs: a file is either complete or not there, and a copy that catches the journal in the middle of a line is read up to that line.
- A restored folder is used as it is. Events between the backup and the restore are missing, and nothing else is wrong.
- For proof against tampering, also keep the **last link of each chain** from the Data section somewhere else: see [Integrity](Reports-Data.md#integrity).

## Moving it

Stop the server, move the folder, set **Folder** in Preferences, Reporting, start the server. The folder setting needs a restart.

## In a cluster

All servers of a cluster use **one** folder, on storage all of them reach, and each has its own **Node number** (0 to 1022) and so its own `node-` folder in it.

- Each server writes only into its own folder and reads all of them. A report on any server shows the events of all, about a second after they happened.
- A server never changes another server's files.
- Two servers with the same node number would write into the same folder. The `LOCK` file prevents it: the second one refuses to start its store.

The shared storage must be one where a rename is all-or-nothing, which ordinary network file systems are.

## When something is wrong

| Sign | Means | Do |
|---|---|---|
| **Dropped** is not 0 in the Data section | events arrived faster than the disk took them, and the oldest waiting ones were thrown away | a faster disk for the folder; look at what else writes there |
| "Reporting is not running" | the store could not be opened: the folder is missing, full, or locked by another process | the reason is shown with it; fix and restart |
| a line in the server log about a damaged journal line | the server stopped uncleanly while writing | nothing: the journal is read up to the damaged line |
| **Verify now** reports a difference | a closed day's file is not what was sealed | restore that day from a backup; find out who touched the folder |
| totals and rows disagree | | **Rebuild rollups** in the Data section |

When events are dropped or the disk fails, the server writes a line `ACTIVITY: …` to its log, and the Data section says so at its top. An alert of the type **Report Store Problem** in [Preferences, Alerts](Prefs-Alerts.md) tells someone: see [The data](Reports-Data.md#things-to-know).

## What it is not

- **Not encrypted.** The files are compact, not secret. Keep the folder where only the server's account reads, and on an encrypted disk if the record must be protected at rest.
- **Not for other programs.** The format is the server's own and may change between versions. Other programs get the data through [exports](Reports-Running.md#export), [schedules](Reports-Schedules.md), the [API](API-Reports.md), or the [database option](Reports-Store-SQL.md).
