Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: clean failed backup file (#2823)

Yilong Li9e5a8d1fa865
diff --git a/server/task_executor_database_backup.go b/server/task_executor_database_backup.go
index 048f7a1e81..0f26d110b5 100644
--- a/server/task_executor_database_backup.go
+++ b/server/task_executor_database_backup.go
@@ -76,6 +76,9 @@ func (exec *DatabaseBackupTaskExecutor) RunOnce(ctx context.Context, server *Ser
if backupErr != nil {
backupStatus = string(api.BackupStatusFailed)
comment = backupErr.Error()
+ if err := removeLocalBackupFile(server.profile.DataDir, backup); err != nil {
+ log.Warn(err.Error())
+ }
}
backupPatch := api.BackupPatch{
ID: backup.ID,
@@ -98,6 +101,17 @@ func (exec *DatabaseBackupTaskExecutor) RunOnce(ctx context.Context, server *Ser
}, nil
}
+func removeLocalBackupFile(dataDir string, backup *api.Backup) error {
+ if backup.StorageBackend != api.BackupStorageBackendLocal {
+ return nil
+ }
+ backupFilePath := getBackupAbsFilePath(dataDir, backup.DatabaseID, backup.Name)
+ if err := os.Remove(backupFilePath); err != nil {
+ return errors.Wrapf(err, "failed to delete the local backup file %s", backupFilePath)
+ }
+ return nil
+}
+
// getAvailableFSSpace gets the free space of the mounted filesystem.
// path is the pathname of any file within the mounted filesystem.
// It calls syscall statfs under the hood.
diff --git a/server/task_scheduler.go b/server/task_scheduler.go
index 83f0dd1ee1..9de365f707 100644
--- a/server/task_scheduler.go
+++ b/server/task_scheduler.go
@@ -318,14 +318,18 @@ func (s *TaskScheduler) ClearRunningTasks(ctx context.Context) error {
return errors.Wrapf(err, "failed to parse the payload of backup task %d", task.ID)
}
statusFailed := string(api.BackupStatusFailed)
- if _, err := s.server.store.PatchBackup(ctx, &api.BackupPatch{
+ backup, err := s.server.store.PatchBackup(ctx, &api.BackupPatch{
ID: payload.BackupID,
UpdaterID: api.SystemBotID,
Status: &statusFailed,
- }); err != nil {
+ })
+ if err != nil {
return errors.Wrapf(err, "failed to patch backup %d's status from %s to %s", payload.BackupID, api.BackupStatusPendingCreate, api.BackupStatusFailed)
}
log.Debug(fmt.Sprintf("Changed backup %d's status from %s to %s", payload.BackupID, api.BackupStatusPendingCreate, api.BackupStatusFailed))
+ if err := removeLocalBackupFile(s.server.profile.DataDir, backup); err != nil {
+ log.Warn(err.Error())
+ }
}
}
return nil