fix: 4200: say which time zone the revision cleanup uses

Midnight for "D" and "W" and the days, weeks and hours of "auto" are in
the local time zone of the server, set with TZ or by the system, and UTC
without either (opencloud-eu/reva#1097 moves the slots of "auto" from UTC
to the local time zone). The description of the strategy, the README of
the service and the help of the cleanup command now say so, how to get
UTC, and that the command must run with the same time zone as the server,
otherwise it decides differently.

https://github.com/opencloud-eu/opencloud/issues/4200

Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
Pascal Bleser committed 2026-12-04 10:59:15 +01:00
1 parent 4154dcd71f
commit 85031fab71
3 files changed
+12 -3

No files matched your search

+3 -1
View File
@@ -363,7 +363,7 @@ Each `X` is either
* a number, which is a number of revisions, always counting from the newest one,
* or a duration with one of the units `w` (weeks), `d` (days), `h` (hours), `m` (minutes) or `s` (seconds).
Durations in days or weeks can use an uppercase unit, `D` or `W`, to count from midnight (server time) instead of from now: `1d` means the last 24 hours, `1D` since yesterday 00:00.
Durations in days or weeks can use an uppercase unit, `D` or `W`, to count from midnight instead of from now: `1d` means the last 24 hours, `1D` since yesterday 00:00, in the local time zone of the server (see below).
| Strategy | Meaning | Examples |
|---|---|---|
@@ -379,6 +379,8 @@ A restore keeps the revision of the content it replaced as long as the file has
Note that 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, by the clock of the server. The revisions are also ordered by it, e.g. for a number of revisions to keep. It is not the modification time of the content of the revision, which is the date the version list shows for it, as clients can set that to any time. A document that was unchanged for two months gets a revision that is a few seconds old when it is changed, and e.g. `30d` keeps that revision for 30 days. `auto` keeps the oldest revision of each time slot, which holds the content the file had when the slot began. Revisions created before OpenCloud recorded the time of their creation get an estimate: the time they were replaced, as far as it can be told from the dates of the newer revisions and of the file.
All times of the cleanup are in the local time zone of the server: midnight for `D` and `W`, and the time slots of `auto`, whose days start at midnight, whose weeks start on Monday at midnight, and whose hours start at the full hour, also when daylight saving time begins or ends. That time zone is the one set with the `TZ` environment variable, or else the time zone of the system (`/etc/localtime`), or else UTC: container images often have no time zone configured, and then use UTC. To use UTC on a system with another time zone, set `TZ=UTC`. The `revisions cleanup` command uses its own local time zone in the same way, also for the times it prints: run it with the same time zone as the server, otherwise it puts revisions into other time slots than the server and decides differently.
#### Selecting the Files
Exactly one of these selects the files to clean up:
@@ -80,6 +80,12 @@ description of STORAGE_USERS_REVISIONS_CLEANUP_STRATEGY for the strategies, e.g.
whatever is configured: the command finds files faster than the workers clean them up,
so dropping the files that find the queue full would skip most of them.
The times of the strategy (midnight for 'D' and 'W', the days, weeks and hours of
'auto') and the times the command prints are in its local time zone: the one set with
the TZ environment variable, or else the time zone of the system, or else UTC. Run it
with the same time zone as the server, otherwise it decides differently than the server
would, e.g. with 'TZ=UTC' if the server runs in UTC.
The command uses the storage directly, with the configuration of the storage-users
service, and can run while the service is running. It needs access to the storage and,
for the 'posix' driver, to NATS. With the single binary, NATS runs within the server:
@@ -685,7 +691,8 @@ func (out *revisionsCleanupOutput) printText(r revisioncleanup.Result, deleted i
return
}
for _, rev := range r.Revisions {
// in the server's time zone, like the times in the reasons
// in the local time zone of the command, like the times in the reasons, which should
// be the server's (see the help)
fmt.Fprintf(out.w, " %-9s %s %9s %s\n", rev.Decision, rev.Time.Local().Format(time.RFC3339), formatBytes(rev.Size), rev.Reason)
if rev.Err != nil {
fmt.Fprintf(out.w, " %-9s could not be deleted: %s\n", "", rev.Err)
+1 -1
View File
@@ -236,7 +236,7 @@ type Events struct {
// RevisionsCleanup configures the deletion of old revisions, for the 'decomposed', 'decomposeds3' and 'posix' storage drivers
type RevisionsCleanup struct {
Strategy string `yaml:"strategy" env:"STORAGE_USERS_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 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. 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%%"`
Strategy string `yaml:"strategy" env:"STORAGE_USERS_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 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. Midnight for 'D' and 'W' and the days, weeks and hours of 'auto' are those of the local time zone of the server: the time zone set with the TZ environment variable, or else the one of the system, or else UTC. Set TZ=UTC to use UTC. 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%%"`
Async bool `yaml:"async" env:"STORAGE_USERS_REVISIONS_CLEANUP_ASYNC" desc:"Run the revision cleanup in background workers, so that it does not slow down the upload, restore or change that created the new revision. When set to false, the cleanup runs right away." introductionVersion:"%%NEXT%%"`
AsyncWorkers int `yaml:"async_workers" env:"STORAGE_USERS_REVISIONS_CLEANUP_ASYNC_WORKERS" desc:"Number of background workers for the revision cleanup. A value of 0 determines it automatically: half the available CPUs, respecting container CPU limits, but at least 2." introductionVersion:"%%NEXT%%"`
AsyncQueueSize int `yaml:"async_queue_size" env:"STORAGE_USERS_REVISIONS_CLEANUP_ASYNC_QUEUE_SIZE" desc:"Number of files that can wait for a background revision cleanup. A value of 0 determines it automatically: 64 per worker." introductionVersion:"%%NEXT%%"`