feat(backups): add configurable CPU usage for volume compression

Add server-level compression CPU presets for volume backups and close the private key modal after saving.
This commit is contained in:
Andras Bacsai committed 2026-08-14 12:00:46 +02:00
1 parent fe1dc209b7
commit 857375f69c
9 files changed
+142 -9

No files matched your search

@@ -60,6 +60,22 @@ test('generating a private key from the index stores it without redirecting to a
->assertNoRedirect();
});
test('saving a private key from its modal editor closes the modal', function () {
$privateKey = PrivateKey::factory()->create([
'team_id' => $this->team->id,
]);
Livewire::test(Show::class, [
'private_key_uuid' => $privateKey->uuid,
'modalMode' => true,
])->set('name', 'Updated SSH key')
->call('changePrivateKey')
->assertDispatched('securityResourceChanged')
->assertDispatched('close-modal');
expect($privateKey->fresh()->name)->toBe('Updated SSH key');
});
test('manual private key form does not expose key generation controls', function () {
Livewire::test(Create::class)
->assertDontSee('Generate new ED25519 SSH Key')
@@ -0,0 +1,52 @@
<?php
use App\Livewire\Server\Advanced;
use App\Models\Server;
use App\Models\Team;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
it('defaults and saves the server backup compression CPU preset', function () {
$team = Team::factory()->create();
$user = User::factory()->create();
$team->members()->attach($user, ['role' => 'owner']);
$server = Server::factory()->create(['team_id' => $team->id]);
$this->actingAs($user);
session(['currentTeam' => $team]);
expect($server->settings->backup_compression_cpu_percentage)->toBe(25);
Livewire::test(Advanced::class, ['server_uuid' => $server->uuid])
->assertSet('backupCompressionCpuPercentage', 25)
->assertSee('Backup compression CPU')
->assertSee('Sets how many CPU threads can be used to compress volume backups')
->assertDontSee('gzip fallback')
->assertSee('Low (25%)')
->set('backupCompressionCpuPercentage', 75)
->call('instantSave')
->assertHasNoErrors()
->assertDispatched('success');
expect($server->settings->fresh()->backup_compression_cpu_percentage)->toBe(75);
});
it('rejects unsupported server backup compression CPU percentages', function () {
$team = Team::factory()->create();
$user = User::factory()->create();
$team->members()->attach($user, ['role' => 'owner']);
$server = Server::factory()->create(['team_id' => $team->id]);
$this->actingAs($user);
session(['currentTeam' => $team]);
Livewire::test(Advanced::class, ['server_uuid' => $server->uuid])
->set('backupCompressionCpuPercentage', 30)
->call('instantSave')
->assertHasErrors(['backupCompressionCpuPercentage']);
expect($server->settings->fresh()->backup_compression_cpu_percentage)->toBe(25);
});
+10 -5
View File
@@ -1570,11 +1570,12 @@ it('marks a running execution failed even when the job instance lost its executi
&& str_contains($process->command, 'timed-out.tar.gz'));
});
it('archives a named volume on its server', function () {
it('archives a named volume using the server compression CPU percentage', function (int $compressionCpuPercentage) {
config(['broadcasting.default' => 'null']);
InstanceSettings::unguarded(fn () => InstanceSettings::create(['id' => 0]));
$team = Team::factory()->create();
[$application, $volume] = createVolumeBackupApplication($team);
[$application, $volume, $server] = createVolumeBackupApplication($team);
$server->settings->update(['backup_compression_cpu_percentage' => $compressionCpuPercentage]);
$backup = $volume->scheduledBackups()->create([
'team_id' => $team->id,
'frequency' => 'daily',
@@ -1608,13 +1609,16 @@ it('archives a named volume on its server', function () {
&& str_contains($process->command, 'app-data:/volume:ro')
&& str_contains($process->command, 'command -v pigz')
&& str_contains($process->command, 'pigz -3 -p')
&& str_contains($process->command, '$(nproc) + 1')
&& str_contains($process->command, "\$(nproc) * {$compressionCpuPercentage} + 99")
&& str_contains($process->command, 'gzip -3')
&& str_contains($process->command, 'tar -I "$compressor" -cf -')
&& str_contains($process->command, '> ')
&& str_contains($process->command, '.tar.gz')
&& ! str_contains($process->command, ':/backup'));
});
})->with([
'low' => 25,
'high' => 75,
]);
it('logs the selected volume backup compressor in development', function (string $detectedCompressor) {
config(['app.env' => 'local', 'broadcasting.default' => 'null']);
@@ -1644,7 +1648,8 @@ it('logs the selected volume backup compressor in development', function (string
Log::shouldHaveReceived('info')->once()->with(
'Volume backup compressor selected',
Mockery::on(fn (array $context): bool => $context['compressor'] === $detectedCompressor
&& $context['backup_id'] === $backup->id),
&& $context['backup_id'] === $backup->id
&& $context['cpu_percentage'] === 25),
);
})->with([
'pigz' => 'pigz -3 -p 4',