# Back up and restore

> Where a self-hosted memex keeps its daily backups, how to copy them off the machine, and how to restore one.

Page: https://docs.memex.tools/self-hosted-backups

Once a day memex writes a copy of its database files and a Markdown export of your notes to `/data/backups`, and keeps the last seven. They are on the same volume as everything else, so copy them off the machine:

```
docker cp memex:/data/backups ./memex-backups
```

**Settings › Notes** › **Export** downloads the Markdown export at any time.

> **Keep secret.env too**
>
> The keys you add in **Settings › AI features** are stored encrypted with `/data/secret.env`. Keep a copy of that file somewhere safe as well: `docker cp memex:/data/secret.env .` Without it, a restored memex asks for those keys again.

## Restore everything from a backup folder

`YYYYMMDD-HHMMSS` stands for the one you choose:

```
docker stop memex
docker run --rm -v memex:/data -v "$PWD/memex-backups/YYYYMMDD-HHMMSS:/backup:ro" --entrypoint sh ghcr.io/artem-kolesnikov/memex -c 'test -f /backup/directory.sqlite && test -d /backup/vaults && old=/data/before-restore-$(date +%s) && mkdir "$old" && mv /data/directory.sqlite* /data/vaults "$old"/ && cp /backup/directory.sqlite /data/ && cp -r /backup/vaults /data/ && echo restored'
docker start memex
```

Nothing is touched unless the folder holds a backup, and what was there before is moved to `/data/before-restore-…` rather than deleted. Put `secret.env` back the same way if the volume was lost.

## Restore notes only, from a Markdown export

On a new memex, **Settings › Notes** › **Import** takes the ZIP. Each note arrives with its tags, description and dates; history, connections and settings stay behind. An export from memex.tools imports the same way, and back. See [Import notes](https://docs.memex.tools/import).

## Related

- [Upgrade](https://docs.memex.tools/self-hosted-upgrade): Move a self-hosted memex to the newest image, keeping your notes.
- [Export notes](https://docs.memex.tools/export): Download one note, a selection, or everything as Markdown files.
- [Import notes](https://docs.memex.tools/import): Bring in Markdown or text files, or a ZIP of a folder such as an Obsidian vault.
