---
title: "Archives, retention and backups"
description: "How events move from DuckDB to Parquet, when retention deletes them, and what a backup is."
---

> 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.

# Archives, retention and backups

Each index keeps recent events in DuckDB and moves older ones into Parquet files. Events leave an index when they pass its retention period or when the index reaches its disk-size target.

## The lifecycle of an event

Every index runs a maintenance pass at startup and then every `maintenance_interval_secs` (60 seconds by default). A pass runs these jobs in order:

| Job | What it does |
| --- | --- |
| Retain | Expires events older than the retention window. |
| Enforce size | When the index has a [disk-size target](#disk-size-targets) and is over it, expires the oldest events. It runs again at the end of the pass. |
| Archive | Moves hot events older than `archive_after_ms` from DuckDB into Parquet files. Archiving does not delete anything. |
| Compact | Merges small Parquet files in the same time partition into larger ones. |

All of these work on **event time**. By default an event stays in DuckDB for about a day, then lives in an archive until retention expires it.

### Archives

An archive is a Parquet file of older events. Archived events stay searchable: a query reads the hot rows and the relevant Parquet files together. See [search and live tail](https://sandrinodm.github.io/logbrook/concepts/search-and-tail/).

Archives are partitioned by event time, one hour per partition by default (`storage.archive_partition_ms`). A manifest inside the index database records each archive's time range and size. Manifest paths are relative to the data directory, so you can move a complete data directory.

Archive files live in the index's `archives/` directory. Keep other files out of it: at startup, Logbrook removes `.tmp` files and any `.parquet` file the manifest doesn't reference. A missing archive file, or one with an unexpected size, is an integrity failure that makes the server unready.

## Retention

Retention is how long an index keeps events, measured against event time. The default is 7 days, and you can override it per index.

Expiry and file deletion are separate:

- An expired event disappears from queries immediately.
- An archive file is deleted only when every event in it has expired. A partly expired file stays on disk and is not rewritten.
- The expiry cutoff is stored and only moves forward. Live ingestion rejects events older than it.

Retention must be longer than the archive age. For one-day retention, also shorten `archive_after_ms`, for example to one hour.

### Changing retention

A policy change takes effect on the first maintenance pass after a restart.

- A **shorter** retention can expire existing events on that pass.
- A **longer** retention never restores events that already expired, so lengthen it before you need it.

## Disk-size targets

An index can also have a disk-size target. When the index reaches it, Logbrook expires the oldest events before they reach the age limit.

The target is measured, not reserved. It counts the database, the write-ahead log, archive files (including ones that running queries still hold), spill files and other files Logbrook owns in the index directory.

When an index is at or over its target, maintenance:

1. Reclaims space from the write-ahead log.
2. Expires the oldest archives, once queries have released them.
3. Expires hot rows if no archives remain.

While the index is at its target, ingestion returns `507`. Writes resume once space is reclaimed, or after you raise the target and restart.

> **The size target is not a hard quota**
>
> Writes in flight, compaction, exports and query spill can briefly exceed the target. DuckDB reuses freed space inside its database file but does not shrink the file, so the footprint may stay above the target after events expire. Monitor free disk space separately. If you need a hard limit, use a filesystem or volume quota.

Both limits apply per index: a 20 GB target gives each index its own 20 GB, not a share of it.

## Backups

A backup is a copy of the whole data directory, taken while the server is stopped. It must include:

- the DuckDB files and any write-ahead log
- the archive manifest, which lives inside the DuckDB database
- all Parquet archive files

Neither the archive files nor the database alone hold all retained data. Don't copy a live data directory with a plain recursive copy, and don't treat `.index-trash/` as a backup. See [Back up and upgrade](https://sandrinodm.github.io/logbrook/operate/backup-and-upgrade/) for the procedure.

## Next steps

- [Indexes and retention](https://sandrinodm.github.io/logbrook/configure/indexes-and-retention/) — Set retention, archive age and size targets.
- [Back up and upgrade](https://sandrinodm.github.io/logbrook/operate/backup-and-upgrade/) — Copy, restore and upgrade a data directory.
- [Archives and migration](https://sandrinodm.github.io/logbrook/operate/archives-and-migration/) — Offline archive and import commands.

Source: https://sandrinodm.github.io/logbrook/concepts/archives-and-retention/index.mdx
