> Index of every page on this site: [llms.txt](https://docs.a-line.cloud/llms.txt)

# Keep data with volumes and backups

> Give an app a persistent volume, back it up on a schedule and restore it.

**Goal**: an app whose data survives restarts and redeploys, with nightly
backups you can restore.

## Before you start

- An app on a running cluster.
- For backups: object storage in your organization. Backups are stored
  there and billed as storage usage. See
  [Use object storage](/guides/object-storage).

## Add a volume

A container's own disk is wiped on every restart. Write data you want to
keep to a volume.

<Steps>
<Step>

Open the app on the project canvas and go to its **Settings** tab.

</Step>
<Step>

In the **Storage** section, select **Add volume**.

</Step>
<Step>

Pick **New volume**, or **Mount existing** to reuse a volume.

</Step>
<Step>

Enter a **Volume name**, a **Mount path** such as `/data`, and a **Size**
in GiB.

</Step>
<Step>

Save and deploy the app.

</Step>
</Steps>

Templates such as PostgreSQL bring their own storage; you set its size when
you create them.

## Add a backup policy

Apps with volumes and stateful templates get a **Backups** tab.

<Steps>
<Step>

Open the **Backups** tab and select **Add backup**.

</Step>
<Step>

Pick the **Source**, or start from one of the presets.

</Step>
<Step>

Set the **Schedule**, for example every night.

</Step>
<Step>

Pick the **Backup type**:
- **Full**: a complete copy every run.
- **Incremental**: only the changes, with a full copy every 7th run.

</Step>
<Step>

Pick the **Compression** and the **Destinations**. The **Primary target**
is used for restores by default.

</Step>
<Step>

Name the policy, such as `nightly-data`, and select **Create policy**.

</Step>
</Steps>

Select **Run now** on a policy to take a backup at once.

<Callout title="Crash-consistent backups">
  Volume backups are taken while the app keeps running, so a restore looks
  like the moment after a power cut. Most apps recover from that. Run a
  database as a [database app](/guides/managed-database) instead of on a
  volume: PostgreSQL backups can be restored to a
  [point in time](/concepts/backups#restores).
</Callout>

## Verify

The backup history on the **Backups** tab lists every run. A run is
`running`, then `succeeded` or `failed`. Filter it by policy or target.

## Restore

<Steps>
<Step>

In the history, select **Restore** on a backup. The **Restore backup**
dialog opens.

</Step>
<Step>

Pick the target under **Restore from target**. For PostgreSQL, you can also
**Restore to a point in time** between backups.

</Step>
<Step>

Read what the restore does, confirm **I understand** and start it.

</Step>
</Steps>

What happens depends on the app:

| App | Restore |
| --- | --- |
| PostgreSQL | Restores into a new copy. The current database keeps running until you promote the restored copy. |
| ClickHouse | Restores in place. |
| Volumes | Stops the app, replaces the data, then starts the app again. |

## Troubleshooting

- **No Backups tab**: the app has no volume and is not a stateful template.
  Add a volume first.
- **A run failed**: open it in the history for the error. Check that the
  target bucket still exists and is not over its quota.
- **The app lost its files after a restart**: it writes outside the volume's
  **Mount path**. Change the app or the mount path.

## Deleted apps

Deleting an app keeps its backups until their retention runs out. Select
**Restore into new app** on a kept backup to bring the data back.

## In IaC

An app file lists `volumes` (`name`, `mount_path`, `size`) and
`backup_policies` (by default every night at 02:00, kept 7 days). See
[Volumes in IaC](/iac/data#volumes) and [backups in IaC](/iac/data#backups).

## Next steps

- [Backups](/concepts/backups): runs, targets and mirrors.
- [Use object storage](/guides/object-storage)
- [Add a database and connect an app](/guides/managed-database)
