# Backups & recovery

Source: https://docs.apphaven.eu/backups

AppHaven is built durability-first: the platform assumes that something (a
bad migration, an overeager script, a hardware fault) will eventually go
wrong, and treats getting your data back as a core feature. Your production
deployment is backed up automatically, with no schedule to wire up. The one
choice you make is how long restore points are kept.

## What is protected

Two layers run side by side:

**Restore points: everything, consistently.** A restore point captures all of
a deployment's persistent data, both its [volumes](https://docs.apphaven.eu/volumes.md) and its
[managed database](https://docs.apphaven.eu/services/postgres.md) storage, in a single atomic snapshot.
Atomic means the volumes and the database are captured at the same instant,
so a restored point is internally consistent: no database that's newer than
the files it refers to. Restore points are taken at three moments:

| Restore point | Taken |
| ------------- | ----- |
| **Daily** | Every night. |
| **Before deploy** | Right before each new version of production starts, so there is always a point to return to from just before a deploy. |
| **Before restore** | Right before production is [replaced by a restore](https://docs.apphaven.eu/restore.md#replacing-production). |

**Continuous database capture: every change, as it happens.** For the managed
database, AppHaven additionally records its change stream continuously, from
the daily restore point before last up to the present moment. That window
covers at least the last full day, and up to two days just before the next
daily point.

The window starts afresh at two moments:

- **When production is restored.** The restored database begins a new history
  of its own, so the window starts at the restore. The database as it was
  before the restore stays available through the **Before restore** point.
- **When the database changes more than its change history has room for.**
  The history has a size limit of its own (see
  [below](#how-backups-relate-to-your-storage-size)). When the changes since
  the daily restore point before last no longer fit, AppHaven starts a
  complete new record instead of keeping one with a gap. Your app keeps
  running and writing as usual; only the window starts over.

The Backups section shows since when database changes are kept. It shows
**Restore points only** while a new record does not yet reach back to the
daily restore point before last, or when the database has not changed since
that point.

The change stream is deliberately stored **outside your app's environment**,
separate from the database itself. A bug that mangles the database, a
compromised app, or a deploy gone wrong cannot reach back and damage the
record needed to recover from it.

## Choosing how long backups are kept

Open your app's **Backups** section in the console to set the retention window:
how far back your restore points reach. You can keep 7, 14, or 30 days. A longer
window gives you more room to recover from a problem you only notice later, and
uses more of your storage budget for history. New apps start at 7 days.

The retention window also decides how long the builds of your production
versions are kept, so you can [run an older version](https://docs.apphaven.eu/restore.md#run-an-older-version)
from anywhere in the same window. See [App versions](https://docs.apphaven.eu/resources.md#app-versions).

## The Backups section

The Backups section shows what is protected at a glance: since when database
changes are kept and how much storage your restore points use. You set how
long restore points are kept under **Settings > Backups**. Below that are your restore points, newest first and grouped per day,
with each *Before deploy* point naming the deploy it precedes. The tabs narrow
the list to the points taken before a deploy or the daily ones.

## What you can recover, and to when

| What | Recoverable to |
| ---- | -------------- |
| Managed database | Any restore point within your retention window |
| Persistent volume files | Any restore point within your retention window |
| Application code | Any production version that ran within your retention window, exactly as it was built; beyond that, any commit in your Git history |
| Configuration | Current manifest in your repository; current Variables & Secrets in the console |

## Restoring

You restore from the console yourself: go back to before a deploy, run an
older version, or rewind the database, either in place or as a private
restore preview next to production. [Restoring your app](https://docs.apphaven.eu/restore.md) walks
through each option.

To bring the database back to a specific moment between two restore points,
within the window its changes are kept, contact AppHaven support with the app
and the moment you need. "The database as it was yesterday at 14:05" is
exactly the right shape of request.

## How backups relate to your storage size

Restore points and the database change history live inside your deployment's
[storage size](https://docs.apphaven.eu/resources.md): the single number you pick covers your live
data *and* the history kept to protect it. Restore points only store what
changed since the previous one, so a point taken before a deploy costs little
unless your app rewrites a lot of data. A longer retention window keeps more
history, so it uses more of that budget. The database change stream counts
too, up to a limit of its own: each managed database's change history can use
a quarter of your storage size, or 2 GB if that is more. At the smallest
storage size of 5 GB that is 2 GB per managed database, so two databases can
use most of the storage for their change history. Once a history reaches its
limit it starts afresh instead of growing further, and its window of kept
changes starts over. The deployment page shows how much of the budget is in
use, split into database, files, and backups.

Choose a storage size with room for your data, its restore points, and the
change history of each managed database up to its limit. They all share the
one budget, so when it is full, your app's own writes fail as well. Watch the
split on the deployment page and
[increase the storage](https://docs.apphaven.eu/resources.md#storage) before it runs out.

The builds of your app versions are kept separately and are not part of this
budget; see [App versions](https://docs.apphaven.eu/resources.md#app-versions).

## Scope: your production deployment

Backups protect your **production deployment**, the one running your production
branch. [Preview deployments](https://docs.apphaven.eu/previews.md) are disposable: each is rebuilt from its
branch every time you deploy, so they carry no separate backups, and nothing you
try on a branch can consume or contaminate your production history. The same
goes for [restore previews](https://docs.apphaven.eu/restore.md#restore-previews): each is a copy made
from production's restore points, which stay protected on production.

Two lifecycle rules follow from data belonging to the deployment:

- **Stopping a deployment keeps its data and backups.** Deploy again and
  everything is still there.
- **Deleting a deployment removes its data and backups.** Delete is the one
  operation that lets go of your data. If you might want it later, stop
  instead, or take an export first ([Application portability](https://docs.apphaven.eu/portability.md)
  covers how).

## Where to go next

- [Restoring your app](https://docs.apphaven.eu/restore.md): putting production back, or trying a restore
  first on a private copy.
- [Database](https://docs.apphaven.eu/services/postgres.md): the managed database these guarantees apply to.
- [CPU, memory & storage](https://docs.apphaven.eu/resources.md): sizing the storage budget.
- [Building with AI agents](https://docs.apphaven.eu/ai-agents.md): migration safety and recovery in practice.
