---
title: Data and privacy
description: What a self-hosted Peal keeps for the law, how deletions survive a restored backup, and the privacy declaration.
sidebar:
  icon: shield
---

You decide whether your server keeps data for French law, set up the ledger that keeps deletions through a restored backup, and declare what each user's data export says about you.

## Legal retention [#legal-retention]

French law has a host keep the data that identifies whoever contributed content, so that a judicial authority can ask for it (loi n° 2004-575, Article 6, V, and décret n° 2021-1362). Peal can do it, but doesn't by default: `PEAL_LEGAL_RETENTION` is `false` unless you set it.

Which value you need depends on your server:

| Your server                                                                                                                                                                                       | `PEAL_LEGAL_RETENTION` | Why                                                                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | ---------------------------------------------------------------------------------------------- |
| Both are true: you're established in France, or offer your Peal to people there, and your Peal stores content for other people (customers, clients, the public, anyone but your own organisation) | `true`                 | Not keeping the data is an offence (the same Article 6, V, B)                                  |
| Everyone else, such as a team that runs Peal for its own posts, or an operator with no tie to France                                                                                              | `false`                | Data protection law (GDPR, Article 5(1)(c)) forbids keeping this data without an obligation to |

> **The law may apply once others use your server**
>
> Ask a lawyer before you open your server to others.

### What it keeps [#legal-records]

Records go in the `legal` schema, which nothing else in the server reads:

| Record                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | Kept                          |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
| Each request that creates, changes or deletes content (posts, articles, signatures, comments, messages, approvals, the feeds and rules that publish for a workspace, the times a queue gives its posts, and media files and their descriptions, whether uploaded, made from a prompt or composed from the workspace's files), through the web app, an API key, the command line or an MCP client: when, from which address (read as sign-in reads it, from `AUTH_IP_HEADERS`), over which protocol and how it signed in. Never what the request carried. | 1 year |
| When an account closes, its holder's name and email address                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | 5 years    |
| When an account closes, how they signed in (each sign-in method's identifier, never the password or its hash) and their Stripe customers                                                                                                                                                                                                                                                                                                                                                                                                                 | 1 year     |
| Each answer staff give to a legal request                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | 5 years |

A daily job (`legal.retention`, at 03:47 UTC) deletes each record once its time is up. Staff read these records only by answering a legal request in the [staff console](/self-hosting/staff#legal-requests), and each answer is recorded.

Each user's export lists their connections and what closing their account would leave. Your own privacy notice should say that you keep them.

When it's off, the server writes nothing to the `legal` schema, and closing an account erases everything.

### Turn it off later [#legal-retention-off]

Turning it off after it was on keeps nothing more, and deletes nothing at once. What the server already holds stays until its time is up, because the law had you keep it for that long, and the daily job goes on deleting it. Meanwhile, staff with the legal role can still answer a request about it, and each user's export still lists the connections kept about them.

## Deletions and backups [#erasure-ledger]

A backup holds what was deleted after it was taken. Restoring one brings back the accounts and workspaces their users deleted since, and the law has you delete them again before anyone can use them.

Peal keeps what that takes outside the database, because a restore would rewind the database too. Each time a workspace is deleted or an account closed, the server writes a small entry in the object store, under `erasures/`. It holds the ids and the time and nothing else (no name, address or content).

The entry is written before the deletion is final, so none goes unrecorded. When the store can't be reached, the deletion is refused and can be tried again.

### After a restore [#replay]

A restored database doesn't know what was deleted since the backup, but the ledger does.

> **Apply the ledger before you start a restored server**
>
> After any restore, apply it again before the server starts, or the accounts
> and workspaces deleted since the backup come back.

Run one of these commands:

```sh With Compose
docker compose … run --rm --no-deps server packages/peal-server/src/replay-erasures.ts
```

```sh From a checkout
bun nx run peal-server:erasures:replay
```

Here's what it does, and when it stops:

- It deletes again whatever the restore brought back, and prints what it did by id. You can run it again without harm, because what's gone stays gone.
- It cancels nothing at Stripe and emails no one, as both were done when the deletion first ran.
- A deletion that's refused, such as a post going out, makes it exit with an error. Keep the server stopped until it passes.
- An entry the server never confirmed, because it stopped in the middle of a deletion, is listed and left alone. `--apply-unconfirmed` applies those too, once you've decided each was asked for.

### Where the ledger lives [#ledger-bucket]

The ledger lives in the media bucket by default. Nothing there is served, because the server signs no link to `erasures/`.

If your media bucket is public (`PEAL_MEDIA_PUBLIC_BASE_URL`), name a private bucket with `PEAL_ERASURE_LEDGER_BUCKET`, on the same store and reachable with the same key. The server warns at startup until you do.

> **Don't use your backups' bucket**
>
> A server that can write there can delete the backups.

Entries are kept 42 days. That's a little longer than the backups hold deleted data (5 weeks with the stack's four weekly full backups). A daily job (`workspace.erasure-ledger-retention`, at 04:17 UTC) drops older entries. Keep your backups shorter than that.

### Add a lifecycle rule [#ledger-lifecycle]

Where the store has lifecycle rules, add one as a second guard, on the ledger's bucket or its prefix alone. With Cloudflare R2:

```sh
wrangler r2 bucket lifecycle add <bucket> expire-erasures erasures/ --expire-days 42
```

> **Check the prefix before you save the rule**
>
> A rule that names the wrong prefix would delete your media.

## Privacy declaration [#privacy-declaration]

Each user can download a copy of their data (**Profile**, **Your data**, or `peal account export`). With it comes what the GDPR, Article 15, has a controller tell them:

- For each category of data, what it's for, on which legal basis, how long it's kept and where it came from.
- Who receives it.
- The rights over it.

Peal writes most of it from one registry in its code. Its own privacy policy's retention table is written from that registry too, so the two can't disagree.

### Declare what depends on you [#declaration-file]

What depends on you, Peal can't know, and never guesses. Declare it in a JSON file, as `self-host/privacy-declaration.example.json` shows, and name the file with `PEAL_PRIVACY_DECLARATION`. The Compose stack mounts it. A server run another way reads `PEAL_PRIVACY_DECLARATION_FILE`.

The file holds these fields:

| Field                  | What it holds                                                                                                                                                                                                                                                                                                                                      |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `controller`           | Who decides what the data is processed for, that is you: `name`, and if you wish `address`, `contact` (where privacy requests go) and `dataProtectionOfficer`                                                                                                                                                                                      |
| `policyUrl`            | Where your privacy policy is                                                                                                                                                                                                                                                                                                                       |
| `supervisoryAuthority` | The data protection authority you answer to, `name` and `url`                                                                                                                                                                                                                                                                                      |
| `recipients`           | Every provider that processes your users' data for you (hosting, media storage, email, payments, bot protection, AI, product analytics, alerts). Each has its `name`, the `service` it gives, the `country` it processes the data in, and the `safeguard` of a transfer outside the European Economic Area, or `null`.                             |
| `retention`            | Only if you run another stack than this repository's: how long yours keeps `technicalLogs` and `backups`, in English (`en`) and French (`fr`). Otherwise the registry states the production stack's: logs 31 days, traces 14 days, metrics 30 days, and deleted data gone from backups within 5 weeks. |

Every part is optional. What you leave out reads as not declared in each export, which then tells users less than the law has you tell them. Fill it in before you open your server to others.

> **Restart the server after you change the file**
>
> The server reads the file when it starts, and stops on one it can't read.
> Until you restart it (`docker compose restart server`), exports keep the old
> declaration.
