Skip to content

Commit

Permalink
add cassandra data dir existence tet before backup or restore, fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Dec 31, 2018
1 parent cfa713f commit 0e658c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/cain/cain.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func Backup(o BackupOptions) (string, error) {
return "", err
}

log.Println("Testing existence of data dir")
if err := utils.TestK8sDirectory(k8sClient, pods, o.Namespace, o.Container, o.CassandraDataDir); err != nil {
return "", err
}

log.Println("Backing up schema")
dstBasePath, err := BackupKeyspaceSchema(k8sClient, dstClient, o.Namespace, pods[0], o.Container, o.Keyspace, dstPrefix, dstPath)
if err != nil {
Expand Down Expand Up @@ -101,6 +106,11 @@ func Restore(o RestoreOptions) error {
return err
}

log.Println("Testing existence of data dir")
if err := utils.TestK8sDirectory(k8sClient, existingPods, o.Namespace, o.Container, o.CassandraDataDir); err != nil {
return err
}

log.Println("Getting current schema")
_, sum, err := DescribeKeyspaceSchema(k8sClient, o.Namespace, existingPods[0], o.Container, o.Keyspace)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions pkg/utils/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,19 @@ func ChangeFilesOwnership(iK8sClient interface{}, pods []string, namespace, cont
}
return nil
}

// TestK8sDirectory checks if a path exists
func TestK8sDirectory(iK8sClient interface{}, pods []string, namespace, container, cassandraDataDir string) error {
k8sClient := iK8sClient.(*skbn.K8sClient)
command := []string{"ls", cassandraDataDir}
for _, pod := range pods {
stderr, err := skbn.Exec(*k8sClient, namespace, pod, container, command, nil, nil)
if len(stderr) != 0 {
return fmt.Errorf("STDERR: " + (string)(stderr))
}
if err != nil {
return fmt.Errorf(cassandraDataDir + " does not exist. " + err.Error())
}
}
return nil
}

0 comments on commit 0e658c0

Please sign in to comment.