# Backup storage Backup **content** lives in a repository; the **catalog** (what exists, where, and when) lives in PostgreSQL. **Back up the database too**: rebuilding the catalog from the repository alone is planned (manifests, below) but not built. Until then, a repository connected to a new, empty database keeps its data safe but cannot be browsed. ## Repository format - **Content-addressed**: every blob is stored under the hash (BLAKE3) of its plaintext, so identical content (the same attachment sent to 500 people, an unchanged Entra object) is stored once. - **Chunking**: content is split into fixed 4 MiB chunks. Content-defined chunking (FastCDC) can replace it later without a format change, because chunks are addressed by hash, not position. For the initial target (< 50 GB, mostly mail and Office files that change as a whole) fixed chunks give nearly the same deduplication. - **Packing**: small blobs are packed into ~16–64 MiB pack files to avoid millions of tiny objects (important for S3 cost and filesystem inodes). - **Compression**: zstd. - **Encryption**: AES-256-GCM per blob. A random repository data key is wrapped by a key derived (Argon2id) from the admin's repository passphrase. Losing the passphrase means losing the backups; the UI makes the admin download a recovery kit at setup. - **Self-describing** (planned): each snapshot also writes a small encrypted manifest into the repository so the catalog can be rebuilt (disaster recovery of the backup server itself). - **Catalog generation**: a counter kept both in the database and in the repository (`generation/`, one file per number; the highest counts). Every catalog commit of a backup raises the database's number in the same transaction, then writes it to the repository. If the repository's number is ahead, the database is older than the repository (a new server, or an older database dump restored, even one taken while a backup ran) and does not know all of its data. Retention then reclaims no space, since data the database does not know about would look unreferenced, and it warns. Restoring the newest database dump ends this. Repairing unreadable data (`repository-check --repair`) deletes only the unreadable blobs, so it is safe either way. ## Setting up storage *Administration → Backup storage* creates a repository (or connects one that already exists, e.g. on a new server after a disaster). Filesystem repositories must be inside the backup volume (`S365B_REPOSITORY_PATH`, `/repo` in the container); mount extra disks or NFS/SMB shares below it. This keeps the web UI from writing anywhere else in the container. The passphrase is stored encrypted with the server's master key, so scheduled jobs can open the repository. The **recovery kit** (passphrase, repository ID and a copy of the encrypted key file) is offered as a download at creation and can be downloaded again by an admin; every download is audited. ## Storage backends | Backend | Use | |--------------|-------------------------------------------------| | `filesystem` | **Default.** Local disk, or NFS/SMB mounted into the container | | `s3` | AWS S3, MinIO, Wasabi, Backblaze B2, Ceph RGW, … | Backends implement a small interface (`put`, `get`, `list`, `delete`, `exists`), so Azure Blob or others can be added later. Several repositories can exist, and each backup job targets one. A **copy job** can replicate a repository to a second target (3-2-1). ## Immutability On S3 backends with **Object Lock**, pack files are written with a retention date matching the job's retention. Deletes before that date are refused by the storage itself, protecting against ransomware and a compromised admin. ## Catalog and point-in-time Each backed-up item has versions with a validity window: ```text item_version(item_id, version_no, valid_from, valid_to, deleted, blob_refs, metadata) ``` Browsing "as of T" means: versions where `valid_from <= T` and (`valid_to` is null or `valid_to > T`) and not deleted. This gives point-in-time restore without full snapshots of every mailbox each run. ### Changing a job's repository The catalog is one history per item. Repositories are where its versions are kept: each version records its repository, and a restore reads from it. A job can be moved to another repository, or a second job can back up the same items into one: - The sync state remembers the repository it was saved for. A backup into another one starts from what the module keeps of it (`BackupModule.state_for_new_repository`): Exchange re-lists every mail folder and drops its delta tokens; Entra ID reads everything each run anyway. - Every current item gets a new version in the new repository, even when it has not changed, along with its restore copies. Unchanged items count as unchanged and raise no change alerts. Because blob IDs are keyed per repository, "unchanged" compares name, folder, metadata and size. - Deletions found during that run are recorded as usual, so afterwards the new repository alone holds every current item. Older versions stay in the old repository until retention removes them. The first run after a move takes about as long as a first backup; the job form says so. Two jobs that alternate between repositories for the same items repeat that copy on every run, so use one job per mailbox. ## Retention (built) Point in time, per **repository** (Administration → Retention): keep restore points for N days (Forever by default; presets 1, 3 and 7 years, or custom). Every backup in the period can be restored exactly. A version is removed only when it was replaced or deleted before the period started, or it is a deletion marker older than the period. Anything still in Microsoft 365 is always kept. - **Holds** on protected objects (reason, who, when; audited) exempt them. - **Preview** before saving shows the versions, items and size the next run removes; shortening the period needs an explicit confirmation. - A **nightly retention run** (hour configurable) prunes the catalog, then compacts the repository: packs holding only unreferenced blobs are deleted, packs with at least 20% garbage are rewritten (sealed blobs copied, never decrypted; new packs written before old ones are deleted). It shows in Recent runs, is audited, and raises an alert on failure. - Locking: backups hold a Postgres advisory lock on the repository *shared*; retention takes it *exclusively* without waiting. If a backup is writing, the run is recorded as skipped and retried every 30 minutes (up to 6 hours). - The audit log (default 6 years) and alerts (default 1 year) are purged on the same schedule. Later: thinning (GFS-style: fewer old restore points), item-age deletion per module, Object Lock dates on S3.