Repository Public
1# Backup and restore23**Status: scripts built; a restore drill runs in the automated tests (`tests/studio-ops.test.ts`). No backup has ever been taken of a real deployment — there is none.**45## What must survive67| What | Where | In a default backup |8|---|---|---|9| Database: editors and passkeys (public keys), working copy, every section body and figure, publications, audit log, jobs | `ATLAS_DATA_DIR/atlas.db` | **yes** — consistent snapshot (`VACUUM INTO`), taken while the site runs |10| Downloadable resources, all versions | `resources/` | **yes** |11| Captions, transcripts, chapters | `media/**.vtt`, `media/**.json` | **yes** |12| Slide decks (SVG, thumbnails) | `slides/<session>/<deck>/` | **no** — rebuild the packs from the course repository (`pnpm slides:build`) and import them again; the deck metadata and its publication are in the database |13| Original videos | `masters/<sha256>.<ext>` | no — listed in `media-manifest.json`; `--with-masters`, or rsync |14| Encoded renditions, posters | `media/**` | no — regenerable from masters; `--with-media` |15| Code and committed snapshot | git | by git |16| Learner progress | each visitor's browser | cannot be backed up by the server |1718## Commands (on the node, as the app's user)1920```bash21pnpm studio backup # → $ATLAS_DATA_DIR/backups/<UTC timestamp>/22pnpm studio backup --out /Volumes/X/atlas-2026-12-01 --with-masters --with-media23pnpm studio backup --keep 14 # retention: keep the 14 most recent in the backups directory24pnpm studio restore <backup-dir> --to <data-dir> [--force]25pnpm studio export <dir> [--with-resources] # readable export of all content and metadata (also: Outils → Exporter)26```2728A backup directory holds `atlas.db`, the copied files, `media-manifest.json` (every file under `media/` and `masters/` with its size, its SHA-256 when known, and whether it is in the backup) and `backup.json` (SHA-256 of every file in the backup, schema version, counts).2930**Before an upgrade**: `pnpm studio backup --out <somewhere off the data directory>`, then deploy. Migrations are forward-only; going back means restoring that backup with the previous code.3132## Restore33341. Stop both processes (`pm2 stop atlas-web atlas-worker`): they hold the database open.352. `pnpm studio restore <backup-dir> --to "$ATLAS_DATA_DIR"`. It verifies every checksum before touching anything; refuses a damaged backup or one from a newer application; refuses to replace an existing database unless `--force`, and then keeps the old one as `atlas.db.remplacee-<timestamp>`; replays migrations forward; runs `PRAGMA integrity_check`; prints the media files the backup does not contain.363. Bring back the listed masters/media (rsync from the other copy), or re-encode from masters (*Traitements → Relancer*, or re-attach the master).374. `pm2 start atlas-web atlas-worker`, then *Outils → Liens et intégrité* (or `pnpm studio links`) — it reports any file still missing for what is online.3839## Retention and off-node copy — proposal, to be decided with the owner (nothing is scheduled)4041- Daily `pnpm studio backup --keep 14` by a LaunchAgent/cron on the node; weekly copy of the newest backup **and of `masters/`** to another machine (`rsync -a --checksum`). A backup that stays on the same disk protects against mistakes, not against the loss of the node.42- Quarterly restore drill into a scratch directory (`--to /tmp/atlas-restore`), then `ATLAS_DATA_DIR=/tmp/atlas-restore pnpm studio health`.43- The audit log is never pruned.4445## Not built4647Scheduling, off-node transfer, encryption of backups (they contain passkey public keys and the audit log with IP addresses — keep them on trusted disks), alerting when a backup is missing, point-in-time recovery.48