Deployment and operations#
scrap is one service over one data folder, run from the same container image either way:
systemd and rootless podman on a single server, or the Helm chart on Kubernetes, where the
database sits on the node’s disk and Litestream replicates it into the data folder. On a single
server, scheduled work (backup, gc, enrichment) runs as systemd timers. On Kubernetes, backups are
CronJobs, and gc and the Claude passes run in a jobs container in the scrap pod. Step by step:
Deploy on a single server, Deploy on Kubernetes.
Colours: blue is storage, orange is work that calls Claude, green is the person using scrap.
Single server#
systemd user units run one rootless podman container; Tailscale Serve is the only way in (16. Deployment: rootless podman units for one server, a Helm chart for Kubernetes, 18. Single-server installs listen on a Unix socket, reached only through Tailscale Serve).
flowchart TD
me(["Phone / browser"]):::user
subgraph host["One unix user, rootless podman"]
ts["Tailscale Serve"]
subgraph units["systemd user units"]
svc["scrap.service"]
tb["backup timers<br/>daily + monthly"]
tg["gc timer"]
tr["enrich-related timer"]
tt["enrich-topics timer"]
end
app["scrap container<br/>(serve)"]
data[("SCRAP_DATA<br/>scrap.db + files/")]:::store
bak[("SCRAP_BACKUPS<br/>timestamped runs + monthly/")]:::store
end
me -->|HTTPS, tailnet| ts
ts -->|"Unix socket<br/>scrap.sock"| app
svc -->|scrap-run| app
app --- data
tb -->|"scrap-backup<br/>(--network=none)"| bak
tb -.->|reads| data
tg -->|"scrap-gc<br/>(--network=none)"| data
tr -->|"podman exec<br/>enrich --related"| app:::claude
tt -->|"podman exec<br/>enrich --topics"| app
classDef store fill:#e8f1ff,stroke:#4a7bd0
classDef claude fill:#fff3e0,stroke:#e08a00
classDef user fill:#e9f7ef,stroke:#2e9d5b
Piece |
What it does |
|---|---|
|
|
Listener |
|
Backup, gc |
Separate throwaway containers with |
Enrichment |
|
Image |
One multi-arch image (amd64 + arm64) from the release workflow |
Five timers, all Persistent except gc:
Timer |
When |
Runs |
|---|---|---|
|
daily 03:30 |
backup, then retention |
|
1st of the month 03:50 |
backup into |
|
daily 03:41 |
|
|
Sundays 04:11 |
|
|
daily 04:30 |
|
Each has a 15 minute random delay. install.sh enables a timer only if the installed image has
its command, and says so when it does not.
Kubernetes#
The chart runs exactly one replica with the Recreate strategy, because SQLite has a single
writer (3. One process, one SQLite database, one folder of files). The database is not on the
data volume: it is on an emptyDir on the node’s disk, and Litestream replicates it into the data
volume, because SQLite’s WAL is not safe on NFS or another network filesystem
(46. The database on an emptyDir, replicated with Litestream).
flowchart TD
me(["Browser"]):::user
subgraph edge["Edge (your choice)"]
ing["Ingress<br/>Cloudflare Access or<br/>the DLS login proxy"]
end
subgraph ns["Release namespace"]
np["NetworkPolicy<br/>(optional)"]
svc["Service :80"]
subgraph pod["scrap pod (1 replica, Recreate)"]
init["init: litestream-tool,<br/>db-init"]
app["scrap serve"]
ls["litestream<br/>(native sidecar)"]
jobs["jobs: scrap schedule<br/>gc 04:30, enrich-related 03:41,<br/>enrich-topics Sun 04:11"]
db[("emptyDir /db<br/>scrap.db")]:::store
end
pvc[("Data volume /data<br/>files/ + litestream/")]:::store
cb["Backup CronJobs<br/>03:30 + monthly 1st"]
bk[("Backups<br/>timestamped runs + monthly/")]:::store
end
me --> ing --> np --> svc --> app
init -->|"restore or place"| db
app --- db
app --- pvc
ls -->|"replicates"| pvc
jobs -.-> db
jobs -.->|"gc needs recent<br/>COMPLETE"| bk
cb -->|"restore of the replica<br/>+ files/"| bk
cb -.-> pvc
classDef store fill:#e8f1ff,stroke:#4a7bd0
classDef claude fill:#fff3e0,stroke:#e08a00
classDef user fill:#e9f7ef,stroke:#2e9d5b
Where the data is.
/db/scrap.db(SCRAP_DB_PATH) is on an emptyDir capped bylitestream.sizeLimit(2Gi)./datakeepsfiles/, the regenerable preview cache (never backed up) and the replica,/data/litestream. The data volume may be NFS.Starting. An init container copies the Litestream binary in;
scrap db-initthen keeps a database already on the emptyDir, takes up a staged restore, or restores the replica, and refuses to start when an install with history (a state file, files, backups) has no replica. Litestream runs as a native sidecar (Kubernetes 1.29 or newer), so it starts before scrap and stops after it.What can be lost. About a second of writes if the node dies; none on a clean stop. If replication stalls for 20 minutes, the
jobscontainer’s readiness probe fails and the pod leaves its Service, so scrap stops taking writes it could lose.Scheduled work. gc and, with ingest on, the related and topics passes run in the pod’s
jobscontainer (scrap schedule), on the live database.scrap schedule status(and opt-in Prometheus metrics) report each job’s last run. The backups stay CronJobs:scrap backup --from-replicachecks and backs up a restore of the replica with/data/files. They run on the scrap pod’s node, as the data claim isReadWriteOnce.No login in scrap. Reach it only through an authenticating proxy: Cloudflare Access, or the DLS login proxy (oauth2-proxy and Keycloak, the chart’s
authProxy), whose token scrap verifies.identityHeadernames the header recorded as the author andmcp.tokenSecretcan require a bearer token on/mcp(23. Bearer token on /mcp and an identity-header setting, 45. scrap verifies the login proxy’s Keycloak token).Public pages (optional,
public.enabled) run in a pod of their own, nginx and the upload receiver from thescrap-publicimage; scrap pushes to the receiver and the public site never talks to scrap (Public site).Secrets are never values. The chart names an existing Secret for the API key, notify URL and MCP token and never creates one. The PVCs carry
helm.sh/resource-policy: keep.Hardening. Restricted Pod Security: non-root uid 10001, read-only root filesystem, all capabilities dropped,
RuntimeDefaultseccomp.Health.
GET /healthzreturns 200 withstatus,version,max_upload_bytes,paused(why the Claude queue is paused, else null) andpublish(the public site’s state); 503 if the ingest worker has stopped. The pod is ready only while thejobscontainer sees replication working.
Settings are in HTTP API and CLI; every chart value is in charts/scrap/values.yaml,
checked by values.schema.json.
Data protection loop#
Backup, retention, gc and restore form one loop, and gc will not delete unless the loop has recently worked.
flowchart LR
b["Backup<br/>SQLite online backup<br/>+ files/ copy"] --> v["Integrity check<br/>write COMPLETE"]
v --> r["Retention<br/>keep newest N"]
r --> g{"COMPLETE run<br/>under 26 h old?"}
g -->|yes| d["gc --delete"]
g -->|no| c["gc counts only,<br/>job fails loudly"]
r -.-> x[("Backups<br/>newest N runs")]:::store
x --> s["Restore"]
s --> k{"Checks"}
k -->|"integrity ok<br/>schema not newer"| ok["Swap in DB,<br/>add files"]
k -->|"non-empty dir<br/>without --force"| no["Refused"]
classDef store fill:#e8f1ff,stroke:#4a7bd0
Backup is safe while serving. It snapshots the database first and copies
files/second. Blobs are written before the transaction that names them, so the snapshot never names a missing file.COMPLETEmarks a good run. Only a checked snapshot gets one; a failed run’s directory is removed and older runs are untouched.Retention (
SCRAP_BACKUP_KEEPon a single server,backup.keepin the chart; install.sh writes 14, the chart defaults to 7) deletes only directories named like a run (20261019T033000Z); symlinks and other files are never touched. Both add a monthly tier inmonthly/(backup.monthlyin Helm,SCRAP_BACKUP_MONTHLY_KEEPon a single server; newest 12) for changes noticed late.gc follows backup. It takes the same lock, so a file removed mid-backup cannot be one the backup’s database names. Without a recent
COMPLETErun it only counts and exits non-zero, so a missing backup shows up as a failed job.On Kubernetes the backup reads the replica.
scrap backup --from-replicarestores the replica to a temporary file and backs that up with/data/files. It refuses a replica whose heartbeat (stamped every 15 minutes byscrap schedule) is over 3 hours old, so a stalled replica fails the job rather than writing aCOMPLETErun that gc would trust. gc there also only counts, and fails, when the files it would delete are over 10% of them and at least 5, or the database has no captures beside stored files (--allow-largeafter a person has looked), and after an override, untilscrap db-hold --clear. For 14 days after a restore it only counts without failing; that hold ends by itself, or sooner withscrap db-hold --clear.Restore copies the backup database beside the live one and opens only the copy, so read-only media work. The copy must pass
integrity_checkand not be from a newer schema than the code; it is then migrated and swapped in. Files are only added. A refusal leaves the data folder as it was, and a non-empty folder needs--forcewith scrap stopped. On Kubernetes a restore is staged instead (scrap restore --stage): the next pod start takes it up in place of the replica.A local copy is not an off-site copy. Copy
SCRAP_BACKUPS(or the backup volume) elsewhere.
See also#
Architecture, the architecture landing page; Data model and storage for the database and files; MCP server and access for tokens and identity; Job queue and Claude features for the Claude passes the schedules start.
Scheduled jobs and HTTP API and CLI for commands and settings.
ADRs: 3. One process, one SQLite database, one folder of files, 7. Tailscale Serve is the only way in; no login code, 16. Deployment: rootless podman units for one server, a Helm chart for Kubernetes, 18. Single-server installs listen on a Unix socket, reached only through Tailscale Serve, 21. Ingest on a Claude seat: claude -p with a long-lived token, 23. Bearer token on /mcp and an identity-header setting, 45. scrap verifies the login proxy’s Keycloak token, 46. The database on an emptyDir, replicated with Litestream.