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_datavolume and the host'sbackend/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.shIt writes to ./backups (ignored by git). Give another folder as the first argument:
bash
scripts/backup.sh /mnt/backup-disk/scholarlensTo 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.
Stop the API and the worker. The database must have no other connections.
Run the restore with the backup folder:
bashscripts/restore.sh backups/scholarlens-<time> --yesIt checks every file against the manifest first and stops on a mismatch. Without
--yesit does nothing.If the backup is from an older version, bring the schema up to date from the
backendfolder:bashalembic upgrade headStarting the API does the same.
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
Make a backup.
Pull the new code:
bashgit pullUpdate the dependencies. From
backend:pip install -e ".[dev]". Fromfrontend:npm ci. Fromextension, if you use it:npm ciandnpm run build.Rebuild changed containers, for example the sandbox:
bashdocker compose -f scholarlens-stack.yml --profile sandbox up -d --build sandboxRestart 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.