@@ -143,73 +143,12 @@ func (t *ScheduledForgetTask) Next(now time.Time, runner TaskRunner) (ScheduledT
143143 }, nil
144144}
145145
146- // shouldSkip returns true if there are no new successful backups since the last scheduled forget.
147- func (t * ScheduledForgetTask ) shouldSkip (runner TaskRunner , repoProto * v1.Repo ) bool {
148- var lastForgetEndMs int64
149- var hasNewBackup bool
150-
151- _ = runner .QueryOperations (oplog.Query {}.
152- SetInstanceID (runner .InstanceID ()).
153- SetRepoGUID (repoProto .GetGuid ()).
154- SetPlanID (PlanForSystemTasks ).
155- SetReversed (true ), func (op * v1.Operation ) error {
156- if op .Status != v1 .OperationStatus_STATUS_SUCCESS {
157- return nil
158- }
159- if _ , ok := op .Op .(* v1.Operation_OperationForget ); ok && op .UnixTimeEndMs != 0 {
160- lastForgetEndMs = op .UnixTimeEndMs
161- return oplog .ErrStopIteration
162- }
163- return nil
164- })
165-
166- if lastForgetEndMs == 0 {
167- return false // no previous forget, don't skip
168- }
169-
170- // Check if any backup completed after the last forget.
171- // Intentionally not scoped by instance ID: in a sync setup the server receives
172- // backup operations from remote clients. We want forget to run whenever new
173- // snapshots appear in the repo regardless of which instance created them.
174- _ = runner .QueryOperations (oplog.Query {}.
175- SetRepoGUID (repoProto .GetGuid ()).
176- SetReversed (true ), func (op * v1.Operation ) error {
177- if op .UnixTimeEndMs < lastForgetEndMs {
178- return oplog .ErrStopIteration // older than last forget, stop looking
179- }
180- if op .Status == v1 .OperationStatus_STATUS_SUCCESS {
181- if _ , ok := op .Op .(* v1.Operation_OperationBackup ); ok {
182- hasNewBackup = true
183- return oplog .ErrStopIteration
184- }
185- }
186- return nil
187- })
188-
189- return ! hasNewBackup
190- }
191-
192146func (t * ScheduledForgetTask ) Run (ctx context.Context , st ScheduledTask , runner TaskRunner ) error {
193- op := st .Op
194-
195147 repoProto , err := runner .GetRepo (t .RepoID ())
196148 if err != nil {
197149 return NotifyError (ctx , runner , t .Name (), fmt .Errorf ("get repo %q: %w" , t .RepoID (), err ), v1 .Hook_CONDITION_FORGET_ERROR )
198150 }
199151
200- // Skip if no new backups since last forget run.
201- // Mark as system-cancelled so it doesn't count as a successful run
202- // and the next schedule is computed from the last actual forget.
203- // Interactive (force) runs always execute.
204- if ! t .force && t .shouldSkip (runner , repoProto ) {
205- op .Op = & v1.Operation_OperationForget {
206- OperationForget : & v1.OperationForget {},
207- }
208- op .Status = v1 .OperationStatus_STATUS_SYSTEM_CANCELLED
209- op .DisplayMessage = "Skipped: no new backups since last forget"
210- return nil
211- }
212-
213152 err = forgetHelper (ctx , st , runner , repoProto .GetForgetPolicy ().GetRetention (),
214153 restic .WithFlags ("--group-by" , "tags" ),
215154 )
0 commit comments