@@ -186,38 +186,59 @@ func NIMJobList() []Job {
186
186
},
187
187
},
188
188
{
189
- Name : "exec-dqlite-dump-core " ,
189
+ Name : "exec-dqlite-dump" ,
190
190
Timeout : time .Second * 30 ,
191
191
Execute : func (dc * data_collector.DataCollector , ctx context.Context , ch chan JobResult ) {
192
192
jobResult := JobResult {Files : make (map [string ][]byte ), Error : nil }
193
- containerName := "core"
194
- dbName := "core"
195
- outputFile := "/tmp/core.sql"
196
- dbAddr := "0.0.0.0:7891"
193
+
194
+ dbConfigs := []struct {
195
+ dbName string
196
+ containerName string
197
+ outputFile string
198
+ dbAddr string
199
+ }{
200
+ {"core" , "core" , "/tmp/core.sql" , "0.0.0.0:7891" },
201
+ {"dpm" , "dpm" , "/tmp/dpm.sql" , "0.0.0.0:7890" },
202
+ {"integrations" , "integrations" , "/tmp/integrations.sql" , "0.0.0.0:7892" },
203
+ {"license" , "integrations" , "/tmp/license.sql" , "0.0.0.0:7893" },
204
+ // Add more containers as needed
205
+ }
197
206
198
207
// /etc/nms/scripts/dqlite-backup -n core -c /etc/nms/nms.conf -a 0.0.0.0:7891 -o /tmp/core.sql -k
199
- command := [] string { dqliteBackupPath , "-n" , dbName , "-c" , nmsConfigPath , "-a" , dbAddr , "-o" , outputFile , "-k" }
208
+
200
209
for _ , namespace := range dc .Namespaces {
201
210
pods , err := dc .K8sCoreClientSet .CoreV1 ().Pods (namespace ).List (ctx , metav1.ListOptions {})
202
211
if err != nil {
203
212
dc .Logger .Printf ("\t Could not retrieve pod list for namespace %s: %v\n " , namespace , err )
204
213
} else {
205
- for _ , pod := range pods .Items {
206
- if strings .Contains (pod .Name , containerName ) {
207
- res , err := dc .PodExecutor (namespace , pod .Name , containerName , command , ctx )
208
- if err != nil {
209
- jobResult .Error = err
210
- dc .Logger .Printf ("\t Command execution %s failed for pod %s in namespace %s: %v\n " , command , pod .Name , namespace , err )
211
- } else {
212
- jobResult .Files [filepath .Join (dc .BaseDir , "exec" , namespace , pod .Name + "__dqlite-dump-" + containerName + ".txt" )] = res
213
-
214
- // Move the dumped file to the base directory
215
- destPathFilename := filepath .Join (dc .BaseDir , "exec" , namespace , pod .Name + "__dqlite-dump-" + filepath .Base (outputFile ))
216
- if err := dc .CopyFileFromPod (namespace , pod .Name , containerName , outputFile , destPathFilename , ctx ); err != nil {
214
+ for _ , config := range dbConfigs {
215
+ command := []string {dqliteBackupPath , "-n" , config .dbName , "-c" , nmsConfigPath , "-a" , config .dbAddr , "-o" , config .outputFile , "-k" }
216
+ for _ , pod := range pods .Items {
217
+ if strings .Contains (pod .Name , config .containerName ) {
218
+ res , err := dc .PodExecutor (namespace , pod .Name , config .containerName , command , ctx )
219
+ if err != nil {
217
220
jobResult .Error = err
218
- dc .Logger .Printf ("\t Failed to copy dumped file for pod %s in namespace %s: %v\n " , pod .Name , namespace , err )
221
+ dc .Logger .Printf ("\t Command execution %s failed for pod %s in namespace %s: %v\n " , command , pod .Name , namespace , err )
219
222
} else {
220
- dc .Logger .Printf ("\t Successfully copied dumped file for pod %s in namespace %s\n " , pod .Name , namespace )
223
+ jobResult .Files [filepath .Join (dc .BaseDir , "exec" , namespace , pod .Name + "__dqlite-dump-" + config .dbName + ".txt" )] = res
224
+
225
+ // Copy the dumped file from the pod to the host
226
+ destPathFilename := filepath .Join (dc .BaseDir , "exec" , namespace , pod .Name + "__dqlite-dump-" + filepath .Base (config .outputFile ))
227
+ if err := dc .CopyFileFromPod (namespace , pod .Name , config .containerName , config .outputFile , destPathFilename , ctx ); err != nil {
228
+ jobResult .Error = err
229
+ dc .Logger .Printf ("\t Failed to copy dumped file %s from pod %s in namespace %s to %s: %v\n " , config .outputFile , pod .Name , namespace , destPathFilename , err )
230
+ } else {
231
+ dc .Logger .Printf ("\t Successfully copied dumped file %s from pod %s in namespace %s to %s\n " , config .outputFile , pod .Name , namespace , destPathFilename )
232
+ }
233
+
234
+ // Remove/delete the dumped file from the pod
235
+ _ , err := dc .PodExecutor (namespace , pod .Name , config .containerName , []string {"rm" , "-f" , config .outputFile }, ctx )
236
+ if err != nil {
237
+ jobResult .Error = err
238
+ dc .Logger .Printf ("\t Failed to remove dumped file %s from pod %s in namespace %s: %v\n " , config .outputFile , pod .Name , namespace , err )
239
+ } else {
240
+ dc .Logger .Printf ("\t Successfully removed dumped file %s from pod %s in namespace %s\n " , config .outputFile , pod .Name , namespace )
241
+ }
221
242
}
222
243
}
223
244
}
0 commit comments