---
title: "Import log files"
description: "Load existing Pino JSON or NDJSON files into an index offline."
---

> Documentation Index
> Fetch the complete documentation index at: https://sandrinodm.github.io/logbrook/llms.txt
> Use this file to discover all available pages before exploring further.

# Import log files

`logbrook import` loads events from a file straight into a data directory. Unlike HTTP ingestion, it accepts events older than the retention window, so use it to backfill history or migrate logs you already have on disk.

> **Stop the server first**
>
> Import opens the data directory itself, and only one process can own a data directory. Stop the Logbrook server that uses it before you import.

## File format

The file holds events in the same shape as [HTTP ingestion](https://sandrinodm.github.io/logbrook/send-logs/http/#event-fields): each needs `time` (Unix milliseconds), `level` (integer) and `msg` (string).

| Format | Flag | Contents |
| --- | --- | --- |
| JSON | none | One nonempty JSON array of event objects. It must fit within the body limit (1 MiB by default). |
| NDJSON | `--ndjson` | One event object per line. Blank lines are skipped. The file is streamed in bounded batches. |

Use NDJSON for large files. A JSON file over the body limit fails with `JSON import exceeds body limit; use batched NDJSON`. An NDJSON line longer than the event limit (64 KiB by default) also fails.

## Run an import

1. **Stop the server**

   Stop the process or container that uses the data directory.
2. **Set retention to cover the history**

   Retention works on event time. Set it to cover the imported history before you start the server again, or the events expire. See [indexes and retention](https://sandrinodm.github.io/logbrook/configure/indexes-and-retention/).
3. **Import the file**

   Use the same config file or environment variables as the server:

   ```sh
   logbrook --config logbrook.toml --index payments import events.ndjson --source checkout --ndjson
   ```

   For a JSON array:

   ```sh
   logbrook --config logbrook.toml --index payments import events.json --source checkout
   ```

   On success the command prints the number of events committed:

   ```text
   { "imported": 1250 }
   ```
4. **Start the server and check**

   Start the server again and count the events:

   ```sh
   logbrook count payments --since 30d --source checkout
   ```

   For history older than that, pass `--from` and `--to` instead. One query spans at most 31 days by default, so count longer history in adjacent windows.

## Options

| Option | Meaning |
| --- | --- |
| `<file>` | Path of the JSON or NDJSON file. |
| `--source <name>` | Required. The `source` stored on every imported event, in place of the one an ingestion token would set. 1 to 128 ASCII letters, digits, `-`, `_` or `.`. |
| `--ndjson` | Read the file as NDJSON instead of one JSON array. |
| `--index <name>` | Global option. Destination index, `default` if omitted. The index is created if it doesn't exist. |
| `--config <file>` | Global option. The server's TOML file. |

A new index still counts against `max_indexes`, and the command fails if creating it would exceed the limit.

## Failures and retries

Each batch commits on its own. If a later batch is invalid or the process stops, earlier batches stay in the index. Rerunning the whole import then stores them a second time, because Logbrook doesn't deduplicate.

For a clean retry, import into a new data directory. The `{ "imported": N }` line is printed only after a complete run, so for a failed run use the error message: an over-long NDJSON line reports how many events were already committed.

## Next steps

- [Send logs over HTTP](https://sandrinodm.github.io/logbrook/send-logs/http/) — Live ingestion for new events.
- [Indexes and retention](https://sandrinodm.github.io/logbrook/configure/indexes-and-retention/) — Set retention to cover imported history.
- [Archives and migration](https://sandrinodm.github.io/logbrook/operate/archives-and-migration/) — Archive and move data offline.

Source: https://sandrinodm.github.io/logbrook/send-logs/import-files/index.mdx
