Skip to content

Backups and migrations

The school operator owns backup and restore. YearRoll does not ship a hosted backup service, and nothing in the app writes a backup to a vendor on a timer.

On startup the app checks its migration journal against the SQL files it was built with. In Docker, that check runs before the server listens. A failed file or a checksum mismatch stops the container.

After the process is listening, confirm the journal with:

Terminal window
curl -fsS http://127.0.0.1:3456/api/v1/health

migrations is applied when the journal matches. pending, mismatch, and error are HTTP 503. See API. Do not send users to an instance whose health check is failing.

Apply the same files the image expects. Do not edit a migration that has already been applied to a school database. A checksum change is a mismatch, and the instance will stay unhealthy until the file and the journal agree.

Take a logical dump of the school database from a machine that can reach it. Custom format keeps the dump restorable with pg_restore:

Terminal window
umask 077
pg_dump --format=custom --no-owner --no-acl --file yearroll.dump "$DATABASE_URL"
pg_restore --list yearroll.dump >/dev/null

pg_restore --list only reads the file. It does not connect. Store the dump on an encrypted disk the school controls.

If Postgres is the Compose service, you can also dump from the host while the 5432 port is published, using the host form of DATABASE_URL in .env.example. Stop publishing that port on a server that is reachable from the internet.

Do not point a restore at the database in DATABASE_URL. A restore goes to a different server or a local database you can throw away.

Confirm the target host is not the live host before you restore. The application repository includes a check that compares the two URLs and does not print them:

Terminal window
SOURCE_DATABASE_URL="$DATABASE_URL" \
RESTORE_DATABASE_URL="$RESTORE_DATABASE_URL" \
npx tsx src/db/check-restore-target.ts

Run that from a checkout of yearroll, with RESTORE_DATABASE_URL set to the empty target. Exit 0 means the hosts differ. Exit 1 means it refused, because the hosts match or a host could not be read.

Only then:

Terminal window
pg_restore --no-owner --no-acl --clean --if-exists \
--dbname "$RESTORE_DATABASE_URL" \
yearroll.dump

Check the restored copy. Leave the running app on the original DATABASE_URL until you have decided to cut over, and change that variable only as a deliberate step. Deleting or overwriting the live database is not a drill.

Next: Licensing and extensions.