Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes an issue when copying a custom volume using the --refresh flag #1437

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/incusd/migrate_storage_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (c *migrationSink) DoStorage(state *state.State, projectName string, poolNa
for _, sourceSnap := range sourceSnapshots {
sourceSnapshotComparable = append(sourceSnapshotComparable, storagePools.ComparableSnapshot{
Name: sourceSnap.GetName(),
CreationDate: time.Unix(sourceSnap.GetCreationDate(), 0),
CreationDate: time.Unix(0, sourceSnap.GetCreationDate()),
})
}

Expand Down Expand Up @@ -501,7 +501,7 @@ func volumeSnapshotToProtobuf(vol *api.StorageVolumeSnapshot) *migration.Snapsho
LocalDevices: []*migration.Device{},
Architecture: proto.Int32(0),
Stateful: proto.Bool(false),
CreationDate: proto.Int64(0),
CreationDate: proto.Int64(vol.CreatedAt.UnixNano()),
LastUsedDate: proto.Int64(0),
ExpiryDate: proto.Int64(0),
}
Expand Down
1 change: 1 addition & 0 deletions internal/server/storage/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6211,6 +6211,7 @@ func (b *backend) GenerateCustomVolumeBackupConfig(projectName string, volName s
Name: snapName, // Snapshot only name, not full name.
Config: dbVolSnaps[i].Config,
ContentType: dbVolSnaps[i].ContentType,
CreatedAt: dbVolSnaps[i].CreationDate,
}

config.VolumeSnapshots = append(config.VolumeSnapshots, &snapshot)
Expand Down
29 changes: 10 additions & 19 deletions test/suites/storage_local_volume_handling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,40 +219,32 @@ test_storage_local_volume_handling() {
incus storage volume snapshot create "${source_pool}" vol5
incus storage volume set "${source_pool}" vol5 user.foo=snap1vol5
incus storage volume snapshot create "${source_pool}" vol5
incus storage volume set "${source_pool}" vol5 user.foo=snapremovevol5
incus storage volume snapshot create "${source_pool}" vol5 snapremove
incus storage volume set "${source_pool}" vol5 user.foo=postsnap1vol5

# create storage volume with user config differing over snapshots and additional snapshot than vol5
incus storage volume create "${source_pool}" vol6 --type=block size=4194304
incus storage volume set "${source_pool}" vol6 user.foo=snap0vol6
incus storage volume snapshot create "${source_pool}" vol6
incus storage volume set "${source_pool}" vol6 user.foo=snap1vol6
incus storage volume snapshot create "${source_pool}" vol6
incus storage volume set "${source_pool}" vol6 user.foo=snap2vol6
incus storage volume snapshot create "${source_pool}" vol6
incus storage volume set "${source_pool}" vol6 user.foo=postsnap1vol6

# copy to new volume destination with refresh flag
incus storage volume copy --refresh "${source_pool}/vol5" "${target_pool}/vol5"

# check snapshot volumes (including config) were copied
incus storage volume get "${target_pool}" vol5 user.foo | grep -Fx "postsnap1vol5"
incus storage volume get "${target_pool}" vol5/snap0 user.foo | grep -Fx "snap0vol5"
incus storage volume get "${target_pool}" vol5/snap1 user.foo | grep -Fx "snap1vol5"
incus storage volume get "${target_pool}" vol5/snapremove user.foo | grep -Fx "snapremovevol5"

# create additional snapshot on source_pool and one on target_pool
incus storage volume snapshot create "${source_pool}" vol5 postsnap1vol5
incus storage volume set "${target_pool}" vol5 user.foo=snapremovevol5
incus storage volume snapshot create "${target_pool}" vol5 snapremove

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

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

# copy ISO custom volumes
Expand All @@ -272,7 +264,6 @@ test_storage_local_volume_handling() {
incus storage volume delete "${target_pool}" vol4
incus storage volume delete "${source_pool}" vol5
incus storage volume delete "${target_pool}" vol5
incus storage volume delete "${source_pool}" vol6
incus storage volume delete "${target_pool}" iso1
incus storage volume delete "${target_pool}" iso2
rm -f foo.iso
Expand Down