Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/gpctl/cmd/workspaces-backup.go
2498 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"context"
9
"strings"
10
11
"github.com/spf13/cobra"
12
13
"github.com/gitpod-io/gitpod/common-go/log"
14
"github.com/gitpod-io/gitpod/ws-manager/api"
15
)
16
17
// workspacesBackupCmd represents the backup command
18
var workspacesBackupCmd = &cobra.Command{
19
Use: "backup <workspaceID>",
20
Short: "takes a backup of a workspace",
21
Args: cobra.ExactArgs(1),
22
Run: func(cmd *cobra.Command, args []string) {
23
ctx, cancel := context.WithCancel(context.Background())
24
defer cancel()
25
26
conn, client, err := getWorkspacesClient(ctx)
27
if err != nil {
28
log.WithError(err).Fatal("cannot connect")
29
}
30
defer conn.Close()
31
32
instanceID := args[0]
33
if strings.ContainsAny(instanceID, ".") || strings.HasPrefix(instanceID, "http://") || strings.HasPrefix(instanceID, "https://") {
34
s, err := getStatusByURL(ctx, client, instanceID)
35
if err != nil {
36
log.Fatal(err)
37
}
38
instanceID = s.Id
39
}
40
41
log.WithField("instance id", instanceID).Debug("starting workspace backup")
42
resp, err := client.BackupWorkspace(ctx, &api.BackupWorkspaceRequest{
43
Id: instanceID,
44
})
45
if err != nil {
46
log.WithError(err).Fatal("error during RPC call")
47
}
48
49
err = getOutputFormat("{{ .Url }}\n", "{.url}").Print(resp)
50
if err != nil {
51
log.Fatal(err)
52
}
53
},
54
}
55
56
func init() {
57
workspacesCmd.AddCommand(workspacesBackupCmd)
58
}
59
60