Skip to content

Backups and upgrades ​

This page explains how to back up Scholar Lens, how to restore a backup, and how to upgrade safely. It is for whoever runs the server.

What a backup holds ​

scripts/backup.sh makes one folder per backup with:

  • database.dump: the whole database (pg_dump, custom format), taken while the app keeps running,
  • one archive of uploaded files per place that has some (the app_data volume and the host's backend/data/uploads),
  • MANIFEST.txt: the time, the schema revision, the sizes and a SHA-256 sum of each file.

It keeps the newest 7 backups. Change that with BACKUP_KEEP.

WARNING

The .env files are not in the backup, because they hold secrets. Keep JWT_SECRET, SETTINGS_KEY and ACCESS_GRANT_KEY somewhere safe yourself. Settings and sign-ins saved in the app are encrypted with them and can't be read without them.

Make a backup ​

From the repository root, with the stack's Postgres running:

bash
scripts/backup.sh

It writes to ./backups (ignored by git). Give another folder as the first argument:

bash
scripts/backup.sh /mnt/backup-disk/scholarlens

To run it every night, add a cron entry that calls the script with a full path.

Restore a backup ​

A restore replaces the database and the uploaded files.

  1. Stop the API and the worker. The database must have no other connections.

  2. Run the restore with the backup folder:

    bash
    scripts/restore.sh backups/scholarlens-<time> --yes

    It checks every file against the manifest first and stops on a mismatch. Without --yes it does nothing.

  3. If the backup is from an older version, bring the schema up to date from the backend folder:

    bash
    alembic upgrade head

    Starting the API does the same.

  4. Start the API and the worker.

In a test, a backup of 25.7 MB of database and 20 MB of files restored into a fresh database with the same counts of documents, chunks, messages and users, and identical files.

Upgrade ​

  1. Make a backup.

  2. Pull the new code:

    bash
    git pull
  3. Update the dependencies. From backend: pip install -e ".[dev]". From frontend: npm ci. From extension, if you use it: npm ci and npm run build.

  4. Rebuild changed containers, for example the sandbox:

    bash
    docker compose -f scholarlens-stack.yml --profile sandbox up -d --build sandbox
  5. Restart the API. It applies new migrations when it starts.

To apply migrations without starting the API, run alembic upgrade head from the backend folder, with the Python environment active. alembic current shows the database's revision; it ends in "(head)" when it is up to date.

Database migrations ​

Migrations live in backend/app/db/migrations/versions/. They are written by hand with Alembic and named by date, for example 20261022_a1c3e5f7b902_.... A test checks that the migrations produce exactly the schema the models describe. See Contributing.