Skip to content

sow retain

Keep the package files and manifest of a Generation so local GC cannot reclaim them, or release them again.

Each build replaces the current Generation, and once nothing else refers to them, sow gc may delete packages that only the old Generation used. sow retain marks a Generation to keep: it verifies the Generation, saves a frozen copy of its manifest and metadata references in private state, and makes local GC keep every package file it needs. The packages stay in the shared pool, so retention copies nothing. It does not restore or publish the old view; it keeps the bytes and the record of what that Generation contained.

Synopsis

sow retain add GENERATION [-C|--workdir DIR] [-r|--repo NAME] [-T|--timeout DUR | -N|--no-wait] [--json]
sow retain ls             [-C|--workdir DIR] [-r|--repo NAME] [--json]
sow retain rm GENERATION  [-C|--workdir DIR] [-r|--repo NAME] [-T|--timeout DUR | -N|--no-wait] [--json]

GENERATION is a decimal integer greater than zero.

Options

Flag Commands Meaning
-C, --workdir DIR all Workspace discovery start directory
-r, --repo NAME all Select a repository (selection rules)
-T, --timeout DUR add, rm Maximum lock wait; 0 (default) waits indefinitely
-N, --no-wait add, rm Fail immediately when the lock is held
--json all Output JSON

retain add

retain add accepts only the current Generation, so run it right after the build you want to keep and before the next build replaces it. Take the number from sow status or the build output:

sow retain add 12 -r pgsql
retained generation 00000000000000000012: /srv/sow/.sow/pgsql/retained/00000000000000000012

Any other Generation is rejected with exit 6:

sow retain add 5
operation rejected: managed: operation rejected: retained/v1 add requires the current Built Generation

Adding the same Generation again changes nothing, provided its retained record still passes verification.

retain ls

sow retain ls -r pgsql
GENERATION	RECORD_IDENTITY	PATH
00000000000000000012	678beeae...	/srv/sow/.sow/pgsql/retained/00000000000000000012

An empty list is a successful result.

retain rm

retain rm releases a Generation by removing its retained record:

sow retain rm 12 -r pgsql
removed retained generation 00000000000000000012

It deletes no package files. A later local sow gc reclaims them once no other record or operation needs them. Removing a Generation that is not retained is a no-op that succeeds.

Details

Interrupted removal

Before deleting a record, SOW writes a removal plan (.sow/<repo>/stage/retain-remove-<GENERATION>.plan.json) and moves the record to a tombstone (.sow/<repo>/stage/retain-remove-<GENERATION>). If the removal stops halfway, rerun retain rm or run local sow gc; either replays the tombstone and finishes the job. Until then, the retained layer of sow check reports the unfinished removal.

Damaged records

If a retained record is damaged, retain rm, retain ls, local gc, and check report an error, and the retained layer of check names the Generation. To discard the damaged record:

  1. Stop workspace writers.
  2. Move .sow/<repo>/retained/<GENERATION> to a backup location outside the workspace.
  3. Run sow check again.

Moving the record also removes its protection against GC.

Exit behavior

Code Trigger
0 Operation completed, including an empty list or a no-op
1 Filesystem or runtime I/O failure
2 Invalid Generation syntax, discovery error, or implicit repository selection is ambiguous
4 Write lock unavailable for add or rm
5 Generation manifest or repository state is inconsistent
6 Explicit repository is not configured, retain add does not name the current Generation, or another safety rule rejects the request

See also

  • sow gc — reclaim packages that no retained Generation needs
  • sow changes — compare a Generation with an earlier one
  • Repository Layout — where retained records live

Table reader