---
url: /guide/volumes.md
description: Persistent volumes for services, their size, scheduled snapshots and restore.
---

# Volumes

A volume keeps data across deploys and restarts:

```toml
[services.nats.volumes]
data = "/data"
```

or with a size and scheduled backups:

```toml
[services.nats.volumes]
data = { path = "/data", size = "5G", backup = { schedule = "0 4 * * *", retain = 7 } }
```

| Key | Meaning |
|---|---|
| `path` | Absolute mount path in the container |
| `size` | Disk quota, such as `10G`. Defaults to the plan default, capped by the plan maximum. |
| `backup.schedule` | Five-field cron expression, UTC |
| `backup.retain` | Number of snapshots to keep, at least 1 |

## One writer

A service with a volume runs exactly one instance, and deploys **recreate**
it: the old container stops before the new one starts. `replicas > 1` on such
a service is a config error rather than a silent clamp.

## Backups and restore

```bash
duploy volume backup data --service nats
duploy volume backups data --service nats
duploy volume restore data <backup-id>
```

A restore stops the service, keeps a copy of the current data, unpacks the
snapshot and starts the service again. If anything fails on the way, the copy
is put back. Deploys, starts and cron triggers wait while a restore runs.

## Removing and renaming

Removing a volume from `duploy.toml` does not delete the data. The volume
stays as an orphan until you delete it:

```bash
duploy volumes
duploy volume rm data --service nats
```

Renaming a volume in the file creates a new, empty volume; the panel warns
about it, and the old data stays in the orphan.
