Skip to content

Commit d5ba373

Browse files
committed
cmd:incusd: Adding refresh-exclude-older flag
Signed-off-by: Parm Gill <[email protected]>
1 parent e6f2b91 commit d5ba373

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

cmd/incusd/instance.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ type instanceCreateAsCopyOpts struct {
290290
targetInstance db.InstanceArgs // Configuration for new instance.
291291
instanceOnly bool // Only copy the instance and not it's snapshots.
292292
refresh bool // Refresh an existing target instance.
293+
refreshExcludeOlder bool // During refresh, exclude source snapshots earlier than latest target snapshot
293294
applyTemplateTrigger bool // Apply deferred TemplateTriggerCopy.
294295
allowInconsistent bool // Ignore some copy errors
295296
}
@@ -372,7 +373,7 @@ func instanceCreateAsCopy(s *state.State, opts instanceCreateAsCopyOpts, op *ope
372373
})
373374
}
374375

375-
syncSourceSnapshotIndexes, deleteTargetSnapshotIndexes := storagePools.CompareSnapshots(sourceSnapshotComparable, targetSnapshotsComparable)
376+
syncSourceSnapshotIndexes, deleteTargetSnapshotIndexes := storagePools.CompareSnapshots(sourceSnapshotComparable, targetSnapshotsComparable, opts.refreshExcludeOlder)
376377

377378
// Delete extra snapshots first.
378379
for _, deleteTargetSnapIndex := range deleteTargetSnapshotIndexes {

cmd/incusd/instances_post.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ func createFromCopy(ctx context.Context, s *state.State, r *http.Request, projec
549549
targetInstance: args,
550550
instanceOnly: req.Source.InstanceOnly,
551551
refresh: req.Source.Refresh,
552+
refreshExcludeOlder: req.Source.RefreshExcludeOlder,
552553
applyTemplateTrigger: true,
553554
allowInconsistent: req.Source.AllowInconsistent,
554555
}, op)

cmd/incusd/migrate.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ type migrationSink struct {
185185
push bool
186186
clusterMoveSourceName string
187187
refresh bool
188+
refreshExcludeOlder bool
188189
}
189190

190191
// MigrationSinkArgs arguments to configure migration sink.
@@ -201,6 +202,7 @@ type migrationSinkArgs struct {
201202
Idmap *idmap.Set
202203
Live bool
203204
Refresh bool
205+
RefreshExcludeOlder bool
204206
ClusterMoveSourceName string
205207
Snapshots []*migration.Snapshot
206208

cmd/incusd/migrate_instance.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func newMigrationSink(args *migrationSinkArgs) (*migrationSink, error) {
169169
clusterMoveSourceName: args.ClusterMoveSourceName,
170170
push: args.Push,
171171
refresh: args.Refresh,
172+
refreshExcludeOlder: args.RefreshExcludeOlder,
172173
}
173174

174175
secretNames := []string{api.SecretNameControl, api.SecretNameFilesystem}
@@ -275,8 +276,9 @@ func (c *migrationSink) Do(state *state.State, instOp *operationlock.InstanceOpe
275276
},
276277
ClusterMoveSourceName: c.clusterMoveSourceName,
277278
},
278-
InstanceOperation: instOp,
279-
Refresh: c.refresh,
279+
InstanceOperation: instOp,
280+
Refresh: c.refresh,
281+
RefreshExcludeOlder: c.refreshExcludeOlder,
280282
})
281283
if err != nil {
282284
l.Error("Failed migration on target", logger.Ctx{"err": err})

cmd/incusd/migrate_storage_volumes.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,10 @@ func newStorageMigrationSink(args *migrationSinkArgs) (*migrationSink, error) {
208208
migrationFields: migrationFields{
209209
volumeOnly: args.VolumeOnly,
210210
},
211-
url: args.URL,
212-
push: args.Push,
213-
refresh: args.Refresh,
211+
url: args.URL,
212+
push: args.Push,
213+
refresh: args.Refresh,
214+
refreshExcludeOlder: args.RefreshExcludeOlder,
214215
}
215216

216217
secretNames := []string{api.SecretNameControl, api.SecretNameFilesystem}
@@ -329,6 +330,7 @@ func (c *migrationSink) DoStorage(state *state.State, projectName string, poolNa
329330
TrackProgress: true,
330331
ContentType: req.ContentType,
331332
Refresh: args.Refresh,
333+
RefreshExcludeOlder: args.RefreshExcludeOlder,
332334
VolumeOnly: args.VolumeOnly,
333335
}
334336

@@ -373,7 +375,7 @@ func (c *migrationSink) DoStorage(state *state.State, projectName string, poolNa
373375
}
374376

375377
// Compare the two sets.
376-
syncSourceSnapshotIndexes, deleteTargetSnapshotIndexes := storagePools.CompareSnapshots(sourceSnapshotComparable, targetSnapshotsComparable)
378+
syncSourceSnapshotIndexes, deleteTargetSnapshotIndexes := storagePools.CompareSnapshots(sourceSnapshotComparable, targetSnapshotsComparable, c.refreshExcludeOlder)
377379

378380
// Delete the extra local snapshots first.
379381
for _, deleteTargetSnapshotIndex := range deleteTargetSnapshotIndexes {

cmd/incusd/storage_volumes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ func doCustomVolumeRefresh(s *state.State, r *http.Request, requestProjectName s
829829
return fmt.Errorf("No source volume name supplied")
830830
}
831831

832-
err = pool.RefreshCustomVolume(projectName, srcProjectName, req.Name, req.Description, req.Config, req.Source.Pool, req.Source.Name, !req.Source.VolumeOnly, op)
832+
err = pool.RefreshCustomVolume(projectName, srcProjectName, req.Name, req.Description, req.Config, req.Source.Pool, req.Source.Name, !req.Source.VolumeOnly, req.Source.RefreshExcludeOlder, op)
833833
if err != nil {
834834
return err
835835
}

0 commit comments

Comments
 (0)