# Backups

Backups are snapshots of the data and configuration, taken on a schedule you choose or before an operation that could lose data. For a database that means a physical base backup plus the write-ahead log, which is the only way a Postgres restore is actually correct. They are stored inside the same region as the target, which is the one thing that makes restore fast and cheap.

## Take one

```
kraftify backup create <id> --label before-migration
```

## List and restore

```
kraftify backup list <id>
kraftify backup restore <id> <backup-id>
```

Restoring stops the target, swaps the files and starts it again. The target is unavailable for the length of the swap, which is seconds for a small database and minutes for a large one.

## Schedule them

A schedule keeps the most recent 24 hourly and 7 daily snapshots and prunes the rest. Pruning is a delete, so the schedule is the only place retention is ever automatic.

```
kraftify backup schedule <id> --hourly --daily
```

> Snapshots are not replicated off the node. A node loss takes its snapshots with it. That is a deliberate cost decision, not an oversight, and it is the main thing we would change first with more funding.
