-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
fly volume snapshot create
(#3087)
This new command is used to snapshot volumes on-demand.
- Loading branch information
Showing
7 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package snapshots | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/superfly/flyctl/client" | ||
"github.com/superfly/flyctl/flaps" | ||
"github.com/superfly/flyctl/internal/appconfig" | ||
"github.com/superfly/flyctl/internal/command" | ||
"github.com/superfly/flyctl/internal/flag" | ||
) | ||
|
||
func newCreate() *cobra.Command { | ||
const ( | ||
short = "Snapshot a volume" | ||
long = "Snapshot a volume\n" | ||
usage = "create <volume-id>" | ||
) | ||
|
||
cmd := command.New(usage, short, long, create, command.RequireSession) | ||
cmd.Args = cobra.ExactArgs(1) | ||
|
||
flag.Add(cmd, flag.JSONOutput()) | ||
return cmd | ||
} | ||
|
||
func create(ctx context.Context) error { | ||
var client = client.FromContext(ctx).API() | ||
|
||
volumeId := flag.FirstArg(ctx) | ||
|
||
appName := appconfig.NameFromContext(ctx) | ||
if appName == "" { | ||
n, err := client.GetAppNameFromVolume(ctx, volumeId) | ||
if err != nil { | ||
return err | ||
} | ||
appName = *n | ||
} | ||
|
||
flapsClient, err := flaps.NewFromAppName(ctx, appName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = flapsClient.CreateVolumeSnapshot(ctx, volumeId) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Scheduled to snapshot volume %s\n", volumeId) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ func New() *cobra.Command { | |
|
||
snapshots.AddCommand( | ||
newList(), | ||
newCreate(), | ||
) | ||
|
||
return snapshots | ||
|