forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.go
78 lines (68 loc) · 1.89 KB
/
backup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2015, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vtctl
import (
"flag"
"fmt"
"github.com/youtube/vitess/go/vt/mysqlctl/backupstorage"
"github.com/youtube/vitess/go/vt/topo/topoproto"
"github.com/youtube/vitess/go/vt/wrangler"
"golang.org/x/net/context"
)
func init() {
addCommand("Shards", command{
"ListBackups",
commandListBackups,
"<keyspace/shard>",
"Lists all the backups for a shard."})
addCommand("Shards", command{
"RemoveBackup",
commandRemoveBackup,
"<keyspace/shard> <backup name>",
"Removes a backup for the BackupStorage."})
}
func commandListBackups(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
if err := subFlags.Parse(args); err != nil {
return err
}
if subFlags.NArg() != 1 {
return fmt.Errorf("action ListBackups requires <keyspace/shard>")
}
keyspace, shard, err := topoproto.ParseKeyspaceShard(subFlags.Arg(0))
if err != nil {
return err
}
bucket := fmt.Sprintf("%v/%v", keyspace, shard)
bs, err := backupstorage.GetBackupStorage()
if err != nil {
return err
}
bhs, err := bs.ListBackups(bucket)
if err != nil {
return err
}
for _, bh := range bhs {
wr.Logger().Printf("%v\n", bh.Name())
}
return nil
}
func commandRemoveBackup(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
if err := subFlags.Parse(args); err != nil {
return err
}
if subFlags.NArg() != 2 {
return fmt.Errorf("action RemoveBackup requires <keyspace/shard> <backup name>")
}
keyspace, shard, err := topoproto.ParseKeyspaceShard(subFlags.Arg(0))
if err != nil {
return err
}
bucket := fmt.Sprintf("%v/%v", keyspace, shard)
name := subFlags.Arg(1)
bs, err := backupstorage.GetBackupStorage()
if err != nil {
return err
}
return bs.RemoveBackup(bucket, name)
}