Replication, Backups & PITR
HTTP WAL streaming replication, fenced promotion, verified online base backups, and exact-LSN PITR.
SpydDB supports both online HTTP WAL streaming replication with automatic split-brain epoch fencing and verified online base backups + non-destructive Point-In-Time Recovery (PITR) into isolated new databases.
1. Physical WAL Streaming Replication (/v1/replication/*)#
Stream encrypted/checksummed WAL frames cleanly over HTTPS between primary and standby nodes without requiring shared network storage.
Start Following a Primary Node#
Run on the standby server:
curl -fsS -X POST --cacert tls/ca.crt https://standby-1.internal:8080/v1/replication/follow \
-H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"primary_url": "https://primary.internal:8080",
"interval_ms": 50
}'Inspect replica state, head LSN, and fencing epoch at any time:
curl -fsS --cacert tls/ca.crt https://standby-1.internal:8080/v1/replication/status \
-H "Authorization: Bearer $SPYD_ADMIN_TOKEN"Primary Lease Renewal & Fenced Promotion#
The active primary maintains a monotonic epoch and lease TTL (/v1/replication/lease/renew). Promoting a standby actively fences the prior primary at a higher epoch first so split-brain writers return 503 primary_fenced:
# Promote standby safely (fences old primary before accepting writes)
curl -fsS -X POST --cacert tls/ca.crt https://standby-1.internal:8080/v1/replication/promote \
-H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"primary_url": "https://primary.internal:8080",
"node_id": "standby-1",
"lease_ttl_ms": 10000
}'2. Online Base Backups, Verification & PITR Restore#
Configure "backup_root": "/var/lib/spyd/backups" in server.json. All backup and WAL archive names are validated as safe single directory names (preventing path traversal and symlink escapes).
# 1. Take a consistent online base backup
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/admin/backups \
-H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "daily-2026-11-27"}'
# 2. Verify checksums & decode every row and segment read-only from the backup copy
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/admin/backups/verify \
-H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "daily-2026-11-27"}'
# 3. Capture a WAL archive snapshot for fine-grained PITR recovery
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/admin/wal/archive \
-H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "wal-2026-11-27-21h"}'
# 4. List all available base backups and WAL archives
curl -fsS --cacert tls/ca.crt https://localhost:8080/v1/admin/backups \
-H "Authorization: Bearer $SPYD_ADMIN_TOKEN"Non-Destructive PITR Restore Into a New Database#
SpydDB never overwrites a live database during restore. Specify a target "database" name along with optional "wal_archive", "lsn", or microsecond "time_us" point-in-time boundary:
curl -fsS -X POST --cacert tls/ca.crt https://localhost:8080/v1/admin/restore \
-H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"backup": "daily-2026-11-27",
"wal_archive": "wal-2026-11-27-21h",
"lsn": 18420,
"database": "recovery_probe"
}'Query "recovery_probe" immediately over X-Spyd-Database: recovery_probe or pgwire while existing production traffic continues undisturbed.
3. Logical Replication Slots & Consistent Snapshot Export#
For CDC downstream consumers and analytical warehouses, export a transactionally consistent snapshot carrying its global change sequence, then stream forward from a durable named slot:
- Bootstrap snapshot (
snapshot.json+snapshot.ndjson): Captures every collection's exact schema field order and commitsequencenumber atomically. - Logical Change Log Retention: Bounded via
logical_max_bytesandlogical_max_age_secsand guarded by the oldest confirmed replication slot so consumers never experience silent data gaps.