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(backups): retain volume backups without server

Andras Bacsai994eee83777c
diff --git a/app/Jobs/ScheduledJobManager.php b/app/Jobs/ScheduledJobManager.php
index 01b122a8d7..6e2fab14a5 100644
--- a/app/Jobs/ScheduledJobManager.php
+++ b/app/Jobs/ScheduledJobManager.php
@@ -2,6 +2,7 @@
namespace App\Jobs;
+use App\Actions\Shared\DeleteScheduledVolumeBackup;
use App\Models\ScheduledDatabaseBackup;
use App\Models\ScheduledTask;
use App\Models\ScheduledVolumeBackup;
@@ -397,8 +398,8 @@ class ScheduledJobManager implements ShouldQueue
return;
}
- if (! $backup->backupable || ! $server) {
- $backup->delete();
+ if (! $backup->backupable) {
+ DeleteScheduledVolumeBackup::run($backup, $server);
$this->skippedCount++;
$this->logSkip('volume_backup', 'resource_deleted', [
'backup_id' => $backup->id,
@@ -408,6 +409,16 @@ class ScheduledJobManager implements ShouldQueue
return;
}
+ if (! $server) {
+ $this->skippedCount++;
+ $this->logSkip('volume_backup', 'server_missing', [
+ 'backup_id' => $backup->id,
+ 'team_id' => $backup->team_id,
+ ]);
+
+ return;
+ }
+
if (! $server->isFunctional()) {
$this->skippedCount++;
$this->logSkip('volume_backup', 'server_not_functional', [
diff --git a/tests/Feature/VolumeBackupTest.php b/tests/Feature/VolumeBackupTest.php
index e00841110a..256dbb5e5d 100644
--- a/tests/Feature/VolumeBackupTest.php
+++ b/tests/Feature/VolumeBackupTest.php
@@ -2010,6 +2010,34 @@ it('dispatches due scheduled directory backups', function () {
);
});
+it('retains scheduled volume backups and archive metadata when the server is missing', function () {
+ config(['constants.coolify.self_hosted' => true]);
+ Queue::fake();
+ $team = Team::factory()->create();
+ [$application, $volume] = createVolumeBackupApplication($team);
+ $backup = $volume->scheduledBackups()->create([
+ 'team_id' => $team->id,
+ 'frequency' => '* * * * *',
+ 'enabled' => true,
+ ]);
+ $execution = ScheduledVolumeBackupExecution::create([
+ 'scheduled_volume_backup_id' => $backup->id,
+ 'status' => 'success',
+ 'filename' => '/data/coolify/backups/volumes/test/archive.tar.gz',
+ ]);
+ $application->update([
+ 'destination_id' => null,
+ 'destination_type' => null,
+ ]);
+
+ (new ScheduledJobManager)->handle();
+
+ expect($backup->fresh())->not->toBeNull()
+ ->and($execution->fresh())->not->toBeNull()
+ ->and($execution->fresh()->filename)->toBe('/data/coolify/backups/volumes/test/archive.tar.gz');
+ Queue::assertNotPushed(VolumeBackupJob::class);
+});
+
it('dispatches pending recovery without starting another volume backup', function () {
config(['constants.coolify.self_hosted' => true]);
Queue::fake();