Skip to content
Documentation

Back up, restore, and upgrade Nibleaf

Capture Postgres and object storage as one recovery set, test restoration in isolation, and upgrade or roll back a pinned Nibleaf release.

  • 7 min read
  • Updated

A usable recovery set includes Postgres and object storage from the same operational window. A database dump without uploaded assets is incomplete. Keep copies outside the live host and account, and prove restoration before relying on them.

Run the commands on this page from the deployment directory. A guided-installer directory contains only docker-compose.yml and .env, so docker compose finds its file directly. In a repository checkout, first run export COMPOSE_FILE=docker-compose.prod.yml, because docker-compose.yml there is the source-build stack.

Schedule a maintenance window: these commands stop all application writers and maxio until both copies are complete. Stop any external writer too. Use the existing .env and Compose project. The shell exits on the first failure, leaving services stopped for investigation. Do not use this procedure while other processes are still uploading or publishing.

Dump Postgres in custom format, then archive the bundled maxio volume:

bash
set -eu
mkdir -m 700 -p backups
STAMP=$(date +%Y%m%d-%H%M%S)
docker compose --profile admin stop app admin server worker
docker compose stop maxio
docker compose exec -T postgres pg_dump -U nibleaf -d nibleaf --format=custom > "backups/nibleaf-db-$STAMP.dump"
MAXIO_VOLUME=$(docker inspect --format '{{range .Mounts}}{{if eq .Destination "/data"}}{{.Name}}{{end}}{{end}}' "$(docker compose ps --all -q maxio)")
test -n "$MAXIO_VOLUME"
docker volume inspect "$MAXIO_VOLUME" >/dev/null
docker run --rm -v "$MAXIO_VOLUME":/data:ro -v "$PWD/backups":/backup alpine:3.22 tar czf "/backup/nibleaf-storage-$STAMP.tar.gz" -C /data .
cp -p .env "backups/env-$STAMP"
cp -p "${COMPOSE_FILE:-docker-compose.yml}" "backups/compose-$STAMP.yml"
ls -lh "backups/nibleaf-db-$STAMP.dump" "backups/nibleaf-storage-$STAMP.tar.gz"
docker compose up -d

These commands find the volume mounted at /data in the stopped maxio container, so they work with any Compose project name and stop if it cannot be identified. External R2 or S3 buckets are not in this volume, so skip those lines and use provider versioning, replication, or an independent bucket backup.

In a repository checkout, bash scripts/backup.sh dumps Postgres, archives a named storage volume when it exists, and prunes matching local files after 14 days. It does not stop writers, back up .env, or discover your storage volume. Its default STORAGE_VOLUME is nibleaf_nibleaf-maxio; with a custom project name, pass the actual mounted volume or it can skip storage and still succeed. Use the inspected MAXIO_VOLUME above as STORAGE_VOLUME. COMPOSE_FILE defaults to docker-compose.prod.yml, BACKUP_DIR to ./backups, RETENTION_DAYS to 14, and PGUSER / PGDATABASE to nibleaf. The script accepts one Compose filename; for multiple overlays, use a reviewed wrapper with the same file list as the deployment. It is not a release asset.

.env holds the secrets that make a restore usable, including the encryption keys for Git and integration credentials. Keep a protected copy with its own access control. Without those keys, stored credentials cannot be decrypted.

Ship both artifacts off-host with separate credentials and record identifiers, sizes, timestamps, retention, and the application release.

Never overwrite production for a drill. Create an isolated database, storage target, and application origin, then restore into them. On a separate host with its own stack, use the same $STAMP. Set STAMP to the suffix shared by your backup files. Start from a new empty database and a dedicated empty storage volume; do not start the migrate service before restoration. The guard below refuses a database with public tables. Never point these commands at the live Compose project. If any step fails, keep application services stopped:

bash
set -eu
docker compose --profile admin stop app admin server worker
docker compose up -d postgres dragonfly maxio
test "$(docker compose exec -T postgres psql -U nibleaf -d nibleaf -Atc "SELECT count(*) FROM pg_tables WHERE schemaname='public'")" = 0
docker compose exec -T postgres pg_restore -U nibleaf -d nibleaf --exit-on-error < "backups/nibleaf-db-$STAMP.dump"
MAXIO_VOLUME=$(docker inspect --format '{{range .Mounts}}{{if eq .Destination "/data"}}{{.Name}}{{end}}{{end}}' "$(docker compose ps --all -q maxio)")
test -n "$MAXIO_VOLUME"
docker volume inspect "$MAXIO_VOLUME" >/dev/null
docker compose stop maxio
docker run --rm -v "$MAXIO_VOLUME":/data -v "$PWD/backups":/backup alpine:3.22 sh -c "find /data -mindepth 1 -delete && tar xzf /backup/nibleaf-storage-$STAMP.tar.gz -C /data"
docker compose up -d

Then verify projects, memberships, page trees, current drafts, ready deployments, uploaded assets, authentication isolation, and public search.

Record elapsed time and every manual step. A backup job exit code without a successful isolated restore is not recovery evidence.

