Skip to content

feat: clean up old revisions according to a cleanup strategy - #3778

Merged
pbleser-oc merged 8 commits into
opencloud-eu:mainfrom
pbleser-oc:feat/1419-clean-up-file-versions
Nov 24, 2026
Merged

pbleser-oc merged 8 commits into
opencloud-eu:mainfrom
pbleser-oc:feat/1419-clean-up-file-versions

Conversation

@pbleser-oc

@pbleser-oc pbleser-oc commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Description

The OpenCloud side of the revision cleanup: old revisions (versions) of files are deleted according to a configurable cleanup strategy, for the decomposed, decomposeds3 and posix storage drivers. The cleanup itself is in reva, opencloud-eu/reva#895; this PR configures it and adds a command to run it on demand.

opencloud-eu/reva#895 is merged, and main already has a reva version with it (bumped in #4065), so this PR needs no reva bump of its own.

Configuration

A revisions_cleanup section of the storage-users configuration, passed to all three drivers, in the storage provider and the data provider:

environment variable default meaning
STORAGE_USERS_REVISIONS_CLEANUP_STRATEGY disabled which old revisions to delete whenever a file gets a new revision, e.g. auto, 30d, 10, 5, 30d or 7d, auto, 90d
STORAGE_USERS_REVISIONS_CLEANUP_ASYNC true run the cleanup in background workers, so it doesn't slow down the upload, restore or change on disk that created the revision
STORAGE_USERS_REVISIONS_CLEANUP_ASYNC_WORKERS 0 (half the CPUs, at least 2) number of background workers
STORAGE_USERS_REVISIONS_CLEANUP_ASYNC_QUEUE_SIZE 0 (64 per worker) number of files that can wait for a worker
STORAGE_USERS_REVISIONS_CLEANUP_ASYNC_QUEUE_FULL drop drop skips the cleanup of that file until its next revision, block waits for room, up to the timeout
STORAGE_USERS_REVISIONS_CLEANUP_ASYNC_QUEUE_FULL_TIMEOUT 5s how long block waits for room at most, after which the cleanup is skipped as with drop; 0 waits as long as it takes

