diff --git a/neo4j-admin/backup/main/operations.go b/neo4j-admin/backup/main/operations.go index c7df132e..14ed0519 100644 --- a/neo4j-admin/backup/main/operations.go +++ b/neo4j-admin/backup/main/operations.go @@ -183,7 +183,8 @@ func startupOperations() { err = neo4jAdmin.CheckDatabaseConnectivity(address) handleError(err) - os.Setenv("LOCATION", "/backups") + backupPath := neo4jAdmin.GetBackupPath() + os.Setenv("LOCATION", backupPath) } func handleError(err error) { @@ -216,16 +217,19 @@ func generateAddress() (string, error) { func deleteBackupFiles(backupFileNames, consistencyCheckReports []string) error { if value, present := os.LookupEnv("KEEP_BACKUP_FILES"); present && value == "false" { + backupPath := neo4jAdmin.GetBackupPath() for _, backupFileName := range backupFileNames { - log.Printf("Deleting file /backups/%s", backupFileName) - err := os.Remove(fmt.Sprintf("/backups/%s", backupFileName)) + filePath := fmt.Sprintf("%s/%s", backupPath, backupFileName) + log.Printf("Deleting file %s", filePath) + err := os.Remove(filePath) if err != nil { return err } } for _, consistencyCheckReportName := range consistencyCheckReports { - log.Printf("Deleting file /backups/%s", consistencyCheckReportName) - err := os.Remove(fmt.Sprintf("/backups/%s", consistencyCheckReportName)) + filePath := fmt.Sprintf("%s/%s", backupPath, consistencyCheckReportName) + log.Printf("Deleting file %s", filePath) + err := os.Remove(filePath) if err != nil { return err } diff --git a/neo4j-admin/backup/neo4j-admin/helpers.go b/neo4j-admin/backup/neo4j-admin/helpers.go index 3948e598..f3678383 100644 --- a/neo4j-admin/backup/neo4j-admin/helpers.go +++ b/neo4j-admin/backup/neo4j-admin/helpers.go @@ -16,6 +16,12 @@ func getBackupPath() string { return "/backups" } +// GetBackupPath returns the configured backup path or the default /backups +// This is exported for use in other packages +func GetBackupPath() string { + return getBackupPath() +} + // getBackupCommandFlags returns a slice of string containing all the flags to be passed with the neo4j-admin backup command func getBackupCommandFlags(address string) []string { flags := []string{"database", "backup"} diff --git a/neo4j-admin/backup/neo4j-admin/operations.go b/neo4j-admin/backup/neo4j-admin/operations.go index 0abe4960..bb6417a0 100644 --- a/neo4j-admin/backup/neo4j-admin/operations.go +++ b/neo4j-admin/backup/neo4j-admin/operations.go @@ -171,8 +171,9 @@ func PerformConsistencyCheck(database string) (string, error) { log.Printf("Inconsistencies found for database %s. Exit code was %d\n", database, me.ExitCode()) log.Printf("Consistency Check Completed !!") - tarFileName := fmt.Sprintf("/backups/%s.report.tar.gz", fileName) - directoryName := fmt.Sprintf("/backups/%s.report", fileName) + backupPath := getBackupPath() + tarFileName := fmt.Sprintf("%s/%s.report.tar.gz", backupPath, fileName) + directoryName := fmt.Sprintf("%s/%s.report", backupPath, fileName) log.Printf("tarfileName %s directoryName %s", tarFileName, directoryName) _, err = exec.Command("tar", "-czvf", tarFileName, directoryName, "--absolute-names").CombinedOutput() if err != nil { diff --git a/neo4j-admin/templates/neo4j-cronjob.yaml b/neo4j-admin/templates/neo4j-cronjob.yaml index ca8a0179..c7d05e85 100644 --- a/neo4j-admin/templates/neo4j-cronjob.yaml +++ b/neo4j-admin/templates/neo4j-cronjob.yaml @@ -67,6 +67,8 @@ spec: value: {{ .Values.backup.cloudProvider | trim }} - name: BUCKET_NAME value: {{ .Values.backup.bucketName | trim }} + - name: BACKUP_PATH + value: {{ .Values.backup.backupPath | default "/backups" | trim | quote }} - name: KEEP_BACKUP_FILES value: {{ .Values.backup.keepBackupFiles| toString | quote | default true }} - name: PAGE_CACHE diff --git a/neo4j-admin/values.yaml b/neo4j-admin/values.yaml index 2ff2f440..9752d44b 100644 --- a/neo4j-admin/values.yaml +++ b/neo4j-admin/values.yaml @@ -91,6 +91,12 @@ backup: # the /backups mount can point to a persistentVolume based on the definition set in tempVolume cloudProvider: "" + # Path where backups will be written within the mounted volume + # Default: /backups (writes to the root of the mounted volume) + # To match neo4j db chart's /backups mount with subPath, set this to /backups/backups + # This allows configuring the backup directory to align with how the neo4j db chart mounts volumes + backupPath: "/backups" + # name of the kubernetes secret containing the respective cloud provider credentials # Ensure you have read,write access to the mentioned bucket # For AWS :