> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magpiedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Magpie is a trace store for AI agents, used as a library (crate `magpiedb`, npm `magpiedb`, PyPI `magpiedb`) or as `magpie-server`, which takes OpenTelemetry (OTLP over HTTP on 127.0.0.1:4318 and gRPC on 127.0.0.1:4317 by default).
> Use only the commands, flags, routes and JSON shapes that these pages show. Do not guess a flag or a query field: if a page does not show it, say that the docs do not show it.
> Packages and server binaries are not published yet: build from source, as the quick start shows. Check the status note on the introduction page before you suggest `cargo add`, `npm install` or `pip install`.
> Only one process may write to a store folder at a time. For many apps, send traces to one `magpie-server`.

# Import and backup

> Load traces from files with magpie-server import, and back up and restore a store.

## Import

`magpie-server import` loads traces from files into a store: a Magpie export, OTLP/JSON files of the OpenTelemetry Collector's `file` exporter, or LangSmith runs.

> [!WARNING]
>
> **Stop the server first**, or import into a new folder: an import is a writer.

An OTLP/JSON file has one request per line (`jq -c . trace.json` makes one line of a request that is printed on many lines):

```sh theme={null}
cat > old-traces.json <<'EOF'
{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"support-bot"}}]},"scopeSpans":[{"spans":[{"traceId":"5b8efff798038103d269b633813fc60c","spanId":"eee19b7ec3c1b174","name":"chat gpt-4o","startTimeUnixNano":"1764500000000000000","endTimeUnixNano":"1764500002000000000","attributes":[{"key":"gen_ai.operation.name","value":{"stringValue":"chat"}},{"key":"gen_ai.prompt","value":{"stringValue":"Where is my refund?"}}]}]}]}]}
EOF
magpie-server import --dir ./imported --format otlp old-traces.json 2> /dev/null | jq -c '{format, lines, spans, skippedLines, spansInStore, tracesInStore}'
```

```json theme={null}
{"format":"otlp","lines":1,"spans":1,"skippedLines":0,"spansInStore":1,"tracesInStore":1}
```

* Formats: `magpie` (the lines of `POST /v1/export` and `/v1/export/scores`), `otlp`, `langsmith`. A file that ends in `.gz` is read as gzip; `-` is the standard input.
* A bad line is skipped and counted; the first 10 are named in the summary. `--strict` stops at the first one.
* An import is safe to run again: every span replaces the stored span with the same ids. There is no resume: a stopped import starts from the first line again.
* The import writes in time order. So import old traces first, into an empty store, then go live.
* `--prices` and `--mask` work as on the server: give the import the same files.
* Memory (`--memory-mb`, default 1024), disk, and formats in full: [Server reference, "Import old traces"](https://docs.magpiedb.com/reference/server.md).

## Backup

There is no backup command. Two ways work and were run here.

### 1. Export, then import

The server keeps running. The export is the commit of the moment of the request.

```sh theme={null}
magpie-server --dir ./live
```

```sh theme={null}
"$REPO/scripts/send-trace.sh" --url http://127.0.0.1:4318 --count 3 > /dev/null
sleep 2
curl -sN localhost:4318/v1/export -d '{}' > backup-spans.ndjson
curl -sN localhost:4318/v1/export/scores -d '{}' > backup-scores.ndjson
wc -l < backup-spans.ndjson
```

```text theme={null}
9
```

To restore, import both files into an empty folder:

```sh theme={null}
magpie-server import --dir ./restored --format magpie backup-spans.ndjson backup-scores.ndjson 2> /dev/null | jq -c '{spansInStore, tracesInStore}'
```

```json theme={null}
{"spansInStore":9,"tracesInStore":3}
```

### 2. Stop the server, copy the folder

A store folder that no process has open is a whole store. Copy it, and a server opens the copy:

```sh theme={null}
cp -R live live-copy
```

```sh theme={null}
magpie-server --dir ./live-copy
```

```sh theme={null}
curl -s localhost:4318/v1/count -d '{}'
```

```json theme={null}
{"count":9}
```

### What is not tested

* A copy of the folder **while the server writes** is not tested. Do not rely on it: use the export, or stop the server.
* A disk snapshot of the whole volume (for example an EBS snapshot) is not tested either.
* With `--s3`, the bucket is a copy that is at most about 10 s behind ([the S3 guide](https://docs.magpiedb.com/operations/s3.md)).

> [!WARNING]
>
> A backup holds private data. Deletes and purges do not touch it: delete old backups by your own rule.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.