The default keeps all revisions, as before. An invalid strategy makes the storage-users service fail at startup. The storage provider and the data provider share one cleanup, with one set of background workers, per storage (see opencloud-eu/reva#895). Other commands that create a storage driver, posixfs scan and uploads sessions, clean up without background workers, as they could exit before the workers are done.

opencloud storage-users revisions cleanup

The service only cleans up a file when it gets a new revision. The command covers the files that aren't changed anymore, and applies a different strategy once, e.g. after the strategy was changed or to free storage:

  • which files: --space (repeatable, with --path for a file or folder within the space), --all, or --fs-path (a file or folder by its path on disk, posix only); the id of a file or folder (<storage>$<space>!<node>) is rejected as a space, instead of cleaning up its whole space, and so is an id without a space id (<storage>$);
  • how: --strategy and the settings of the background workers (--async, --workers, --queue-size) default to the configured ones; only --queue-full defaults to block without a timeout (--queue-full-timeout 0), whatever is configured, as the command finds files faster than the workers clean them up, and dropping the ones that find the queue full would skip most of them;
  • output: a line for every file whose revisions were deleted, that failed or that was skipped, with its path within its space, and a summary; --verbose adds every revision with the decision and its reason; --json prints JSON objects, one per line;
  • --dry-run deletes nothing and changes nothing on disk, not even lock files: it doesn't keep the files locked while it decides, so its decisions are a snapshot. It always keeps its file metadata cache in its own memory, whatever is configured, so that it doesn't fill a shared cache with the metadata of every file it looks at;
  • --timeout stops gracefully, as does ctrl-c (or SIGTERM), which counts as a failure, though; a second ctrl-c ends the command right away, which can leave the blob of a deleted revision behind; --shuffle walks the spaces and folders in a random order, so that repeated runs, e.g. a nightly cron job, eventually reach all files;
  • exit codes: 0 when done, 1 if the cleanup or any file failed, or if it was interrupted (ctrl-c, SIGTERM), 2 if the timeout stopped it before all files were cleaned up.

Short flags: -a, -p, -s, -n, -v, -j, -t. The command uses the storage driver directly, in its own process, like uploads sessions: posix neither scans nor watches the file system, and no driver joins the postprocessing consumer group.

The file metadata cache must be shared. The command runs in a process of its own: with a cache that each process keeps in its own memory (memory, the default, or ocmem), the server doesn't learn about the revisions the command deletes. It lists the versions of a file from disk all the same, so a new list is right, but a list that is already open, e.g. in the Versions panel, keeps showing the deleted versions, and downloading or restoring one of them fails. Unless it is a dry run, the command therefore refuses to run with such a cache. The error names the fix, STORAGE_USERS_FILEMETADATA_CACHE_STORE=nats-js-kv (OC_CACHE_STORE would switch the cache of all services), and --allow-local-cache runs it anyway. As long as memory is the default, this is what admins see on a default setup; #4064 proposes nats-js-kv as the default. The acceptance tests pass --allow-local-cache, as their server runs with the default cache.

It has to run as the user OpenCloud runs as: the lock files it creates belong to the user that runs it, and OpenCloud may not be able to open them otherwise. Unless it is a dry run, it warns when the storage belongs to another user. A shared check for all commands that write to the storage is proposed in #4042.

opencloud storage-users revisions cleanup --all --strategy "auto, 90d" --dry-run --verbose
opencloud storage-users revisions cleanup --space <space id> --path /Documents --strategy 10
opencloud storage-users revisions cleanup --all --timeout 1h --shuffle

The storage-users README documents the configuration, the strategies, the command and its output, with examples. The admin documentation in opencloud-eu/docs follows separately.

Commits

  1. feat: 1419: configure the revision cleanup of the storage-users drivers
  2. feat: 1419: add a command to clean up old revisions on demand
  3. test: 1419: acceptance tests for the revision cleanup
  4. feat: 1419: refuse to clean up revisions with a file metadata cache local to each process
  5. docs: 1419: a restore keeps the revision of the replaced content
  6. feat: 1419: let a dry run of the revisions cleanup keep a cache of its own
  7. fix: 1419: describe what a file metadata cache local to each process does
  8. feat: 1419: clean up revisions by the time they were created

Every commit builds from vendor/ and passes the storage-users tests.

Related Issue

Motivation and Context

Every change to a file keeps the previous content as a revision, forever. Without a cleanup, revisions accumulate and use up storage, and the only way to get rid of them was to delete the files or to disable versioning, which keeps the revisions that exist. #1419 asks for a configurable cleanup that runs automatically, without slowing down writes, and that can also be run on demand for spaces, folders or files.

How Has This Been Tested?

  • unit tests: the configuration reaching all three drivers (revaconfig), and the command: flag validation, the strategy and worker defaults, the refusal with a cache local to each process and --allow-local-cache, the own cache of a dry run, text and JSON output, the exit codes (command)
  • acceptance tests: a new feature, tests/acceptance/features/cliCommands/cleanupFileVersions.feature, with 15 scenarios against a running server (14 without posix), checking the remaining versions through the WebDAV versions API: all spaces, a dry run, a folder within the personal space, a project space, the JSON output, no strategy while the configured one is disabled (exit code 1), a timeout (exit code 2), a strategy without spaces after its commas, a folder by its path on disk (posix only), the configured strategy cleaning up on every new version, without and with background workers (the default), also for uploads with TUS, the age of a version as the time it was created (30d keeps versions whose content is dated 60 and 50 days ago), a version with content dated 10 years ahead that doesn't push out the newest one under 1, and a restore that can be undone, as the content from before it is kept. Run locally on posix (15/15) and decomposed (14/14, the posix-only scenario is skipped), last on 2026-11-24, after the rebase onto main (reva at 20c6e7824); the dry run also with STORAGE_USERS_FILEMETADATA_CACHE_STORE=nats-js-kv (2026-11-18).
  • acceptance tests for changes on disk (posix): a second feature, tests/acceptance/features/collaborativePosix/cleanupFileVersions.feature, with 3 scenarios for the versions that changes on disk create (STORAGE_USERS_POSIX_ENABLE_FS_REVISIONS): the configured strategy cleans them up, with and without background workers, and so does the command. The collaborativePosix suite doesn't run in the CI for now (watch-fs. Flaky api tests #2036), so they are ready for when it does again; they passed locally 4 times in a row, and again with reva at a37f627e2. Since the rebase onto main, they sometimes fail at their very first upload, which comes back empty: that is posix: uploads of new files lose their content with the fs watcher and a short scan debounce delay (also the driver's default of 10ms) reva#1062 (new uploads lose their content when the posix watcher reacts quickly), not the cleanup (2026-11-24: one of two runs passed, in the other, two scenarios failed that way).
  • end to end: a scripted run against a single-binary server with posix: files with revisions created over WebDAV, then the command (dry run, a folder, JSON output, an invalid scope, a timeout, all spaces) next to the running server, checking the revisions on disk, the versions API and the file contents.
  • the reva side is tested in feat: clean up old revisions according to a cleanup strategy reva#895.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation added

