Skip to content

Commit 50aba9a

Browse files
authored
Merge pull request #1437 from presztak/volume_copy_with_refresh
Fixes an issue when copying a custom volume using the `--refresh` flag
2 parents 9c98257 + 301a297 commit 50aba9a

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

cmd/incusd/migrate_storage_volumes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func (c *migrationSink) DoStorage(state *state.State, projectName string, poolNa
353353
for _, sourceSnap := range sourceSnapshots {
354354
sourceSnapshotComparable = append(sourceSnapshotComparable, storagePools.ComparableSnapshot{
355355
Name: sourceSnap.GetName(),
356-
CreationDate: time.Unix(sourceSnap.GetCreationDate(), 0),
356+
CreationDate: time.Unix(0, sourceSnap.GetCreationDate()),
357357
})
358358
}
359359

@@ -501,7 +501,7 @@ func volumeSnapshotToProtobuf(vol *api.StorageVolumeSnapshot) *migration.Snapsho
501501
LocalDevices: []*migration.Device{},
502502
Architecture: proto.Int32(0),
503503
Stateful: proto.Bool(false),
504-
CreationDate: proto.Int64(0),
504+
CreationDate: proto.Int64(vol.CreatedAt.UnixNano()),
505505
LastUsedDate: proto.Int64(0),
506506
ExpiryDate: proto.Int64(0),
507507
}

internal/server/storage/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6211,6 +6211,7 @@ func (b *backend) GenerateCustomVolumeBackupConfig(projectName string, volName s
62116211
Name: snapName, // Snapshot only name, not full name.
62126212
Config: dbVolSnaps[i].Config,
62136213
ContentType: dbVolSnaps[i].ContentType,
6214+
CreatedAt: dbVolSnaps[i].CreationDate,
62146215
}
62156216

62166217
config.VolumeSnapshots = append(config.VolumeSnapshots, &snapshot)

test/suites/storage_local_volume_handling.sh

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -219,40 +219,32 @@ test_storage_local_volume_handling() {
219219
incus storage volume snapshot create "${source_pool}" vol5
220220
incus storage volume set "${source_pool}" vol5 user.foo=snap1vol5
221221
incus storage volume snapshot create "${source_pool}" vol5
222-
incus storage volume set "${source_pool}" vol5 user.foo=snapremovevol5
223-
incus storage volume snapshot create "${source_pool}" vol5 snapremove
224222
incus storage volume set "${source_pool}" vol5 user.foo=postsnap1vol5
225223

226-
# create storage volume with user config differing over snapshots and additional snapshot than vol5
227-
incus storage volume create "${source_pool}" vol6 --type=block size=4194304
228-
incus storage volume set "${source_pool}" vol6 user.foo=snap0vol6
229-
incus storage volume snapshot create "${source_pool}" vol6
230-
incus storage volume set "${source_pool}" vol6 user.foo=snap1vol6
231-
incus storage volume snapshot create "${source_pool}" vol6
232-
incus storage volume set "${source_pool}" vol6 user.foo=snap2vol6
233-
incus storage volume snapshot create "${source_pool}" vol6
234-
incus storage volume set "${source_pool}" vol6 user.foo=postsnap1vol6
235-
236224
# copy to new volume destination with refresh flag
237225
incus storage volume copy --refresh "${source_pool}/vol5" "${target_pool}/vol5"
238226

239227
# check snapshot volumes (including config) were copied
240228
incus storage volume get "${target_pool}" vol5 user.foo | grep -Fx "postsnap1vol5"
241229
incus storage volume get "${target_pool}" vol5/snap0 user.foo | grep -Fx "snap0vol5"
242230
incus storage volume get "${target_pool}" vol5/snap1 user.foo | grep -Fx "snap1vol5"
243-
incus storage volume get "${target_pool}" vol5/snapremove user.foo | grep -Fx "snapremovevol5"
231+
232+
# create additional snapshot on source_pool and one on target_pool
233+
incus storage volume snapshot create "${source_pool}" vol5 postsnap1vol5
234+
incus storage volume set "${target_pool}" vol5 user.foo=snapremovevol5
235+
incus storage volume snapshot create "${target_pool}" vol5 snapremove
244236

245237
# incremental copy to existing volume destination with refresh flag
246-
incus storage volume copy --refresh "${source_pool}/vol6" "${target_pool}/vol5"
238+
incus storage volume copy --refresh "${source_pool}/vol5" "${target_pool}/vol5"
247239

248240
# check snapshot volumes (including config) was overridden from new source and that missing snapshot is
249241
# present and that the missing snapshot has been removed.
250-
# Note: Due to a known issue we are currently only diffing the snapshots by name, so infact existing
251-
# snapshots of the same name won't be overwritten even if their config or contents is different.
252-
incus storage volume get "${target_pool}" vol5 user.foo | grep -Fx "postsnap1vol5"
242+
# Note: We are currently diffing the snapshots by name and creation date, so infact existing
243+
# snapshots of the same name and cretion date won't be overwritten even if their config or contents is different.
244+
incus storage volume get "${target_pool}" vol5 user.foo | grep -Fx "snapremovevol5"
253245
incus storage volume get "${target_pool}" vol5/snap0 user.foo | grep -Fx "snap0vol5"
254246
incus storage volume get "${target_pool}" vol5/snap1 user.foo | grep -Fx "snap1vol5"
255-
incus storage volume get "${target_pool}" vol5/snap2 user.foo | grep -Fx "snap2vol6"
247+
incus storage volume get "${target_pool}" vol5/postsnap1vol5 user.foo | grep -Fx "postsnap1vol5"
256248
! incus storage volume get "${target_pool}" vol5/snapremove user.foo || false
257249

258250
# copy ISO custom volumes
@@ -272,7 +264,6 @@ test_storage_local_volume_handling() {
272264
incus storage volume delete "${target_pool}" vol4
273265
incus storage volume delete "${source_pool}" vol5
274266
incus storage volume delete "${target_pool}" vol5
275-
incus storage volume delete "${source_pool}" vol6
276267
incus storage volume delete "${target_pool}" iso1
277268
incus storage volume delete "${target_pool}" iso2
278269
rm -f foo.iso

0 commit comments

Comments
 (0)