Skip to Content
Pet Adopt
Deploy

Backups and updates

What to back up and restore together, how to update a site and its plugins, and running more than one server.

Backups

A site is three things. Back up all three, and restore the database and the bucket together: the database refers to image files by name, so one without the other leaves broken images or orphaned files.

WhatHow
The databasePostgreSQL: pg_dump. SQLite: sqlite3 pet-adopt.db ".backup backup.db", which is safe while the site runs. Copying the file by hand is not, unless the site is stopped.
The storage bucketCopy or sync the bucket with your storage provider's tool, or switch on its versioning.
The secretsBETTER_AUTH_SECRET and the rest of the environment. Without the same secret, restored accounts lose two-factor and every stored password and key must be entered again.

Take the database backup first and the bucket copy straight after. A bucket that is slightly newer than the database only holds a few unused files; a database newer than the bucket has images that are missing.

Test a restore into a scratch database and bucket before you need one.

Updating

git pull
pnpm install --frozen-lockfile
pnpm build        # migrates PostgreSQL and hosted libSQL, then builds
# restart the server
  • Back up first. Migrations change the database and are not reversed by going back to older code.
  • Read the release notes for changed settings.
  • With more than one server, build once, then restart them one after another. The build's migration runs before any of them starts the new code.

git pull brings the site and the plugins kept in the repository's plugins/ folder. Plugins you installed from npm are updated separately, below.

Plugins installed from npm

A plugin added with pnpm --filter @pet-adopt/web add <name> comes from npm, and git pull does not move it. Update it on your own machine, test, and commit the result:

pnpm update -r "@pet-adopt/plugin-*"            # stays inside the ranges in apps/web/package.json
pnpm update -r --latest "@pet-adopt/plugin-*"   # or: move to the newest release
pnpm typecheck
pnpm build
  • A plain pnpm update stays inside the version range written in apps/web/package.json. An exact version (0.1.0) does not move at all, and ^0.1.0 takes only patch releases while the version starts with 0. A new minor release (0.2.0) can need action from you, so read the plugin's changelog before you use --latest.
  • Plugins from other authors have their own names: put each one in place of the pattern, as in pnpm update -r --latest acme-pet-adopt-gallery.
  • Check apps/web/package.json afterwards. Plugins kept in the repository's plugins/ folder must still say workspace:*. If one now names a version from npm, put workspace:* back and run pnpm install.
  • A plugin needs a recent enough site. Plugins depend on the SDK (@pet-adopt/plugin-sdk), which comes with the site. If pnpm warns about an unmet peer dependency on @pet-adopt/plugin-sdk, the new plugin version needs a newer site: update the site first (git pull, as above), or stay on the plugin version you have.
  • Commit the changed apps/web/package.json and pnpm-lock.yaml, then deploy as above. A plugin update can bring migrations for its own tables: pnpm build applies them on PostgreSQL and hosted libSQL, and a local SQLite file applies them when the server starts.

Moving uploads off the disk

Older copies of the site kept uploads in a folder on the server (data/media). To move them into the bucket:

pnpm --filter @pet-adopt/web storage:copy-local             # from data/media
pnpm --filter @pet-adopt/web storage:copy-local --dry-run   # list what it would copy
pnpm --filter @pet-adopt/web storage:copy-local --from <folder>   # relative to apps/web

It skips files that are already in the bucket, so it is safe to run again. It copies only file names the site itself generates and lists the others as skipped. It never changes or deletes the local files: remove the folder yourself once the site shows every image.

More than one server

Works with PostgreSQL or hosted libSQL. Sessions, sign-in limits and settings are in the database, so servers share them.

Two things differ between servers for a short time:

  • Pages: each server keeps its own page cache, which refreshes as soon as you publish and also every 60 seconds. After you publish, the server that handled the request shows the change at once; the others catch up within 60 seconds.
  • Sign-in providers: a change takes effect at once on the server that saved it and within 30 seconds on the others.

On this page