Updates and backups
Update in place, back up the database, uploads and secret, and restore from a backup.
Updating
git pull
docker compose --env-file deploy/.env up -d --build
Pulling the new source and rebuilding replaces the containers. Database migrations run when the API container starts, so there is nothing else to apply.
What to back up
- The database: all your data.
- The uploads volume: images and attachments. The database only holds their names. Skip it if you use S3 storage and rely on the bucket's versioning.
deploy/.env: it holdsBETTER_AUTH_SECRET. A database restored without the same secret signs everyone out, disconnects every calendar and resets every kiosk PIN.
With a hosted database such as Neon or Supabase, the provider keeps its own backups, but you still need deploy/.env and the uploads, and a dump of your own is cheap insurance. Take the database dump and the uploads copy at about the same time, so they match.
docker compose --env-file deploy/.env exec -T db pg_dump -U knotworking knotworking \
| gzip > knotworking-$(date +%F).sql.gz
A nightly backup
This script dumps the database, the uploads and deploy/.env, encrypts them, keeps 14 days locally and copies them off the machine. Adjust the paths, and make the script executable.
#!/usr/bin/env bash
set -euo pipefail
cd /opt/knotworking
dest=/var/backups/knotworking
key="$(cat /root/backup-key.pub)"
mkdir -p "$dest" && chmod 700 "$dest"
stamp=$(date +%F)
docker compose --env-file deploy/.env exec -T db pg_dump -U knotworking knotworking \
| gzip | age -r "$key" > "$dest/db-$stamp.sql.gz.age"
age -r "$key" -o "$dest/env-$stamp.age" deploy/.env
docker compose --env-file deploy/.env exec -T api tar -C /app/data/uploads -czf - . \
| age -r "$key" > "$dest/uploads-$stamp.tar.gz.age"
find "$dest" -type f -mtime +14 -delete
rclone copy "$dest" remote:knotworking-backups # off the machine, so a dead disk doesn't take the backups too
15 3 * * * /usr/local/bin/knotworking-backup >> /var/log/knotworking-backup.log 2>&1
Run it every night, and make cron log or mail failures. Delete old copies on the remote side too, for example with a bucket lifecycle rule.
Test a restore
An untested backup is a guess. Every few months, restore the latest dump into a throwaway database and look at it. Decrypt the dump first if you encrypted it.
age -d -i backup-key.txt db-DATE.sql.gz.age | gunzip > /tmp/restore.sql
docker run -d --name restore-test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=knotworking postgres:17-alpine
sleep 10
docker exec restore-test psql -U postgres -c 'create role knotworking'
docker exec -i restore-test psql -U postgres -d knotworking -v ON_ERROR_STOP=1 < /tmp/restore.sql
docker exec restore-test psql -U postgres -d knotworking -c 'select count(*) from tasks;'
docker rm -f restore-test && shred -u /tmp/restore.sql
The create role line is needed because the dump assigns ownership to the knotworking role. The restore should finish without errors, and the count should match what you see in the app.
Restoring
Restore into a fresh installation, before anyone signs in, using the same deploy/.env. That means the same BETTER_AUTH_SECRET.
docker compose --env-file deploy/.env up -d db
gunzip -c knotworking-DATE.sql.gz \
| docker compose --env-file deploy/.env exec -T db psql -U knotworking knotworking
docker compose --env-file deploy/.env up -d
If the API already ran against the new database, it created empty tables. Stop api and web, drop and recreate the database, then restore as above.
docker compose --env-file deploy/.env stop api web
docker compose --env-file deploy/.env exec db psql -U knotworking -d postgres -c 'drop database knotworking' -c 'create database knotworking'
Then put the uploads back into the volume, before people start uploading. The api container must exist, and up -d creates it.
age -d -i backup-key.txt uploads-DATE.tar.gz.age \
| docker compose --env-file deploy/.env exec -T api tar -C /app/data/uploads -xzf -
Health checks
The api, web and mcp containers have Docker health checks. The API's only checks that the process answers HTTP. It does not query the database, so a suspended hosted database still shows as healthy. For monitoring, check the sign-in page or a real request.
Troubleshooting
| Symptom | Fix |
|---|---|
| Sign-in does nothing, or says invalid origin | The address in the browser doesn't match APP_URL. Use it exactly, or add the other address to TRUSTED_ORIGINS. |
| Everyone was signed out | BETTER_AUTH_SECRET changed or was lost in a restore. Calendar connections need reconnecting too. |
| Invites aren't emailed | MAIL_FROM isn't a sender your provider accepts, or the scheme doesn't match the port. The API log shows the SMTP error. |
| Port 443 or 80 is already allocated | On a local network, leave DOMAIN and COMPOSE_FILE unset and change HTTP_PORT. |
| Lost the setup link | Run docker compose restart api and check the log again. |
| Compose says POSTGRES_PASSWORD is missing | Set it in deploy/.env. There is deliberately no default. |
| Locked out as the only owner | Create a reset link from another owner or admin account. If there is none, promote another member in the database: update workspace_members set role = 'owner' where user_id = '…'; |
To read the logs, run docker compose --env-file deploy/.env logs -f api web caddy.