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

+13 -4
View File
@@ -77,13 +77,14 @@ class VolumeBackupJob implements ShouldBeEncrypted, ShouldQueue
$source = $this->backup->sourcePath();
$containerName = 'volume-backup-'.$this->execution->uuid;
$image = coolifyHelperImage().':'.getHelperVersion();
$this->logCompressorInDevelopment($image, $server);
$compressionCpuPercentage = $this->compressionCpuPercentage($server);
$this->logCompressorInDevelopment($image, $server, $compressionCpuPercentage);
$verifySourceCommand = $target instanceof LocalPersistentVolume && blank($target->host_path)
? 'docker volume inspect '.escapeshellarg($source).' >/dev/null'
: 'test -d '.escapeshellarg($source);
$archiveScript = "compressor='gzip -3'; "
.'if command -v pigz >/dev/null 2>&1; then compressor="pigz -3 -p $(( ($(nproc) + 1) / 2 ))"; fi; '
."if command -v pigz >/dev/null 2>&1; then compressor=\"pigz -3 -p \$(( (\$(nproc) * {$compressionCpuPercentage} + 99) / 100 ))\"; fi; "
.'tar -I "$compressor" -cf - -C /volume .';
$archiveCommand = 'docker run --rm --name '.escapeshellarg($containerName)
.' -v '.escapeshellarg($source.':/volume:ro')
@@ -337,13 +338,13 @@ class VolumeBackupJob implements ShouldBeEncrypted, ShouldQueue
}
}
private function logCompressorInDevelopment(string $image, Server $server): void
private function logCompressorInDevelopment(string $image, Server $server, int $compressionCpuPercentage): void
{
if (! isDev()) {
return;
}
$script = "if command -v pigz >/dev/null 2>&1; then printf 'pigz -3 -p %s' \"$(( ($(nproc) + 1) / 2 ))\"; else printf 'gzip -3'; fi";
$script = "if command -v pigz >/dev/null 2>&1; then printf 'pigz -3 -p %s' \"\$(( (\$(nproc) * {$compressionCpuPercentage} + 99) / 100 ))\"; else printf 'gzip -3'; fi";
$compressor = instant_remote_process(
['docker run --rm '.escapeshellarg($image).' sh -c '.escapeshellarg($script)],
$server,
@@ -356,9 +357,17 @@ class VolumeBackupJob implements ShouldBeEncrypted, ShouldQueue
'execution_id' => $this->execution?->id,
'compressor' => $compressor,
'helper_image' => $image,
'cpu_percentage' => $compressionCpuPercentage,
]);
}
private function compressionCpuPercentage(Server $server): int
{
$percentage = (int) ($server->settings->backup_compression_cpu_percentage ?? 25);
return in_array($percentage, [25, 50, 75, 100], true) ? $percentage : 25;
}
private function removeExpiredBackups(Server $server): void
{
if ($this->hasRetentionLimits(