Skip to content

Operations and backup

How data is stored

<CHUSPA_DATA_DIR>/
  meta.db               index: chuspas, objects and multipart uploads
  blobs/ab/cd/<id>      content, with a random name generated by the server
  blobs/ab/cd/<id>.meta chuspa, key and object metadata
  chuspas/<name>        one marker per chuspa
  staging/              writes in progress

An object key is never used as a file path: ../../etc/passwd is a name like any other. Every write goes to staging/ first, is synced to disk, moved to blobs/ and only then committed to the index. A crash leaves the previous object or the new one, never a half-written one. Leftovers of interrupted writes are removed at startup.

Automatic maintenance

While the server runs:

EveryWhat it does
HourRemoves unreferenced blobs and aborts multipart uploads older than CHUSPA_MULTIPART_EXPIRY.
DayWrites a consistent copy of the index to meta.db.bak.
Week (CHUSPA_SCRUB_INTERVAL)Re-reads all content and compares it with its SHA-256; every damaged object is logged as an error and counted in chuspa_scrub_damaged_objects.

Backup

The safe way to back up is to copy the whole data folder with the server stopped:

docker compose stop chuspa
tar -C /path/to/data -czf chuspa-$(date +%F).tar.gz .
docker compose start chuspa

Restoring means putting that folder back and starting. Then chuspa verify confirms everything is intact.

If you cannot stop the server, copy blobs/ and chuspas/ while it runs (for example with rsync or a volume snapshot). When restoring that copy, run chuspa rebuild-index before starting: it builds the index from what was copied, without relying on a meta.db taken in the middle of a write. Whatever was written while the copy ran may be missing.

If the index is damaged or lost

With the server stopped:

CHUSPA_DATA_DIR=/path/to/data chuspa rebuild-index
CHUSPA_DATA_DIR=/path/to/data chuspa verify

In Docker, with the same image and volume:

docker compose stop chuspa
docker compose run --rm chuspa rebuild-index
docker compose run --rm chuspa verify
docker compose start chuspa

rebuild-index builds a new index from the metadata stored next to each blob and from the chuspa markers. It deletes nothing:

  • it renames the previous index to meta.db.reemplazado-<date>;
  • it moves to recuperados/ whatever it cannot assign to an object: parts of incomplete uploads and old versions left by a crash.

All objects and all chuspas are recovered, including empty ones. Multipart uploads in progress are not.

Verify the content

CHUSPA_DATA_DIR=/path/to/data chuspa verify

It re-reads every object and compares it with its size and SHA-256. It exits with an error if anything is damaged, and lists each case with its chuspa and key. A damaged object is recovered from the backup.

Inspect without the API

Since keys live in the index, data cannot be browsed with ls. With the server stopped:

chuspa inspect                                   # chuspas, with object count and bytes
chuspa inspect feria-de-cali test/               # objects of a chuspa, by prefix
chuspa export feria-de-cali test/salsa.txt ./salsa.txt

Full disk

Below CHUSPA_MIN_FREE_MB free (1 GiB by default), writes return 507 InsufficientStorage and reads keep working. A disk that truly fills up during a write returns the same error, leaving nothing half-written.

Upgrading

  1. Back up the data folder with the server stopped.
  2. Replace the image or binary with the new version, using its exact version.
  3. Start it: the new version migrates the data format on its own, for example from 0.1.x and 0.2.x to the current format.
  4. Run chuspa verify.

An old version refuses to open data from a newer one, so it does not damage it. Migration from real data of previous versions is tested on every change.

Shutdown

On SIGTERM (what docker stop sends), the server stops accepting connections and waits up to 30 seconds for in-flight requests to finish.