@@ -8,10 +8,21 @@ import (
8
8
"github.com/nuvo/skbn/pkg/skbn"
9
9
)
10
10
11
+ // BackupOptions are the options to pass to Backup
12
+ type BackupOptions struct {
13
+ Namespace string
14
+ Selector string
15
+ Container string
16
+ Keyspace string
17
+ Dst string
18
+ Parallel int
19
+ BufferSize float64
20
+ }
21
+
11
22
// Backup performs backup
12
- func Backup (namespace , selector , container , keyspace , dst string , parallel int , bufferSize float64 ) (string , error ) {
23
+ func Backup (o BackupOptions ) (string , error ) {
13
24
log .Println ("Backup started!" )
14
- dstPrefix , dstPath := utils .SplitInTwo (dst , "://" )
25
+ dstPrefix , dstPath := utils .SplitInTwo (o . Dst , "://" )
15
26
16
27
if err := skbn .TestImplementationsExist ("k8s" , dstPrefix ); err != nil {
17
28
return "" , err
@@ -24,42 +35,55 @@ func Backup(namespace, selector, container, keyspace, dst string, parallel int,
24
35
}
25
36
26
37
log .Println ("Getting pods" )
27
- pods , err := utils .GetPods (k8sClient , namespace , selector )
38
+ pods , err := utils .GetPods (k8sClient , o . Namespace , o . Selector )
28
39
if err != nil {
29
40
return "" , err
30
41
}
31
42
32
43
log .Println ("Backing up schema" )
33
- dstBasePath , err := BackupKeyspaceSchema (k8sClient , dstClient , namespace , pods [0 ], container , keyspace , dstPrefix , dstPath )
44
+ dstBasePath , err := BackupKeyspaceSchema (k8sClient , dstClient , o . Namespace , pods [0 ], o . Container , o . Keyspace , dstPrefix , dstPath )
34
45
if err != nil {
35
46
return "" , err
36
47
}
37
48
38
49
log .Println ("Taking snapshots" )
39
- tag := TakeSnapshots (k8sClient , pods , namespace , container , keyspace )
50
+ tag := TakeSnapshots (k8sClient , pods , o . Namespace , o . Container , o . Keyspace )
40
51
41
52
log .Println ("Calculating paths. This may take a while..." )
42
- fromToPathsAllPods , err := utils .GetFromAndToPathsFromK8s (k8sClient , pods , namespace , container , keyspace , tag , dstBasePath )
53
+ fromToPathsAllPods , err := utils .GetFromAndToPathsFromK8s (k8sClient , pods , o . Namespace , o . Container , o . Keyspace , tag , dstBasePath )
43
54
if err != nil {
44
55
return "" , err
45
56
}
46
57
47
58
log .Println ("Starting files copy" )
48
- if err := skbn .PerformCopy (k8sClient , dstClient , "k8s" , dstPrefix , fromToPathsAllPods , parallel , bufferSize ); err != nil {
59
+ if err := skbn .PerformCopy (k8sClient , dstClient , "k8s" , dstPrefix , fromToPathsAllPods , o . Parallel , o . BufferSize ); err != nil {
49
60
return "" , err
50
61
}
51
62
52
63
log .Println ("Clearing snapshots" )
53
- ClearSnapshots (k8sClient , pods , namespace , container , keyspace , tag )
64
+ ClearSnapshots (k8sClient , pods , o . Namespace , o . Container , o . Keyspace , tag )
54
65
55
66
log .Println ("All done!" )
56
67
return tag , nil
57
68
}
58
69
70
+ // RestoreOptions are the options to pass to Restore
71
+ type RestoreOptions struct {
72
+ Src string
73
+ Keyspace string
74
+ Tag string
75
+ Schema string
76
+ Namespace string
77
+ Selector string
78
+ Container string
79
+ Parallel int
80
+ BufferSize float64
81
+ }
82
+
59
83
// Restore performs restore
60
- func Restore (src , keyspace , tag , namespace , selector , container string , parallel int , bufferSize float64 ) error {
84
+ func Restore (o RestoreOptions ) error {
61
85
log .Println ("Restore started!" )
62
- srcPrefix , srcBasePath := utils .SplitInTwo (src , "://" )
86
+ srcPrefix , srcBasePath := utils .SplitInTwo (o . Src , "://" )
63
87
64
88
log .Println ("Getting clients" )
65
89
srcClient , k8sClient , err := skbn .GetClients (srcPrefix , "k8s" , srcBasePath , "" )
@@ -68,21 +92,21 @@ func Restore(src, keyspace, tag, namespace, selector, container string, parallel
68
92
}
69
93
70
94
log .Println ("Getting pods" )
71
- existingPods , err := utils .GetPods (k8sClient , namespace , selector )
95
+ existingPods , err := utils .GetPods (k8sClient , o . Namespace , o . Selector )
72
96
if err != nil {
73
97
return err
74
98
}
75
99
76
100
log .Println ("Getting current schema" )
77
- _ , sum , err := DescribeKeyspaceSchema (k8sClient , namespace , existingPods [0 ], container , keyspace )
101
+ _ , sum , err := DescribeKeyspaceSchema (k8sClient , o . Namespace , existingPods [0 ], o . Container , o . Keyspace )
78
102
if err != nil {
79
103
return err
80
104
}
81
105
log .Println ("Found schema:" , sum )
82
106
83
107
log .Println ("Calculating paths. This may take a while..." )
84
- srcPath := filepath .Join (srcBasePath , keyspace , sum , tag )
85
- fromToPaths , podsToBeRestored , tablesToRefresh , err := utils .GetFromAndToPathsSrcToK8s (srcClient , k8sClient , srcPrefix , srcPath , srcBasePath , namespace , container )
108
+ srcPath := filepath .Join (srcBasePath , o . Keyspace , sum , o . Tag )
109
+ fromToPaths , podsToBeRestored , tablesToRefresh , err := utils .GetFromAndToPathsSrcToK8s (srcClient , k8sClient , srcPrefix , srcPath , srcBasePath , o . Namespace , o . Container )
86
110
if err != nil {
87
111
return err
88
112
}
@@ -93,37 +117,45 @@ func Restore(src, keyspace, tag, namespace, selector, container string, parallel
93
117
}
94
118
95
119
log .Println ("Getting materialized views to exclude" )
96
- materializedViews , err := GetMaterializedViews (k8sClient , namespace , container , existingPods [0 ], keyspace )
120
+ materializedViews , err := GetMaterializedViews (k8sClient , o . Namespace , o . Container , existingPods [0 ], o . Keyspace )
97
121
if err != nil {
98
122
return err
99
123
}
100
124
101
125
log .Println ("Truncating tables" )
102
- TruncateTables (k8sClient , namespace , container , keyspace , existingPods , tablesToRefresh , materializedViews )
126
+ TruncateTables (k8sClient , o . Namespace , o . Container , o . Keyspace , existingPods , tablesToRefresh , materializedViews )
103
127
104
128
log .Println ("Starting files copy" )
105
- if err := skbn .PerformCopy (srcClient , k8sClient , srcPrefix , "k8s" , fromToPaths , parallel , bufferSize ); err != nil {
129
+ if err := skbn .PerformCopy (srcClient , k8sClient , srcPrefix , "k8s" , fromToPaths , o . Parallel , o . BufferSize ); err != nil {
106
130
return err
107
131
}
108
132
109
133
log .Println ("Refreshing tables" )
110
- RefreshTables (k8sClient , namespace , container , keyspace , podsToBeRestored , tablesToRefresh )
134
+ RefreshTables (k8sClient , o . Namespace , o . Container , o . Keyspace , podsToBeRestored , tablesToRefresh )
111
135
112
136
log .Println ("All done!" )
113
137
return nil
114
138
}
115
139
140
+ // SchemaOptions are the options to pass to Schema
141
+ type SchemaOptions struct {
142
+ Namespace string
143
+ Selector string
144
+ Container string
145
+ Keyspace string
146
+ }
147
+
116
148
// Schema gets the schema of the cassandra cluster
117
- func Schema (namespace , selector , container , keyspace string ) ([]byte , string , error ) {
149
+ func Schema (o SchemaOptions ) ([]byte , string , error ) {
118
150
k8sClient , err := skbn .GetClientToK8s ()
119
151
if err != nil {
120
152
return nil , "" , err
121
153
}
122
- pods , err := utils .GetPods (k8sClient , namespace , selector )
154
+ pods , err := utils .GetPods (k8sClient , o . Namespace , o . Selector )
123
155
if err != nil {
124
156
return nil , "" , err
125
157
}
126
- schema , sum , err := DescribeKeyspaceSchema (k8sClient , namespace , pods [0 ], container , keyspace )
158
+ schema , sum , err := DescribeKeyspaceSchema (k8sClient , o . Namespace , pods [0 ], o . Container , o . Keyspace )
127
159
if err != nil {
128
160
return nil , "" , err
129
161
}
0 commit comments