diff --git a/lxd/api_internal_recover.go b/lxd/api_internal_recover.go index bcd57697fa78..173f1b004bda 100644 --- a/lxd/api_internal_recover.go +++ b/lxd/api_internal_recover.go @@ -574,12 +574,23 @@ func internalRecoverImportInstanceSnapshot(s *state.State, pool storagePools.Poo return nil, err } + snapshotExpiry := snap.Config["snapshots.expiry"] + if snapshotExpiry != "" { + expiry, err := shared.GetExpiry(snap.CreatedAt, snapshotExpiry) + if err != nil { + return nil, err + } + + snap.ExpiresAt = expiry + } + _, snapInstOp, cleanup, err := instance.CreateInternal(s, db.InstanceArgs{ Project: projectName, Architecture: arch, BaseImage: snap.Config["volatile.base_image"], Config: snap.Config, CreationDate: snap.CreatedAt, + ExpiryDate: snap.ExpiresAt, Type: instanceType, Snapshot: true, Devices: deviceConfig.NewDevices(snap.Devices), diff --git a/test/suites/backup.sh b/test/suites/backup.sh index 88d1fd314706..316dcfe4b71d 100644 --- a/test/suites/backup.sh +++ b/test/suites/backup.sh @@ -103,8 +103,10 @@ EOF echo "hello world" | lxc exec c1 --project test -- tee /mnt/test.txt [ "$(lxc exec c1 --project test -- cat /mnt/test.txt)" = "hello world" ] lxc stop -f c1 + lxc config set c1 snapshots.expiry 1d lxc snapshot c1 lxc info c1 + snapshotExpiryDateBefore=$(lxc info c1 | grep -wF "snap0") lxc storage volume snapshot "${poolName}" vol1_test snap0 lxc storage volume show "${poolName}" vol1_test @@ -185,6 +187,10 @@ EOF lxc start c1 lxc exec c1 --project test -- hostname + # Check snapshot expiry date has been restored. + snapshotExpiryDateAfter=$(lxc info c1 | grep -wF "snap0") + [ "$snapshotExpiryDateBefore" = "$snapshotExpiryDateAfter" ] + # Check custom volume accessible. lxc exec c1 --project test -- mount | grep /mnt [ "$(lxc exec c1 --project test -- cat /mnt/test.txt)" = "hello world" ]