fix backup, requrie backup job to be removed before creating a new one
@@ -170,6 +170,11 @@ func CreateBackup(request *msgs.CreateBackupRequest) msgs.CreateBackupResponse {
}
for _, arg := range request.Args {
log.Debug("create backup called for " + arg)
+
+ if BackupJobExists("backup-" + arg) {
+ resp.Results = append(resp.Results, "please delete job backup-"+arg+" before creating another backup")
+ } else {
+
result := crv1.Pgbackup{}
// error if it already exists
@@ -214,6 +219,7 @@ func CreateBackup(request *msgs.CreateBackupRequest) msgs.CreateBackupResponse {
return resp
}
resp.Results = append(resp.Results, "created Pgbackup "+arg)
+ }
}
@@ -269,3 +275,20 @@ func getBackupParams(name, storageConfig string) (*crv1.Pgbackup, error) {
}
return newInstance, nil
}
+
+func BackupJobExists(name string) bool {
+
+ options := meta_v1.GetOptions{}
+ resultJob, err := apiserver.Clientset.Batch().Jobs(apiserver.Namespace).Get(name, options)
+ if kerrors.IsNotFound(err) {
+ log.Debug("Job " + err.Error())
+
+ return false
+ }
+ if err != nil {
+ log.Error("error getting Job " + err.Error())
+ return false
+ }
+ log.Debugf("found job %v\n", resultJob)
+ return true
+}
