# Backups

Export and import cached signed history.

## Export and import


```ts
const exported = await db.backup.export();
if (exported.error) throw exported.error;
const json = JSON.stringify(exported.data);
const restored = await db.backup.import(json);
```

An archive contains namespace-scoped, signed cached events, record history, and deletion tombstones. Private events remain ciphertext. Ephemeral messages and unscoped native events are excluded. Queue delivery state is separate and is not included.

Import checks the whole archive's format, namespace, and signatures before changing the cache. It applies tombstones first and does not republish anything. An archive reflects data known to this client; pull from relays first to update that view. It is not a complete relay or global backup. Keep tombstones with records to prevent deleted versions from returning.
