← All lessons/Operations
43
Operations

Snapshots & Backups

Create point-in-time snapshots, list them, and restore from them.

Prerequisite: Lessons 42 and 44 complete

What you'll learn

  • POST /v1/snapshots — name, description
  • GET /v1/snapshots — list all snapshots with size and ts_hlc
  • POST /v1/snapshots/:id/restore — replace current data with snapshot
  • Restore warning: records written after snapshot are lost
  • Best practice: maintenance mode before restore, checkpoint before snapshot
Challenge

Create a snapshot. Write 5 more records. Restore the snapshot. Confirm the 5 records are gone.

Interactive Walkthrough

What you'll learn

Create point-in-time snapshots, list them, and restore from them.

Create a snapshot

curl -s -X POST http://localhost:7475/v1/snapshots \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY" \
  -d '{"name": "pre-migration-2026-07-09", "description": "before schema change"}' \
  | python3 -m json.tool

Response: `json { "snapshot_id": "snap_a1b2c3d4", "name": "pre-migration-2026-07-09", "ts_hlc": 1751900065536000, "agents": ["users", "orders", "payments"], "size_bytes": 10485760 } `

List snapshots

curl -s http://localhost:7475/v1/snapshots \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY" \
  | python3 -m json.tool

Restore from a snapshot

curl -s -X POST http://localhost:7475/v1/snapshots/snap_a1b2c3d4/restore \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY" \
  | python3 -m json.tool

Warning: Restore replaces current strand data with the snapshot state. Any records written after the snapshot was taken are lost. Always write to maintenance mode before restoring.

Best practice backup script

#!/bin/bash
DATE=$(date +%Y-%m-%d)
curl -s -X POST http://localhost:7475/v1/snapshots \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $SAPIX_ROOT_KEY" \
  -d "{\"name\": \"daily-$DATE\", \"description\": \"Automated daily backup\"}"

Run this daily via system cron: 0 2 * * * /path/to/backup.sh

Challenge

Create a snapshot, write 5 more records, restore the snapshot, confirm the 5 records are gone.

---

← Previous
Lesson 42: Epigenetic Profiles
Next →
Lesson 44: WAL & Checkpoints