mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-03 05:19:37 +00:00
feat(backups): use parallel gzip for volume backups
Add pigz to the helper image, select it when available with gzip fallback, and log the selected compressor in development.
This commit is contained in:
1 parent
fd5eb3e0cd
commit
b3aa1fd232
4 files changed
+77
-4
No files matched your search
@@ -77,14 +77,19 @@ class VolumeBackupJob implements ShouldBeEncrypted, ShouldQueue
|
||||
$source = $this->backup->sourcePath();
|
||||
$containerName = 'volume-backup-'.$this->execution->uuid;
|
||||
$image = coolifyHelperImage().':'.getHelperVersion();
|
||||
$this->logCompressorInDevelopment($image, $server);
|
||||
$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; '
|
||||
.'tar -I "$compressor" -cf - -C /volume .';
|
||||
$archiveCommand = 'docker run --rm --name '.escapeshellarg($containerName)
|
||||
.' -v '.escapeshellarg($source.':/volume:ro')
|
||||
.' '.escapeshellarg($image)
|
||||
." tar -I 'gzip -1' -cf - -C /volume . > ".escapeshellarg($backupLocation);
|
||||
.' sh -c '.escapeshellarg($archiveScript)
|
||||
.' > '.escapeshellarg($backupLocation);
|
||||
|
||||
if ($this->backup->stop_during_backup) {
|
||||
$containers = $this->containersUsingVolume($source, $server);
|
||||
@@ -332,6 +337,28 @@ class VolumeBackupJob implements ShouldBeEncrypted, ShouldQueue
|
||||
}
|
||||
}
|
||||
|
||||
private function logCompressorInDevelopment(string $image, Server $server): 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";
|
||||
$compressor = instant_remote_process(
|
||||
['docker run --rm '.escapeshellarg($image).' sh -c '.escapeshellarg($script)],
|
||||
$server,
|
||||
timeout: 60,
|
||||
disableMultiplexing: true,
|
||||
);
|
||||
|
||||
Log::info('Volume backup compressor selected', [
|
||||
'backup_id' => $this->backup->id,
|
||||
'execution_id' => $this->execution?->id,
|
||||
'compressor' => $compressor,
|
||||
'helper_image' => $image,
|
||||
]);
|
||||
}
|
||||
|
||||
private function removeExpiredBackups(Server $server): void
|
||||
{
|
||||
if ($this->hasRetentionLimits(
|
||||
|
||||
Reference in new issue
Block a user