fix: use new removeOldBackups function

- use the new removeOldBackups function
- only call removeOldBackups function when the backup is completed and also only if the backup is successful
This commit is contained in:
peaklabs-dev
2025-01-13 18:39:22 +01:00
parent 3dfca4e4bd
commit 9eebeb9241

View File

@@ -299,7 +299,6 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
throw new \Exception('Unsupported database type');
}
$size = $this->calculate_size();
$this->remove_old_backups();
if ($this->backup->save_s3) {
$this->upload_to_s3();
}
@@ -323,6 +322,9 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
$this->team?->notify(new BackupFailed($this->backup, $this->database, $this->backup_output, $database));
}
}
if ($this->backup_log && $this->backup_log->status === 'success') {
removeOldBackups($this->backup);
}
} catch (\Throwable $e) {
throw $e;
} finally {
@@ -457,14 +459,6 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
return instant_remote_process(["du -b $this->backup_location | cut -f1"], $this->server, false);
}
private function remove_old_backups(): void
{
deleteOldBackupsLocally($this->backup);
if ($this->backup->save_s3) {
deleteOldBackupsFromS3($this->backup);
}
}
private function upload_to_s3(): void
{
try {