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(
@@ -151,6 +151,9 @@ class Show extends Component
refresh_server_connection($this->private_key);
$this->dispatch('success', 'Private key updated.');
$this->dispatch('securityResourceChanged');
if ($this->modalMode) {
$this->dispatch('close-modal');
}
} catch (\Throwable $e) {
return handleError($e, $this);
}
+5
View File
@@ -27,6 +27,9 @@ class Advanced extends Component
#[Validate(['required', 'integer', 'min:1'])]
public int|string $deploymentQueueLimit = 25;
#[Validate(['required', 'integer', 'in:25,50,75,100'])]
public int|string $backupCompressionCpuPercentage = 25;
public function mount(string $server_uuid)
{
try {
@@ -47,6 +50,7 @@ class Advanced extends Component
$this->server->settings->concurrent_builds = $this->concurrentBuilds;
$this->server->settings->dynamic_timeout = $this->dynamicTimeout;
$this->server->settings->deployment_queue_limit = $this->deploymentQueueLimit;
$this->server->settings->backup_compression_cpu_percentage = $this->backupCompressionCpuPercentage;
$this->server->settings->server_disk_usage_notification_threshold = $this->serverDiskUsageNotificationThreshold;
$this->server->settings->server_disk_usage_check_frequency = $this->serverDiskUsageCheckFrequency;
$this->server->settings->save();
@@ -54,6 +58,7 @@ class Advanced extends Component
$this->concurrentBuilds = $this->server->settings->concurrent_builds;
$this->dynamicTimeout = $this->server->settings->dynamic_timeout;
$this->deploymentQueueLimit = $this->server->settings->deployment_queue_limit;
$this->backupCompressionCpuPercentage = $this->server->settings->backup_compression_cpu_percentage;
$this->serverDiskUsageNotificationThreshold = $this->server->settings->server_disk_usage_notification_threshold;
$this->serverDiskUsageCheckFrequency = $this->server->settings->server_disk_usage_check_frequency;
}
+3
View File
@@ -15,6 +15,7 @@ use OpenApi\Attributes as OA;
'id' => ['type' => 'integer'],
'concurrent_builds' => ['type' => 'integer'],
'deployment_queue_limit' => ['type' => 'integer'],
'backup_compression_cpu_percentage' => ['type' => 'integer'],
'dynamic_timeout' => ['type' => 'integer'],
'force_disabled' => ['type' => 'boolean'],
'force_server_cleanup' => ['type' => 'boolean'],
@@ -102,6 +103,7 @@ class ServerSetting extends Model
'server_disk_usage_check_frequency',
'is_terminal_enabled',
'deployment_queue_limit',
'backup_compression_cpu_percentage',
'disable_application_image_retention',
'connection_timeout',
'docker_version',
@@ -123,6 +125,7 @@ class ServerSetting extends Model
'connection_timeout' => 'integer',
'docker_version_checked_at' => 'datetime',
'compose_version_checked_at' => 'datetime',
'backup_compression_cpu_percentage' => 'integer',
];
/**