clipwright/ops/README.md
pedro-bento ace54c6e77
Some checks are pending
CI / backend-tests (push) Waiting to run
CI / frontend-build (push) Waiting to run
chore: rename OpenShorts to Clipwright
- Rebrand all text, package/CLI (clipwright_cli), env vars (CLIPWRIGHT_*),
  localStorage keys, Docker container names and webhook header
- Rename/relocate assets, skills/, n8n examples, font map; delete dead MCP
  metadata (server.json, glama.json) and generated egg-info
- Canonical site URL -> https://git.pbento.pt/pedro-bento/clipwright
- Preserve fork provenance (upstream OpenShorts attribution in README/NOTICE/LICENSE)
2026-10-04 18:07:07 +01:00

91 lines
3.6 KiB
Markdown

# ops/
Operational scripts for Clipwright Cloud. Nothing here runs automatically:
each file is installed and scheduled on the host that needs it.
## `pg_backup.sh` — encrypted PostgreSQL backups, 30-day retention
The only backup mechanism this project has ever had in version control. Art.
32.1.c GDPR requires being able to restore availability of personal data after
an incident, and the privacy policy now states that a deletion is gone from
every copy within 30 days — this script is what makes both sentences true.
### What it does
1. `pg_dump` the cloud database (plain SQL, `--no-owner --no-privileges`).
2. gzip and **encrypt** it, in the same pipeline, with `age` (recommended) or
`gpg`. Only ciphertext ever touches the disk or the bucket. Without a
recipient key configured the script exits with an error rather than writing a
readable dump — a plaintext copy of `users` in an object store is the
incident this file exists to prevent.
3. Upload to `s3://…` (works with Cloudflare R2 via `BACKUP_S3_ENDPOINT`) or
`gs://…`.
4. Delete backups older than `RETENTION_DAYS` (default 30).
### Install
```bash
# On the database host (el servidor de la base de datos), as root:
apt-get install -y postgresql-client age awscli # or gnupg instead of age
install -m 0750 ops/pg_backup.sh /opt/clipwright/ops/pg_backup.sh
```
Generate a key pair **on your laptop, not on the server** — the server only
ever needs the public half, which is the whole point:
```bash
age-keygen -o clipwright-backup.key # keep this file in a password manager
grep 'public key' clipwright-backup.key # -> age1... goes on the server
```
Then create `/etc/clipwright-backup.env` (mode `0600`):
```sh
DATABASE_URL="postgres://user:pass@127.0.0.1:5432/clipwright"
BACKUP_AGE_RECIPIENT="age1................................................"
BACKUP_DEST="s3://clipwright-backups/pg"
BACKUP_S3_ENDPOINT="https://<accountid>.r2.cloudflarestorage.com"
AWS_ACCESS_KEY_ID="..." # an R2 token scoped to THIS bucket only
AWS_SECRET_ACCESS_KEY="..."
RETENTION_DAYS=30
```
Dry run first — it dumps and encrypts locally but uploads nothing:
```bash
set -a; . /etc/clipwright-backup.env; set +a
DRY_RUN=1 /opt/clipwright/ops/pg_backup.sh
```
Schedule it:
```cron
15 3 * * * set -a; . /etc/clipwright-backup.env; set +a; /opt/clipwright/ops/pg_backup.sh >> /var/log/clipwright-backup.log 2>&1
```
### Restore (do this once, before you need it)
```bash
aws s3 cp --endpoint-url "$BACKUP_S3_ENDPOINT" \
s3://clipwright-backups/pg/clipwright-pg-20260904T031500Z.sql.gz.age .
age -d -i clipwright-backup.key clipwright-pg-*.sql.gz.age | gunzip \
| psql "postgres://…/clipwright_restore_test"
psql "postgres://…/clipwright_restore_test" -c 'select count(*) from users;'
```
A backup nobody has restored is a hypothesis. Write down the date of the last
successful restore test somewhere a person will read.
### Things to keep true
- **The bucket is not public and not the same bucket as user clips.** Give the
backup token write access to its own bucket and nothing else.
- **The private key is not on the server.** If it were, an attacker with the
server has both the ciphertext and the key.
- **`RETENTION_DAYS` and the privacy policy move together.** The policy tells
users a deletion disappears from backups within 30 days
(`docs/compliance/retencion.md`, `dashboard/seo/legal.js` §5). Raising the
retention without changing that text makes the policy false.
- **Object-lock / versioning on the bucket would defeat the retention.** If you
enable it for ransomware protection, set the lock window to the same 30 days,
not longer.