AI assistance: Claude Code (claude-opus-5-5) wrote most of the code, the tests and the texts; I reviewed every change before pushing it.

@codacy-production

codacy-production Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 181 complexity

Metric Results
Complexity 181

View in Codacy

🟢 Coverage 79.15% diff coverage · +0.28% coverage variation

Metric Results
Coverage variation ✅ +0.28% coverage variation (-1.00%)
Diff coverage ✅ 79.15% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (dc749a3) 94500 28684 30.35%
Head commit (5e8a88a) 95042 (+542) 29111 (+427) 30.63% (+0.28%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3778) 542 429 79.15%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch 2 times, most recently from 5026cda to 1103975 Compare October 21, 2026 16:51
pbleser-oc added a commit to pbleser-oc/docs that referenced this pull request Oct 22, 2026
OpenCloud can now delete old file versions according to a cleanup
strategy (opencloud-eu/opencloud#1419, opencloud-eu/opencloud#3778).

- a new page, Cleaning Up Old Versions, in the storage configuration:
  what the cleanup does and when it runs, how to turn it on with
  OpenCloud Compose and other installations, the strategies explained
  with one example file throughout, how the age of a version is
  measured, how to try a strategy out, the background workers and the
  logs
- the command to clean up versions on demand, in the maintenance
  commands: a dry run first, selecting the files, choosing the
  strategy, the output, a nightly cron job with a timeout, the exit
  codes
- features and FAQ: versions are kept by default, administrators can
  have old ones deleted
@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch from 1103975 to 463d83b Compare October 23, 2026 06:22
@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch from 463d83b to 13b56eb Compare October 23, 2026 06:54
@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch 2 times, most recently from 5ba90c2 to 411b6b4 Compare October 25, 2026 01:13
pbleser-oc added a commit to pbleser-oc/docs that referenced this pull request Oct 25, 2026
OpenCloud can now delete old file versions according to a cleanup
strategy (opencloud-eu/opencloud#1419, opencloud-eu/opencloud#3778).

- a new page, Cleaning Up Old Versions, in the storage configuration:
  what the cleanup does and when it runs, how to turn it on with
  OpenCloud Compose and other installations, the strategies explained
  with one example file throughout, how the age of a version is
  measured, how to try a strategy out, the background workers and the
  logs
- the command to clean up versions on demand, in the maintenance
  commands: a dry run first, selecting the files, choosing the
  strategy, the output, a nightly cron job with a timeout, the exit
  codes, and what to know when it runs while OpenCloud is running
  (versions in an open Versions panel, NATS for PosixFS)
- features and FAQ: versions are kept by default, administrators can
  have old ones deleted
@maki5 maki5 removed the status in OpenCloud Team Board Oct 28, 2026
@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch from 411b6b4 to 0f568a5 Compare October 28, 2026 17:56
pbleser-oc added a commit to pbleser-oc/docs that referenced this pull request Nov 3, 2026
OpenCloud can now delete old file versions according to a cleanup
strategy (opencloud-eu/opencloud#1419, opencloud-eu/opencloud#3778).

- a new page, Cleaning Up Old Versions, in the storage configuration:
  what the cleanup does and when it runs, how to turn it on with
  OpenCloud Compose and other installations, the strategies explained
  with one example file throughout, how the age of a version is
  measured, how to try a strategy out, the background workers and the
  logs
- the command to clean up versions on demand, in the maintenance
  commands: a dry run first, selecting the files, choosing the
  strategy, the output, a nightly cron job with a timeout, the exit
  codes, and what to know when it runs while OpenCloud is running
  (versions in an open Versions panel, NATS for PosixFS)
- features and FAQ: versions are kept by default, administrators can
  have old ones deleted
@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch from 0f568a5 to 9577974 Compare November 3, 2026 10:57
@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch from 9577974 to b61e8b1 Compare November 17, 2026 01:36
pbleser-oc added a commit to pbleser-oc/docs that referenced this pull request Nov 17, 2026
OpenCloud can now delete old file versions according to a cleanup
strategy (opencloud-eu/opencloud#1419, opencloud-eu/opencloud#3778).

- a new page, Cleaning Up Old Versions, in the storage configuration:
  what the cleanup does and when it runs, how to turn it on with
  OpenCloud Compose and other installations, the strategies explained
  with one example file throughout, how the age of a version is
  measured, how to try a strategy out, the background workers and the
  logs
- the command to clean up versions on demand, in the maintenance
  commands: a dry run first, selecting the files, choosing the
  strategy, the output, a nightly cron job with a timeout, the exit
  codes, and what to know when it runs while OpenCloud is running
  (versions in an open Versions panel, NATS for PosixFS)
- features and FAQ: versions are kept by default, administrators can
  have old ones deleted
@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch 2 times, most recently from e559fae to 677dd87 Compare November 17, 2026 15:12
pbleser-oc added a commit to pbleser-oc/docs that referenced this pull request Nov 17, 2026
OpenCloud can now delete old file versions according to a cleanup
strategy (opencloud-eu/opencloud#1419, opencloud-eu/opencloud#3778).

- a new page, Cleaning Up Old Versions, in the storage configuration:
  what the cleanup does and when it runs, how to turn it on with
  OpenCloud Compose and other installations, the strategies explained
  with one example file throughout, how the age of a version is
  measured, how to try a strategy out, the background workers and the
  logs
- the command to clean up versions on demand, in the maintenance
  commands: a dry run first, selecting the files, choosing the
  strategy, the output, a nightly cron job with a timeout, the exit
  codes, and what to know when it runs while OpenCloud is running
  (the user to run it as, versions in an open Versions panel, NATS for
  PosixFS)
- features and FAQ: versions are kept by default, administrators can
  have old ones deleted
@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch from 3f8e70f to 3cab2ad Compare November 18, 2026 20:51
@pbleser-oc

Copy link
Copy Markdown
Member Author

Rebased onto main, which uses reva /v3 now, and pointed the temporary replace at the current head of opencloud-eu/reva#895 (a37f627e2), which addresses its latest review.

Two changes to the command since the last version:

  • It refuses to run with a file metadata cache local to each process (memory, the default, or ocmem): the server wouldn't see the revisions it deletes and would keep listing them for a while. The error says how to share the cache (STORAGE_USERS_FILEMETADATA_CACHE_STORE=nats-js-kv), and --allow-local-cache runs it anyway. Until default the storage-users filemetadata cache to nats-js-kv #4064 changes the default, that's what admins see on a default setup.
  • A dry run keeps a cache of its own, in its memory, whatever is configured, so that it doesn't fill a shared cache with the metadata of every file it looks at.

The README also says now that a restore keeps the revision of the content it replaced, as long as the file has the restored content, regardless of the strategy.

The description is updated. Every commit builds from vendor/ and passes the storage-users tests, and the acceptance features pass locally on posix and decomposed. The PR stays a draft until opencloud-eu/reva#895 is merged.

@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch from 3cab2ad to d47f996 Compare November 18, 2026 21:31
@pbleser-oc

Copy link
Copy Markdown
Member Author

A correction to my note above: with a cache local to each process, the server doesn't keep listing the deleted versions. It lists the versions of a file from disk, so a new list is right. What it doesn't learn about is that they were deleted: a list of versions that is already open, e.g. in the Versions panel, keeps showing them, and downloading or restoring one of them fails. The command still refuses to run with such a cache, unless --allow-local-cache is given. The texts of the command, the README and the description are corrected.

pbleser-oc added a commit to pbleser-oc/docs that referenced this pull request Nov 18, 2026
OpenCloud can now delete old file versions according to a cleanup
strategy (opencloud-eu/opencloud#1419, opencloud-eu/opencloud#3778).

- a new page, Cleaning Up Old Versions, in the storage configuration:
  what the cleanup does and when it runs, how to turn it on with
  OpenCloud Compose and other installations, the strategies explained
  with one example file throughout, how the age of a version is
  measured, how to try a strategy out, the background workers and the
  logs
- the command to clean up versions on demand, in the maintenance
  commands: a dry run first, selecting the files, choosing the
  strategy, the output, a nightly cron job with a timeout, the exit
  codes, and what to know when it runs while OpenCloud is running
  (the user to run it as, versions in an open Versions panel, NATS for
  PosixFS)
- features and FAQ: versions are kept by default, administrators can
  have old ones deleted
@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch from 80091c1 to 65722e3 Compare November 19, 2026 10:09
@pbleser-oc
pbleser-oc marked this pull request as ready for review November 19, 2026 10:10
@pbleser-oc
pbleser-oc requested a review from aduffeck November 19, 2026 10:32

// RevisionsCleanup configures the deletion of old revisions, for the 'decomposed', 'decomposeds3' and 'posix' storage drivers
type RevisionsCleanup struct {
Strategy string `yaml:"strategy" env:"OC_REVISIONS_CLEANUP_STRATEGY" desc:"Which old revisions (versions) of a file to delete whenever the file gets a new revision. 'disabled' keeps all revisions. A strategy is a comma-separated list of up to three parts: a number of revisions, which counts from the newest one (e.g. '10'), a duration with one of the units 'w', 'd', 'h', 'm' or 's' (e.g. '30d'; with the uppercase units 'D' and 'W', days and weeks count from midnight, e.g. '1D'), and 'auto', which thins out revisions the older they get. 'X' deletes everything beyond X, e.g. '10', '30d', or '0' to delete all revisions. 'X, auto' keeps everything within X and thins out the older revisions, e.g. '14d, auto'. 'auto, X' deletes everything beyond X and thins out the rest, e.g. 'auto, 90d'. 'X1, X2' keeps everything within X1 and deletes everything beyond X2, e.g. '5, 30d'. 'X1, auto, X2' also thins out in between, e.g. '7d, auto, 90d'. The age of a revision is the time its content was written, i.e. the modification time the file had before it was changed, not the time of that change. Only files that get a new revision are cleaned up, including revisions created from changes on disk with posix. An invalid value makes the storage driver fail at startup." introductionVersion:"%%NEXT%%"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason for naming those variables OC_* instead of STORAGE_USERS_*? Until now we prefixed the names with the service they affect and only add OC_ variants if there are multiple services using them to configure all at once.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No good reason, I wasn't aware of that convention. Only storage-users reads them, so they are STORAGE_USERS_REVISIONS_CLEANUP_* now, in all commits, and in the admin docs of opencloud-eu/docs#1222 too.


// RevisionsCleanup configures the deletion of old revisions, for the 'decomposed', 'decomposeds3' and 'posix' storage drivers
type RevisionsCleanup struct {
Strategy string `yaml:"strategy" env:"OC_REVISIONS_CLEANUP_STRATEGY" desc:"Which old revisions (versions) of a file to delete whenever the file gets a new revision. 'disabled' keeps all revisions. A strategy is a comma-separated list of up to three parts: a number of revisions, which counts from the newest one (e.g. '10'), a duration with one of the units 'w', 'd', 'h', 'm' or 's' (e.g. '30d'; with the uppercase units 'D' and 'W', days and weeks count from midnight, e.g. '1D'), and 'auto', which thins out revisions the older they get. 'X' deletes everything beyond X, e.g. '10', '30d', or '0' to delete all revisions. 'X, auto' keeps everything within X and thins out the older revisions, e.g. '14d, auto'. 'auto, X' deletes everything beyond X and thins out the rest, e.g. 'auto, 90d'. 'X1, X2' keeps everything within X1 and deletes everything beyond X2, e.g. '5, 30d'. 'X1, auto, X2' also thins out in between, e.g. '7d, auto, 90d'. The age of a revision is the time its content was written, i.e. the modification time the file had before it was changed, not the time of that change. Only files that get a new revision are cleaned up, including revisions created from changes on disk with posix. An invalid value makes the storage driver fail at startup." introductionVersion:"%%NEXT%%"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The age of a revision is the time its content was written, i.e. the modification time the file had before it was changed, not the time of that change. <- this is no longer correct with the latest changes in the reva PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I missed that one when the cleanup switched to the creation time. It now says: "The age of a revision is the time it was created, i.e. when the file was changed and its previous content became the revision, not the modification time of that content, which the version list shows." The same outdated text in the description of reva's option is fixed in opencloud-eu/reva#1041 (merged).

Wire reva's revision cleanup options into the 'decomposed', 'decomposeds3'
and 'posix' drivers, in the storage provider and in the data provider.

The options are a single 'revisions_cleanup' section of the storage-users
configuration, next to 'filemetadata_cache' and 'id_cache', as only one
driver is used at a time. Its environment variables:

- STORAGE_USERS_REVISIONS_CLEANUP_STRATEGY: which old revisions to
  delete whenever a file gets a new revision, e.g. 'auto', '30d' or
  '7d, auto, 90d'
- STORAGE_USERS_REVISIONS_CLEANUP_ASYNC: run the cleanup in background
  workers
- STORAGE_USERS_REVISIONS_CLEANUP_ASYNC_WORKERS: number of background
  workers
- STORAGE_USERS_REVISIONS_CLEANUP_ASYNC_QUEUE_SIZE: number of files that
  can wait
- STORAGE_USERS_REVISIONS_CLEANUP_ASYNC_QUEUE_FULL: 'drop' or 'block'
- STORAGE_USERS_REVISIONS_CLEANUP_ASYNC_QUEUE_FULL_TIMEOUT: how long
  'block' waits for room at most, 0 for as long as it takes

The strategy defaults to 'disabled', which keeps all revisions as before.
The other defaults are reva's: background workers, with the number of
workers and the queue size determined automatically, dropping the
cleanup of a file when the queue is full (it is cleaned up with its
next revision), and a timeout of 5s for 'block'.

Other commands that create a driver, 'posixfs scan' and 'uploads
sessions', clean up revisions without background workers: they could
exit before the workers are done, and stop the cleanup of a file
midway.

Assisted-by: Claude Code:claude-opus-5-5
'opencloud storage-users revisions cleanup' deletes old revisions,
according to a cleanup strategy, of:

- the files of spaces (--space, repeatable),
- or of a file or folder within a space (--space with --path),
- or of all spaces (--all),
- or of a file or folder given by its path on disk (--fs-path, posix
  only).

The id of a file or folder is rejected as the id of a space, as the
command would otherwise clean up its whole space. So is an id without a
space id, e.g. 'storage$'.

The storage-users service only cleans up the revisions of a file when it
gets a new one. The command also covers the files that are not changed
anymore, and applies a different strategy once.

The strategy and the settings of the background workers default to the
configured ones (STORAGE_USERS_REVISIONS_CLEANUP_*), and can be
overridden with --strategy, --async, --workers and --queue-size. Only
--queue-full defaults to 'block' without a timeout, whatever is
configured: the command finds files faster than the workers clean them
up, so dropping the files that find the queue full, or giving up after
the timeout meant for uploads, would skip most of them.
--queue-full-timeout sets one for the run.

The command uses the storage driver directly, in its own process, like
'uploads sessions': posix neither scans nor watches the file system, and
no driver joins the postprocessing consumer group of the service.

For posix, the driver needs NATS for its event stream. The command waits
for it 10 seconds at most, instead of the 15 minutes the stream retries
for, and ctrl-c also stops that wait: with the single binary, NATS only
runs within the server (opencloud-eu#3805). The driver gets
the logger of the command: posix passes it on to the NATS connections
of its id cache, whose handlers would panic on a lost connection
without one. Ctrl-C also stops waiting for the driver, e.g. for the id
cache, which retries for up to 15 minutes as well.

Unless it is a dry run, which changes nothing on disk, the command
warns when the storage belongs to another user than the one it runs as,
e.g. root: the lock files it creates belong to that user, and the
server may not be able to lock these files anymore.

Output: a line for every file whose revisions were deleted, that failed
or that was skipped, with its path within its space, and a summary;
--verbose adds every file and every revision with the decision and its
reason; --json prints the same as JSON objects, one per line, with a
final summary object. --dry-run deletes nothing.

--timeout stops the cleanup gracefully, as does ctrl-c, and a second
ctrl-c ends the command right away, which can leave the blob of a
deleted revision behind; the help says so. Whether the timeout or ctrl-c
stopped the cleanup is told by the contexts of the command, not by the
error: the storage can return context errors of its own. --shuffle walks
the spaces and folders in a random order, so that repeated runs that
are stopped by the timeout, e.g. from a cron job, eventually reach all
files. The help explains that a file waiting for a lock can't be
interrupted, and that a dry run changes nothing on disk, but decides on
a snapshot, as it doesn't keep the files locked while it decides.

The common flags have short forms: -a (--all), -p (--fs-path),
-s (--strategy), -n (--dry-run), -v (--verbose), -j (--json) and
-t (--timeout).

Exit codes:

- 0 when done,
- 1 if the cleanup or any file failed, or if it was interrupted,
- 2 if the timeout stopped the cleanup before all files were cleaned
  up.

The storage-users README documents the command, along with the cleanup
strategies and how they relate to the configured cleanup.

Assisted-by: Claude Code:claude-opus-5-5
A new cliCommands feature, cleanupFileVersions.feature, tests the
"storage-users revisions cleanup" command against a running server,
checking the remaining versions through the WebDAV versions API:

- keeping the newest version of every file in all spaces
- a dry run, which deletes nothing
- only a folder within the personal space (--space with --path)
- only a project space (--space)
- the JSON output (--json)
- no strategy while the configured one is disabled: exit code 1
- a timeout: exit code 2, nothing deleted
- a strategy without spaces after its commas ("auto,1"), as the CLI
  wrapper splits commands on spaces
- a folder by its path on disk (--fs-path), posix only
- the configured strategy (STORAGE_USERS_REVISIONS_CLEANUP_STRATEGY),
  which cleans up a file whenever it gets a new version: without
  background workers, and with them, the default
- the configured strategy for uploads with TUS, as the web UI and the
  clients upload
- the age of a version, which is the time its content was written:
  uploads with an older modification time (X-OC-Mtime) make versions
  that "30d" deletes right away, while "1,30d" keeps the newest one
- restoring a version with the strategy "0": the content from before
  the restore is kept, so that the restore can be undone

A second feature, collaborativePosix/cleanupFileVersions.feature, tests
the versions that changes on the POSIX filesystem create, with
STORAGE_USERS_POSIX_ENABLE_FS_REVISIONS: the configured strategy cleans
up a file whenever a change on disk creates a version, with and without
background workers, and the command deletes such versions. The
collaborativePosix suite doesn't run in the CI for now
(opencloud-eu#2036), so these
scenarios are ready for when it does again; they pass locally. The
suite gets the FilesVersionsContext, whose steps its existing version
scenarios already use.

New steps: in CliContext, running the command for all spaces, a space,
a path within a space, a path on the POSIX filesystem, or with flags
only; checking the exact exit code; and checking the objects of a JSON
output, which "the command output should contain" can't match as it
contains quotes. In FilesVersionsContext, a number of versions that is
checked until it matches, for the cleanup that runs in the background
after postprocessing. In WebDav, the Given form of an upload with
content and a modification time.

Assisted-by: Claude Code:claude-opus-5-5
…ocal to each process

The revisions cleanup command runs in a process of its own. With a file
metadata cache that each process keeps in its own memory ('memory', the
default, or 'ocmem'), the server doesn't learn about the revisions the
command deletes: a list of versions that is already open, e.g. in the
Versions panel, keeps showing them, and downloading or restoring one of
them fails. A new list is right, as the server lists them from disk.

The command now refuses to run with such a cache. The error says how to
share the cache (STORAGE_USERS_FILEMETADATA_CACHE_STORE=nats-js-kv, not
OC_CACHE_STORE, which sets the cache store of all services) and that
--allow-local-cache runs it anyway. A dry run deletes nothing and runs
with any cache.

The acceptance tests pass --allow-local-cache: their server runs with the
default cache, and they check the versions through the API, which lists
them from disk.

Assisted-by: Claude Code:claude-opus-5-5
The revision cleanup doesn't apply the strategy to the revision a
restore created of the content it replaced, not even an age limit,
as long as the file has the restored content. Say so next to the
strategies, as it is an exception admins wouldn't expect.

Assisted-by: Claude Code:claude-opus-5-5
…s own

A dry run reads the metadata of every file it looks at. With a file
metadata cache shared with the server, e.g. 'nats-js-kv', it filled
that cache with entries for all of them, for a run that changes
nothing.

A dry run now always keeps its file metadata cache in its own memory,
whatever is configured. It doesn't need the shared cache: it deletes
nothing the server would have to see, and a cache of its own starts
empty, so it reads the metadata from disk. A real run still uses the
configured cache, which must be shared.

Assisted-by: Claude Code:claude-opus-5-5
…does

The revisions cleanup command, its help and the README said that, with
a cache local to each process, the server would keep listing the
revisions the command deleted until their cache entries expire or it
restarts. It doesn't: the server lists the revisions of a file from
disk. What it doesn't learn about is that they were deleted, so a list
of versions that is already open, e.g. in the Versions panel, keeps
showing them, and downloading or restoring one of them fails.

The command still refuses to run with such a cache, unless
--allow-local-cache is given: a shared cache is the right setup for a
command that changes the storage next to the server.

Assisted-by: Claude Code:claude-opus-5-5
Follows opencloud-eu/reva#895, which makes the revision cleanup go by
the time a revision was created, recorded by the server, instead of the
modification time of its content, which clients choose with X-OC-Mtime.
"auto" keeps the oldest revision of each slot (opencloud-eu#3735).

- The storage-users README explains the new age of a revision.
- The acceptance scenario outline that checked the age as the time the
  content was written is replaced by two scenarios: versions whose
  content is dated 60 and 50 days ago are kept by "30d", and a version
  with content dated 10 years ahead doesn't push out the newest one
  under "1".

Assisted-by: Claude Code:claude-opus-5-5
@pbleser-oc
pbleser-oc force-pushed the feat/1419-clean-up-file-versions branch from 31eb2fb to 5e8a88a Compare November 23, 2026 23:12
pbleser-oc added a commit to pbleser-oc/docs that referenced this pull request Nov 23, 2026
OpenCloud can now delete old file versions according to a cleanup
strategy (opencloud-eu/opencloud#1419, opencloud-eu/opencloud#3778).

- a new page, Cleaning Up Old Versions, in the storage configuration:
  what the cleanup does and when it runs, how to turn it on with
  OpenCloud Compose and other installations, the strategies explained
  with one example file throughout, how the age of a version is
  measured, how to try a strategy out, the background workers and the
  logs
- the command to clean up versions on demand, in the maintenance
  commands: a dry run first, selecting the files, choosing the
  strategy, the output, a nightly cron job with a timeout, the exit
  codes, and what to know when it runs while OpenCloud is running
  (the user to run it as, versions in an open Versions panel, NATS for
  PosixFS)
- features and FAQ: versions are kept by default, administrators can
  have old ones deleted
@pbleser-oc
pbleser-oc merged commit 0b73e9e into opencloud-eu:main Nov 24, 2026
61 checks passed
@pbleser-oc
pbleser-oc deleted the feat/1419-clean-up-file-versions branch November 24, 2026 11:17
pbleser-oc added a commit to pbleser-oc/docs that referenced this pull request Nov 24, 2026
OpenCloud can now delete old file versions according to a cleanup
strategy (opencloud-eu/opencloud#1419, opencloud-eu/opencloud#3778).

- a new page, Cleaning Up Old Versions, in the storage configuration:
  what the cleanup does and when it runs, how to turn it on with
  OpenCloud Compose and other installations, the strategies explained
  with one example file throughout, how the age of a version is
  measured, how to try a strategy out, the background workers and the
  logs
- the command to clean up versions on demand, in the maintenance
  commands: a dry run first, selecting the files, choosing the
  strategy, the output, a nightly cron job with a timeout, the exit
  codes, and what to know when it runs while OpenCloud is running
  (the user to run it as, versions in an open Versions panel, NATS for
  PosixFS)
- features and FAQ: versions are kept by default, administrators can
  have old ones deleted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revision cleanup: should the age of a revision be the age of its content, or the time it was replaced? 🧹 Clean-Up File Versions

2 participants