---
title: "Back up and restore"
description: "Restoring after a failed migration, copying the database and its screenshots together, and checking the purge before it deletes anything."
---

> Documentation Index
> Fetch the complete documentation index at: https://commentware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Back up and restore

Put back the backup a migration wrote, take your own copy, and see what the
retention purge would delete before it does. Learn more about [what the server
deletes on its own](/docs/concepts/retention/).

## Prerequisites

- A server you run. See [Manage a server](/docs/server/).

## Restore a backup

1. Stop the server with [`commentware stop`](/docs/server/#stop-the-server). The
   restore refuses while a server is running against the database it would
   replace.
2. Run:

```sh
   commentware db restore
```

3. Type `y` at "Restore this backup? [y/N]". Pressing Enter cancels. Optional:
   pass `-y` in step 2 to skip the question.

Somebody running this has had a migration fail on a database nobody else has a
copy of, so the command does the checking they are in no position to do:

- **It opens the backup before touching anything**, so a truncated file fails
  there rather than after it has replaced the live one.
- **It refuses a backup newer than this build understands.**
- **It refuses while a server is running** against the database it would
  replace.

**It renames rather than deletes.** It restores the screenshots with the
database, and what it replaces moves aside — the database to
`<database>.replaced-by-restore`, the screenshots directory to
`<blobs>.replaced-by-restore` — so restoring the wrong thing is
undoable.

## Back it up yourself

Nothing here replaces an ordinary backup. Two paths matter: the SQLite file, and
the directory of screenshots and attachments beside it. `commentware where`
prints both without starting a server, the directory as `blobs`.

1. Stop the server with [`commentware stop`](/docs/server/#stop-the-server), or
   accept that a copy taken while it is running may be mid-write.
2. Copy the SQLite file and the screenshots directory together.

## Preview and run the purge

1. See exactly what would go, and delete nothing:

```sh
   commentware purge --dry-run
```

2. Optional: run it by hand rather than waiting for the next run:

```sh
   commentware purge
```

Run the preview after changing `resolved-purge-days` or `bundle-idle-days`,
before finding out the other way. Learn more about
[settings](/docs/server/settings/).

## Check that it worked

After a restore, what it replaced is beside the database as
`<database>.replaced-by-restore` and `<blobs>.replaced-by-restore`. `commentware purge --dry-run` prints what the
purge would delete, and nothing is gone.

## Next steps

- [Manage a server](/docs/server/): start it again on the restored database.