/
cmds.go
102 lines (92 loc) · 2.76 KB
/
cmds.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package cmds
import (
"fmt"
"os"
"github.com/pachyderm/pachyderm/src/client"
"github.com/pachyderm/pachyderm/src/server/pkg/cmdutil"
"github.com/golang/snappy"
"github.com/spf13/cobra"
)
// Cmds returns a slice containing admin commands.
func Cmds() []*cobra.Command {
var commands []*cobra.Command
var noObjects bool
var url string
extract := &cobra.Command{
Short: "Extract Pachyderm state to stdout or an object store bucket.",
Long: "Extract Pachyderm state to stdout or an object store bucket.",
Example: `
# Extract into a local file:
$ {{alias}} > backup
# Extract to s3:
$ {{alias}} -u s3://bucket/backup`,
Run: cmdutil.RunFixedArgs(0, func(args []string) (retErr error) {
c, err := client.NewOnUserMachine("user")
if err != nil {
return err
}
defer c.Close()
if url != "" {
return c.ExtractURL(url)
}
w := snappy.NewBufferedWriter(os.Stdout)
defer func() {
if err := w.Close(); err != nil && retErr == nil {
retErr = err
}
}()
return c.ExtractWriter(!noObjects, w)
}),
}
extract.Flags().BoolVar(&noObjects, "no-objects", false, "don't extract from object storage, only extract data from etcd")
extract.Flags().StringVarP(&url, "url", "u", "", "An object storage url (i.e. s3://...) to extract to.")
commands = append(commands, cmdutil.CreateAlias(extract, "extract"))
restore := &cobra.Command{
Short: "Restore Pachyderm state from stdin or an object store.",
Long: "Restore Pachyderm state from stdin or an object store.",
Example: `
# Restore from a local file:
$ {{alias}} < backup
# Restore from s3:
$ {{alias}} -u s3://bucket/backup`,
Run: cmdutil.RunFixedArgs(0, func(args []string) error {
c, err := client.NewOnUserMachine("user")
if err != nil {
return err
}
defer c.Close()
if url != "" {
err = c.RestoreURL(url)
} else {
err = c.RestoreReader(snappy.NewReader(os.Stdin))
}
if err != nil {
return fmt.Errorf("%v\nWARNING: Your cluster might be in an invalid "+
"state--consider deleting partially-restored data before continuing",
err)
}
return nil
}),
}
restore.Flags().StringVarP(&url, "url", "u", "", "An object storage url (i.e. s3://...) to restore from.")
commands = append(commands, cmdutil.CreateAlias(restore, "restore"))
inspectCluster := &cobra.Command{
Short: "Returns info about the pachyderm cluster",
Long: "Returns info about the pachyderm cluster",
Run: cmdutil.RunFixedArgs(0, func(args []string) error {
c, err := client.NewOnUserMachine("user")
if err != nil {
return err
}
defer c.Close()
ci, err := c.InspectCluster()
if err != nil {
return err
}
fmt.Println(ci.ID)
return nil
}),
}
commands = append(commands, cmdutil.CreateAlias(inspectCluster, "inspect cluster"))
return commands
}