fix: backup job deletion - delete all backups from s3 and local

This commit is contained in:
peaklabs-dev
2025-01-13 17:31:55 +01:00
parent c03b629e85
commit 3dfca4e4bd
2 changed files with 30 additions and 10 deletions

View File

@@ -123,13 +123,29 @@ class BackupEdit extends Component
} }
try { try {
if ($this->delete_associated_backups_locally) { $server = null;
$filenames = $this->backup->executions->pluck('filename')->filter()->all(); if ($this->backup->database instanceof \App\Models\ServiceDatabase) {
deleteBackupsLocally($filenames, $this->backup->server); $server = $this->backup->database->service->destination->server;
} elseif ($this->backup->database->destination && $this->backup->database->destination->server) {
$server = $this->backup->database->destination->server;
} }
if ($this->delete_associated_backups_s3 && $this->backup->s3) {
$filenames = $this->backup->executions->pluck('filename')->filter()->all(); $filenames = $this->backup->executions()
deleteBackupsS3($filenames, $this->backup->s3); ->whereNotNull('filename')
->where('filename', '!=', '')
->where('scheduled_database_backup_id', $this->backup->id)
->pluck('filename')
->filter()
->all();
if (! empty($filenames)) {
if ($this->delete_associated_backups_locally && $server) {
deleteBackupsLocally($filenames, $server);
}
if ($this->delete_associated_backups_s3 && $this->backup->s3) {
deleteBackupsS3($filenames, $this->backup->s3);
}
} }
$this->backup->delete(); $this->backup->delete();
@@ -145,7 +161,9 @@ class BackupEdit extends Component
} else { } else {
return redirect()->route('project.database.backup.index', $this->parameters); return redirect()->route('project.database.backup.index', $this->parameters);
} }
} catch (\Throwable $e) { } catch (\Exception $e) {
$this->dispatch('error', 'Failed to delete backup: '.$e->getMessage());
return handleError($e, $this); return handleError($e, $this);
} }
} }

View File

@@ -62,10 +62,12 @@ class BackupExecutions extends Component
: $execution->scheduledDatabaseBackup->database->destination->server; : $execution->scheduledDatabaseBackup->database->destination->server;
try { try {
deleteBackupsLocally($execution->filename, $server); if ($execution->filename) {
deleteBackupsLocally($execution->filename, $server);
if ($this->delete_backup_s3 && $execution->scheduledDatabaseBackup->s3) { if ($this->delete_backup_s3 && $execution->scheduledDatabaseBackup->s3) {
deleteBackupsS3($execution->filename, $execution->scheduledDatabaseBackup->s3); deleteBackupsS3($execution->filename, $execution->scheduledDatabaseBackup->s3);
}
} }
$execution->delete(); $execution->delete();