Skip to content

Commit 835a8fd

Browse files
chore(jobs): improve snapshot for instances (#119)
* chore(jobs): improve snapshot for instances * Update jobs/instances-snapshot/main.go Co-authored-by: Ramy <ramychaab@gmail.com> --------- Co-authored-by: Ramy <ramychaab@gmail.com>
1 parent 2b000fd commit 835a8fd

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

jobs/instances-snapshot/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log/slog"
77
"os"
8+
"time"
89

910
"github.com/scaleway/scaleway-sdk-go/api/block/v1"
1011
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
@@ -81,11 +82,22 @@ func createSnapshots(ctx context.Context, instanceAPI *instance.API, blockAPI *b
8182
}
8283

8384
for _, volume := range gotInstance.Server.Volumes {
85+
slog.Info("getting volume informations", "volume_id", volume.ID)
86+
87+
volumeHydrated, err := blockAPI.GetVolume(&block.GetVolumeRequest{
88+
VolumeID: volume.ID,
89+
Zone: zone,
90+
})
91+
if err != nil {
92+
return fmt.Errorf("erro while reading volume informations: %w", err)
93+
}
94+
8495
slog.Info("creating snapshot for volume", "volume_id", volume.ID)
8596
snapshotResp, err := blockAPI.CreateSnapshot(&block.CreateSnapshotRequest{
8697
Zone: zone,
8798
VolumeID: volume.ID,
8899
ProjectID: os.Getenv(envProjectID),
100+
Name: fmt.Sprintf("snapshot-%s-%s", volumeHydrated.Name, time.Now().UTC().Format(time.RFC3339)),
89101
}, scw.WithContext(ctx))
90102
if err != nil {
91103
return fmt.Errorf("error while creating snapshot: %w", err)

0 commit comments

Comments
 (0)