# Backup and restore

> Back up objects and IAM with PostgreSQL tools, and restore them.

---

LLMS index: [llms.txt](/llms.txt)

---

Because `pgsilo` gateways are stateless, backing up the PostgreSQL cluster backs up all objects, versions, multipart parts, annotations, bucket policies, and IAM accounts together. Complete disaster recovery requires a **physical PostgreSQL cluster backup**, a continuous **archived WAL stream**, and separately preserved **external secrets** (especially static SSE-S3 KMS keys).

## Preserve the complete recovery set {#recovery-set}

The PostgreSQL database stores all of the following in transactional consistency:

- Object byte segments, version metadata, and delete markers
- Active multipart upload state and uploaded parts
- Object annotations, annotation payloads, and the orphan cleanup queue
- Bucket configurations, quotas, Object Lock policies, S3 IAM users/policies/service accounts, and native PostgreSQL role bindings (`silo.native_auth_principals`)
- Schema migration ledger (`silo.meta`) and control-plane revision tokens

Physical backups preserve database tables, role OIDs, and relation OIDs, but you must back up these external items independently:

- The exact `silo` binary version and checksums matching the database schema version (`schema_version = 14`)
- Gateway environment configuration (`/etc/default/silo`), S3 root credentials (`MINIO_ROOT_USER` / `MINIO_ROOT_PASSWORD`), and every static SSE-S3 master key (`MINIO_KMS_SECRET_KEY` / `MINIO_KMS_SECRET_KEY_FILE`) ever used to encrypt retained objects
- PostgreSQL and S3 TLS certificates, private keys, CA bundles, and webhook notification target credentials

> [!CAUTION]
> Never store the only copy of your PostgreSQL backup repository or KMS keys inside the same `pgsilo` S3 service that depends on the database being backed up. Without the matching static SSE-S3 key or customer SSE-C key, restored encrypted rows in PostgreSQL cannot be decrypted.

## Physical backup with pgBackRest {#pgbackrest}

Configure an independent `pgBackRest` repository, WAL archiving, and retention policy on your PostgreSQL cluster, then verify and run a full physical backup on the database host:

```bash
sudo -u postgres pgbackrest --stanza=YOUR_STANZA check
sudo -u postgres pgbackrest --stanza=YOUR_STANZA --type=full backup
sudo -u postgres pgbackrest --stanza=YOUR_STANZA info
```

Confirm that `pgbackrest info` reports a valid backup timestamp and continuous WAL archive range.

## Rehearse physical restore and PITR {#rehearse-restore}

1. **Select the recovery target** (timestamp, LSN, or transaction ID) and prepare an isolated PostgreSQL host so the restored cluster does not conflict with production.
2. **Restore the cluster and replay WAL** to the target point using `pgBackRest`. Deploy the `silo` binary version compatible with the restored `schema_version` (`14`).
3. **Install matching external configuration and secrets**: restore `/etc/default/silo`, static `MINIO_KMS_SECRET_KEY` values, and TLS certificates. Start gateways pointing only at the restored database.
4. **Verify data and authorization**:
   - Check plaintext and SSE-S3 object SHA-256 digests, version histories, and delete markers.
   - Verify multipart uploads, object annotations, and ZIP extraction.
   - Test both allowed and denied requests for S3 IAM users and `silo_api` SQL roles, plus bucket quotas and Object Lock retention.
   - Review any IAM credential revocations or policy changes that occurred *after* the PITR target timestamp, since point-in-time recovery restores the IAM state as of that earlier timestamp.
5. **Check health and maintenance leases** (`/minio/health/cluster/read`, `/minio/health/cluster`, and `minio_pg_lifecycle_leader`) before opening client traffic.

Application rows and `silo_api` object writes committed in the same SQL transaction recover atomically to the same point in time. Note that PostgreSQL PITR cannot recall webhook notifications already delivered to external endpoints before the rollback point.

## Why logical `pg_dump` is not a drop-in migration {#logical-dump-limits}

`pg_dump` exports SQL tables and definitions, but `pgsilo` records PostgreSQL internal **role OIDs** and **relation OIDs** (`regclass` / `oid`) inside `silo.bucket_acl` and `silo.native_auth_principals`. Restoring a logical dump into a new PostgreSQL cluster assigns different OIDs to roles and ACL tables, breaking native authorization and SQL bucket ACL lookups.

Current `pgsilo` builds do not include an automated cross-cluster OID remapping utility. Always use physical cluster backup and restore (`pgBackRest` / `pg_basebackup` + WAL replay) for full disaster recovery, and never manually edit private OID columns in `silo.*` tables.

---

Backlinks:

- [Compatibility](/docs/s3/compatibility/)
- [Operations](/docs/s3/operations/)
- [Upgrade](/docs/s3/operations/upgrade/)
- [Encryption](/docs/s3/tutorial/encryption/)
