Test if backup directory is writable to avoid chown (#548)

diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go
index a46ba62..9e46fe8 100644
--- a/controllers/util/solr_util.go
+++ b/controllers/util/solr_util.go
@@ -618,6 +618,7 @@
 		},
 	}
 	setupCommands := []string{"cp /tmp/solr.xml /tmp-config/solr.xml"}
+	setupCommands = append(setupCommands, fmt.Sprintf("adduser -u %d -H -D solr", DefaultSolrUser))
 
 	// Add prep for backup-restore Repositories
 	// This entails setting the correct permissions for the directory
@@ -627,7 +628,8 @@
 				volumeMounts = append(volumeMounts, *volumeMount)
 
 				setupCommands = append(setupCommands, fmt.Sprintf(
-					"chown -R %d:%d %s",
+					"(su solr -c 'test -w %s' || chown -R %d:%d %s)",
+					volumeMount.MountPath,
 					DefaultSolrUser,
 					DefaultSolrGroup,
 					volumeMount.MountPath))
diff --git a/helm/solr-operator/Chart.yaml b/helm/solr-operator/Chart.yaml
index 6607cee..d7691bc 100644
--- a/helm/solr-operator/Chart.yaml
+++ b/helm/solr-operator/Chart.yaml
@@ -146,6 +146,13 @@
           url: https://github.com/apache/solr-operator/issues/477
         - name: GitHub PR
           url: https://github.com/apache/solr-operator/pull/546
+    - kind: fixed
+      description: Avoid backup directory chown when directories are already writable
+      links:
+        - name: GitHub Issue
+          url: https://github.com/apache/solr-operator/issues/537
+        - name: GitHub PR
+          url: https://github.com/apache/solr-operator/pull/548
   artifacthub.io/images: |
     - name: solr-operator
       image: apache/solr-operator:v0.7.0-prerelease