Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

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

peaklabs-dev3dfca4e4bd79
diff --git a/app/Livewire/Project/Database/BackupEdit.php b/app/Livewire/Project/Database/BackupEdit.php
index 19b7987dbf..853b918b82 100644
--- a/app/Livewire/Project/Database/BackupEdit.php
+++ b/app/Livewire/Project/Database/BackupEdit.php
@@ -123,13 +123,29 @@ class BackupEdit extends Component
}
try {
- if ($this->delete_associated_backups_locally) {
- $filenames = $this->backup->executions->pluck('filename')->filter()->all();
- deleteBackupsLocally($filenames, $this->backup->server);
+ $server = null;
+ if ($this->backup->database instanceof \App\Models\ServiceDatabase) {
+ $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();
- deleteBackupsS3($filenames, $this->backup->s3);
+
+ $filenames = $this->backup->executions()
+ ->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();
@@ -145,7 +161,9 @@ class BackupEdit extends Component
} else {
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);
}
}
diff --git a/app/Livewire/Project/Database/BackupExecutions.php b/app/Livewire/Project/Database/BackupExecutions.php
index 526239eea2..7eef1a539c 100644
--- a/app/Livewire/Project/Database/BackupExecutions.php
+++ b/app/Livewire/Project/Database/BackupExecutions.php
@@ -62,10 +62,12 @@ class BackupExecutions extends Component
: $execution->scheduledDatabaseBackup->database->destination->server;
try {
- deleteBackupsLocally($execution->filename, $server);
+ if ($execution->filename) {
+ deleteBackupsLocally($execution->filename, $server);
- if ($this->delete_backup_s3 && $execution->scheduledDatabaseBackup->s3) {
- deleteBackupsS3($execution->filename, $execution->scheduledDatabaseBackup->s3);
+ if ($this->delete_backup_s3 && $execution->scheduledDatabaseBackup->s3) {
+ deleteBackupsS3($execution->filename, $execution->scheduledDatabaseBackup->s3);
+ }
}
$execution->delete();