Documentation menu

Operating the server

Backup and restore

A backup is a single .tar.gz file containing the database, every brain as plain Markdown files, the version history and the configuration. It is made while the server runs, and restoring one never deletes the data it replaces.

Making a backup

sudo memex backup                              # /var/lib/memex/backups/memex-<UTC timestamp>.tar.gz
sudo memex backup --output /mnt/nas/memex.tar.gz
EntryContent
memex.dbA consistent snapshot of the database: users, rights, settings, file index, and the vectors of semantic search.
brains/Every brain, as plain Markdown files.
history/The version history of every brain (git repositories).
config.tomlThe configuration file. It contains the tunnel token if you use a permanent tunnel.
manifest.jsonArchive format, Memex version, database schema version, creation time, number of files.
  • The search index is not included: it is rebuilt when restoring. Neither is the embedding model of semantic search, which can be installed again.
  • The archive is readable only by its owner. It contains every note in clear text: treat backups as secrets.
  • Brains are plain files and histories are plain git repositories, so a backup can be read without Memex: unpack it and open brains/ in any editor.

Scheduling backups

A backup that stays on the same disk does not protect against losing that disk: copy backups to another machine. A nightly job can be as simple as:

# /etc/cron.d/memex-backup
30 3 * * * root /usr/local/bin/memex backup --output /mnt/nas/memex-$(date +\%F).tar.gz

Memex also takes a backup on its own before every update (the three most recent are kept) and before memex reset --erase.

Restoring

sudo memex restore /path/to/memex-20260131-030000.tar.gz
  1. The whole archive is validated before anything is touched. It is refused if it is not a Memex backup, if it was made by a newer Memex than the one installed (update first), or if it contains anything suspicious.
  2. You are asked to confirm (--yes skips the question).
  3. The service is stopped.
  4. The current data is moved aside, never deleted, to /var/lib/memex.before-restore-<timestamp>/. Delete it yourself once you have checked the result.
  5. The archive is extracted, the database is migrated to the current schema if the backup is older, and the search indexes are rebuilt.
  6. The service is started again.

The program, the existing backups and the active configuration file are not touched. The configuration from the archive is saved next to the data as config.restored.toml for reference.

Moving to another machine

  1. On the old machine: sudo memex backup --output memex.tar.gz, and copy the file over.
  2. On the new machine: install Memex normally, with the same access mode or a new one, then sudo memex restore memex.tar.gz.

Accounts, brains, rights and history come along. Sessions too, so people stay signed in. If the address of the instance changes, connected AI clients must be reconnected with the new address.

Rebuilding the index

sudo memex reindex

This rebuilds the search index of every brain and records files that were added, changed or removed directly on disk. The service is stopped for the duration and started again.

Check a backup

sudo tar -tzf /var/lib/memex/backups/memex-<timestamp>.tar.gz | head

The listing shows manifest.json, memex.db and your brains. The only complete test of a backup is a restore on another machine. Reference: backup.md.