Files
Tomas DvorakandDevin 55edbf8b56 feat: phase 6 production hardening + DB-to-DB transfer
Security:
- Graceful shutdown: http.Server + signal.NotifyContext, 10s drain,
  retention sweeper cancelled before pool close
- Scoped API keys (migration 00006): ingest/read/write/admin enforced in
  auth middleware; scope picker + badges in Settings UI; scopeless legacy
  keys act as admin. Read-only keys now get 403 on ingest (verified live)
- nginx: baseline security headers on all responses, CSP scoped to SPA;
  fixed add_header inheritance shadowing
- better-auth rate limit enabled unconditionally (was gated on NODE_ENV,
  which the shipped .env sets to development)
- Mailpit moved to docker-compose.dev.yml; prod compose cannot expose it
- setup.sh generates PRIMORA_ENCRYPTION_KEY

Reliability/ops:
- Retention: per-project retention_{events,audit,webhook}_days
  (migration 00007, 0=off) + hourly RetentionSweeper; edit UI in Projects
- GET /api/v1/metrics Prometheus exposition
- compose: healthchecks + restart policies everywhere, dragonfly pinned
  to v2.0.0, depends_on service_healthy
- backup.sh/restore.sh (pg_dump -Fc + storage volume); restore verified
  against scratch postgres+volume
- .dockerignore: exclude target dirs (build context was 4.7GB)

Correctness/testing:
- DBX transfer endpoint: POST /db-connections/:id/transfer — SQL or Redis
  target, 1000-row bound, server-side creds (verified live pg→dragonfly)
- Pagination audit: ListComponents capped at 500 (auto-registers)
- CI: goose up/reset/up job + compose e2e-smoke job (smoke-e2e.sh
  verified locally: signup, bootstrap, scoped keys, ingest, metrics)
- k6 load sanity script: 6650 reqs, ~217/s, 0 real failures, p95 221ms
  (429s = configured rate limiter working)

Docs: DEPLOYMENT_GUIDE.md, PRODUCTION_READINESS.md; verify script
repaired (stale refs + set -e arithmetic abort). ROADMAP: phase 2 +
phase 6 marked complete.

Authored By: TDvorak <[email protected]>

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-17 09:15:42 +02:00

51 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Primora backup: pg_dump of the database + archive of the object-storage root.
#
# Produces backups/primora-YYYYMMDD-HHMMSS.tar.gz containing:
# db.dump postgres custom-format dump (all schemas, incl. core + auth)
# storage/ contents of the backend_storage volume
#
# Usage (from the repo root, against the compose stack):
# ./scripts/backup.sh
#
# Optional env:
# BACKUP_DIR output directory (default: ./backups)
# POSTGRES_CONTAINER compose container name (default: primora-postgres-1)
# POSTGRES_USER/DB dump credentials (default: primora/primora)
# STORAGE_VOLUME docker volume for objects (default: primora_backend_storage)
#
# Restore with scripts/restore.sh. Schedule via cron or a systemd timer —
# see DEPLOYMENT_GUIDE.md#backups.
set -euo pipefail
BACKUP_DIR="${BACKUP_DIR:-./backups}"
POSTGRES_CONTAINER="${POSTGRES_CONTAINER:-primora-postgres-1}"
POSTGRES_USER="${POSTGRES_USER:-primora}"
POSTGRES_DB="${POSTGRES_DB:-primora}"
STORAGE_VOLUME="${STORAGE_VOLUME:-primora_backend_storage}"
stamp="$(date +%Y%m%d-%H%M%S)"
mkdir -p "$BACKUP_DIR"
BACKUP_DIR="$(cd "$BACKUP_DIR" && pwd)"
# Workdir lives under BACKUP_DIR — /tmp is not bind-mountable on every
# docker setup, and the storage archive is written through a container.
work="$(mktemp -d "$BACKUP_DIR/.tmp.XXXXXX")"
out="$BACKUP_DIR/primora-$stamp.tar.gz"
trap 'rm -rf "$work"' EXIT
echo "==> dumping database from $POSTGRES_CONTAINER"
docker exec "$POSTGRES_CONTAINER" \
pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Fc \
> "$work/db.dump"
[ -s "$work/db.dump" ] || { echo "pg_dump produced an empty file" >&2; exit 1; }
echo "==> archiving storage volume $STORAGE_VOLUME"
# Read the volume through a throwaway container — no host mount assumptions.
docker run --rm -v "$STORAGE_VOLUME:/data:ro" -v "$work:/backup" \
alpine:3 tar -C /data -cf /backup/storage.tar .
[ -s "$work/storage.tar" ] || echo "warning: storage volume appears empty" >&2
tar -C "$work" -czf "$out" db.dump storage.tar
echo "==> wrote $out ($(du -h "$out" | cut -f1))"