Do not re-run the installer to upgrade. It is for new installations only, and replacing .env with newly generated secrets locks you out of existing data.

From v0.1.2 to v0.2.1, follow the upgrade guide. That upgrade has a required staged step. If you change only the version, scheduling is refused and the API and worker do not become ready.

For other upgrades, read each intervening release note and check for release-specific migration or configuration changes. Create and restore-test a backup. Then:

  1. Replace the Compose file with the verified copy from the target release. Keep .env, the Compose project name, and the volume names. A version-only change misses settings that the new Compose file passes to the services:

    bash
    VERSION=vX.Y.Z
    d=$(mktemp -d)
    curl -fsSLo "$d/docker-compose.yml" "https://github.com/lord007tn/nibleaf/releases/download/$VERSION/docker-compose.yml"
    curl -fsSLo "$d/SHA256SUMS" "https://github.com/lord007tn/nibleaf/releases/download/$VERSION/SHA256SUMS"
    (cd "$d" && grep '  docker-compose.yml$' SHA256SUMS | sha256sum -c -)
    cp "$d/docker-compose.yml" "${COMPOSE_FILE:-docker-compose.yml}"
    
  2. Set NIBLEAF_VERSION to the same existing release tag in .env:

    dotenv
    NIBLEAF_VERSION=vX.Y.Z
    
  3. Pull and recreate the services:

    bash
    docker compose pull
    docker compose up -d
    

Confirm the image digest, migration log, service health, sign-in, one upload, one publish, one search, and one public page.

Prisma migrations are forward-only. If no schema migration ran, pin the prior image, restore the prior Compose file, and recreate the services. If a migration changed the database, stop writes and restore the pre-upgrade recovery set before starting the older application. Do not run the older application against the migrated schema.

Going back from v0.2.1 to v0.1.2 also needs the schedule rollback in the upgrade guide. Neither the schedule rollback nor the database restore is enough alone.

Do not combine an application upgrade with a PostgreSQL major-version change. Treat the database upgrade as a separate dump-and-restore project.

The source quickstart and Coolify Compose files define the backups disk at /var/lib/clickhouse/backups on a separate named volume. The v0.2.1 docker-compose.prod.yml has no ClickHouse service at all. First provision your own ClickHouse service and application environment mappings. On that service, mount a volume at /var/lib/clickhouse/backups and add this file as /etc/clickhouse-server/config.d/backups.xml:

xml
<clickhouse>
  <storage_configuration><disks><backups><type>local</type><path>/var/lib/clickhouse/backups/</path></backups></disks></storage_configuration>
  <backups><allowed_disk>backups</allowed_disk></backups>
</clickhouse>

Use ClickHouse 25.8-compatible native backups with an operator identity; keep passwords out of command history. In clickhouse-client (or another authenticated SQL client), run:

sql
BACKUP DATABASE nibleaf_analytics TO Disk('backups', 'analytics-20261106-001');
SELECT name, status, error FROM system.backups;

Use a unique backup name. Require BACKUP_CREATED, archive the backup volume, encrypt it and copy it off-host. A volume on the same full disk is not disaster recovery. Record the exact ClickHouse version, database DDL, users/roles, application revision, retention env and backup checksums. Back up Postgres and object storage separately; analytics backups do not include them.

On an isolated recovery server with the same ClickHouse version and backups disk configuration, copy the backup into that disk and restore to a new database:

sql
RESTORE DATABASE nibleaf_analytics AS nibleaf_analytics_restore
FROM Disk('backups', 'analytics-20261106-001');
SELECT name, status, error FROM system.backups;
SELECT count(), uniqExact(event_id) FROM nibleaf_analytics_restore.analytics_events;
SELECT version FROM nibleaf_analytics_restore.analytics_schema_migrations FINAL ORDER BY version;

Require RESTORED, compare counts and event-id samples with the backup manifest, then set CLICKHOUSE_DATABASE=nibleaf_analytics_restore and an isolated POSTGRES_URL, run migrations and test tenant-scoped reads. Replay project erasures since the backup before allowing application access. Preserve existing keys and salts. Never test a restore over the serving database.

rebuildProjectAnalyticsRollups can rebuild analytics rollups from retained raw facts. Expired raw facts cannot recreate older rollups; raw-event loss leaves permanent gaps. Sensitive query text intentionally expires quickly and is not reconstructed. Do not apply analytics rebuild assumptions to billing/usage data.

Before upgrades, pin the image, create and restore-test a backup, and review ClickHouse release compatibility. Restore to the original server version first, then follow supported upgrade steps. Automatic migrations are additive, not a schema downgrade mechanism. A retention reduction is irreversible after merges. The SQL above is a recovery drill procedure; only a completed isolated restore with matching invariants counts as recovery proof for your deployment. The disk configuration and SQL follow the ClickHouse native backup reference.

If you normally run the admin service, use docker compose --profile admin up -d instead of the final up -d after a successful backup or restore. Restart external writers only after verification. For multiple Compose files, preserve the complete file list and copy each operator override into the recovery set.

Was this page helpful?