/
snapshot.go
123 lines (103 loc) · 3.97 KB
/
snapshot.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"strings"
"github.com/spf13/cobra"
)
var r string
var f string
var w bool
var n bool
var s string
var cleanNumber int
var snapshotCmd = &cobra.Command{
Use: "snapshot",
Short: "tool for managing snapshots",
}
var snapshotRepoRegister = &cobra.Command{
Use: "register [name]",
Short: "Register a new snapshot repository",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
response := client.SnapshotRepoRegister(strings.Join(args, ""), readFromFile())
printResponse(response)
},
}
var snapshotStart = &cobra.Command{
Use: "start [name]",
Short: "Kick off a snapshot",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
response := client.SnapshotStart(strings.Join(args, ""), r, readFromFile(), w, n, s)
printResponse(response)
},
}
var snapshotList = &cobra.Command{
Use: "list",
Short: "List your available snapshots",
Run: func(cmd *cobra.Command, args []string) {
response := client.SnapshotList(r)
printResponse(response)
},
}
var snapshotGet = &cobra.Command{
Use: "get [name]",
Short: "Get details about a snapshot",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
response := client.SnapshotGet(strings.Join(args, ""), r)
printResponse(response)
},
}
var snapshotRestore = &cobra.Command{
Use: "restore [name]",
Short: "Restore a snapshot",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
response := client.SnapshotRestore(strings.Join(args, ""), r, readFromFile(), w)
printResponse(response)
},
}
var snapshotDelete = &cobra.Command{
Use: "delete [name]",
Short: "Delete a snapshot",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if confirm() {
response := client.SnapshotDelete(strings.Join(args, ""), r)
printResponse(response)
}
},
}
var snapshotClean = &cobra.Command{
Use: "clean [# number]",
Short: "Delete all but a certain number of snapshots",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if confirm() {
client.SnapshotClean(cleanNumber, r)
}
},
}
func init() {
rootCmd.AddCommand(snapshotCmd)
snapshotCmd.AddCommand(snapshotRepoRegister, snapshotStart, snapshotRestore, snapshotClean, snapshotList,
snapshotGet, snapshotDelete)
snapshotCmd.PersistentFlags().StringVarP(&f, "frequency", "f", "", "Frequency of the snapshot")
snapshotCmd.PersistentFlags().StringVarP(&r, "repo", "r", "", "Repository for the snapshot")
snapshotList.Flags().StringVarP(&f, "frequency", "f", "", "Frequency of the snapshot")
snapshotList.Flags().StringVarP(&r, "repo", "r", "", "Repository for the snapshot")
snapshotGet.Flags().StringVarP(&f, "frequency", "f", "", "Frequency of the snapshot")
snapshotGet.Flags().StringVarP(&r, "repo", "r", "", "Repository for the snapshot")
snapshotDelete.Flags().StringVarP(&f, "frequency", "f", "", "Frequency of the snapshot")
snapshotDelete.Flags().StringVarP(&r, "repo", "r", "", "Repository for the snapshot")
snapshotStart.Flags().BoolVarP(&w, "wait", "w", false, "Wait for completion of snapshot")
snapshotStart.Flags().BoolVarP(&n, "notify", "n", false, "Send notification to slack")
snapshotStart.Flags().StringVarP(&s, "slack", "s", "", "Slack webhook to send snapshot failures to")
snapshotRestore.Flags().BoolVarP(&w, "wait", "w", false, "Wait for completion of restore")
snapshotStart.Flags().StringVarP(&body, "body", "b", "", "json body to send with this request")
snapshotRestore.Flags().StringVarP(&body, "body", "b", "", "json body to send with this request")
snapshotDelete.Flags().BoolVarP(&override, "confirm", "y", false, "Confirm that you want to destroy a snapshot")
snapshotClean.Flags().BoolVarP(&override, "confirm", "y", false, "Confirm that you want to destroy a snapshot")
snapshotClean.Flags().IntVarP(&cleanNumber, "number", "n", 3, "number of snapshots to keep")
snapshotRepoRegister.Flags().StringVarP(&body, "body", "b", "", "json body to send with this request")
}