@@ -12,9 +12,11 @@ import (
1212 "github.com/stackitcloud/stackit-cli/internal/pkg/print"
1313 "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client"
1414 mongodbUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils"
15+ "github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
1516
1617 "github.com/spf13/cobra"
1718 "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex"
19+ "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/wait"
1820)
1921
2022const (
@@ -47,11 +49,11 @@ func NewCmd(p *print.Printer) *cobra.Command {
4749 `Restores a MongoDB Flex instance with id "yyy" using backup with id "zzz"` ,
4850 `$ stackit mongodbflex backup restore --instance-id yyy --backup-id zzz` ),
4951 examples .NewExample (
50- `Restores a MongoDB Flex instance with id "yyy" using backup with timestamp "zzz"` ,
52+ `Clone a MongoDB Flex instance with id "yyy" via point-in-time restore to timestamp "zzz"` ,
5153 `$ stackit mongodbflex backup restore --instance-id yyy --timestamp zzz` ),
5254 examples .NewExample (
5355 `Restores a MongoDB Flex instance with id "yyy" using backup from instance with id "zzz" with backup id "aaa"` ,
54- `$ stackit mongodbflex backup restore --instance-id yyy --backup-instance-id zzz --backup-id aaa` ),
56+ `$ stackit mongodbflex backup restore --instance-id zzz --backup-instance-id yyy --backup-id aaa` ),
5557 ),
5658 RunE : func (cmd * cobra.Command , args []string ) error {
5759 ctx := context .Background ()
@@ -96,16 +98,37 @@ func NewCmd(p *print.Printer) *cobra.Command {
9698 return fmt .Errorf ("restore MongoDB Flex instance: %w" , err )
9799 }
98100
101+ if ! model .Async {
102+ s := spinner .New (p )
103+ s .Start ("Restoring instance" )
104+ _ , err = wait .RestoreInstanceWaitHandler (ctx , apiClient , model .ProjectId , model .InstanceId , model .BackupId ).WaitWithContext (ctx )
105+ if err != nil {
106+ return fmt .Errorf ("wait for MongoDB Flex instance restoration: %w" , err )
107+ }
108+ s .Stop ()
109+ }
110+
99111 p .Outputf ("Restored instance %q with backup %q\n " , model .InstanceId , model .BackupId )
100112 return nil
101113 }
102114
103- // Else, if timestamp is provided, clone the instance from the backup with the timestep
115+ // Else, if timestamp is provided, clone the instance from a point-in-time snapshot
104116 req := buildCloneRequest (ctx , model , apiClient )
105117 _ , err = req .Execute ()
106118 if err != nil {
107119 return fmt .Errorf ("clone MongoDB Flex instance: %w" , err )
108120 }
121+
122+ if ! model .Async {
123+ s := spinner .New (p )
124+ s .Start ("Cloning instance" )
125+ _ , err = wait .CloneInstanceWaitHandler (ctx , apiClient , model .ProjectId , model .InstanceId ).WaitWithContext (ctx )
126+ if err != nil {
127+ return fmt .Errorf ("wait for MongoDB Flex instance cloning: %w" , err )
128+ }
129+ s .Stop ()
130+ }
131+
109132 p .Outputf ("Cloned instance %q from backup with timestamp %q\n " , model .InstanceId , model .Timestamp )
110133 return nil
111134 },
0 commit comments