Skip to content

Commit

Permalink
lxd/recover: Add snapshot expiry when recovering instance snapshots (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomponline authored Aug 28, 2024
2 parents f882620 + 9d49b92 commit 6f7856c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lxd/api_internal_recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions test/suites/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" ]
Expand Down

0 comments on commit 6f7856c

Please sign in to comment.