Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request vitessio#7352 from tinyspeck/am_vtctld_listbackups
Browse files Browse the repository at this point in the history
[vtctld] Migrate ListBackups as GetBackups in new vtctld server
  • Loading branch information
rohit-nayak-ps authored and ajm188 committed Feb 11, 2021
1 parent 70fe751 commit 5dbea28
Show file tree
Hide file tree
Showing 14 changed files with 638 additions and 140 deletions.
59 changes: 59 additions & 0 deletions go/cmd/vtctldclient/internal/command/backups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2021 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package command

import (
"fmt"
"strings"

"github.com/spf13/cobra"

vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

// GetBackups makes a GetBackups gRPC call to a vtctld.
var GetBackups = &cobra.Command{
Use: "GetBackups keyspace shard",
Args: cobra.ExactArgs(2),
RunE: commandGetBackups,
}

func commandGetBackups(cmd *cobra.Command, args []string) error {
keyspace := cmd.Flags().Arg(0)
shard := cmd.Flags().Arg(1)

resp, err := client.GetBackups(commandCtx, &vtctldatapb.GetBackupsRequest{
Keyspace: keyspace,
Shard: shard,
})
if err != nil {
return err
}

names := make([]string, len(resp.Backups))
for i, b := range resp.Backups {
names[i] = b.Name
}

fmt.Printf("%s\n", strings.Join(names, "\n"))

return nil
}

func init() {
Root.AddCommand(GetBackups)
}
31 changes: 31 additions & 0 deletions go/vt/mysqlctl/mysqlctlproto/backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2021 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package mysqlctlproto

import (
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"

mysqlctlpb "vitess.io/vitess/go/vt/proto/mysqlctl"
)

// BackupHandleToProto returns a BackupInfo proto from a BackupHandle.
func BackupHandleToProto(bh backupstorage.BackupHandle) *mysqlctlpb.BackupInfo {
return &mysqlctlpb.BackupInfo{
Name: bh.Name(),
Directory: bh.Directory(),
}
}
21 changes: 21 additions & 0 deletions go/vt/mysqlctl/mysqlctlproto/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2021 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/*
Package mysqlctlproto provides utility functions for working with data
structures in mysqlctl.proto.
*/
package mysqlctlproto
97 changes: 74 additions & 23 deletions go/vt/proto/mysqlctl/mysqlctl.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5dbea28

Please sign in to comment.