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): stop mc pipe panic in S3-only volume backups

Andras Bacsai0236d32d283b
diff --git a/app/Jobs/VolumeBackupJob.php b/app/Jobs/VolumeBackupJob.php
index aa34999397..6d39ce6b42 100644
--- a/app/Jobs/VolumeBackupJob.php
+++ b/app/Jobs/VolumeBackupJob.php
@@ -407,9 +407,13 @@ class VolumeBackupJob implements ShouldBeEncrypted, ShouldQueue
->implode(' ');
$resolveOptions = $resolveOptions === '' ? '' : ' '.$resolveOptions;
$destination = 'temporary/'.$s3->bucket.$backupLocation;
+ // `mc pipe --quiet` panics in recent mc releases, so keep its progress bar out of the error output instead.
+ // Each progress frame starts with "\r", so printing the last field per line keeps only the final frame and real errors.
+ $mcPipeLog = '/tmp/mc-pipe.log';
$streamScript = 'set -o pipefail; mc alias set'.$resolveOptions.' temporary '
.escapeshellarg($s3->endpoint).' '.escapeshellarg($s3->key).' '.escapeshellarg($s3->secret)
- .' >/dev/null && ('.$archiveScript.' | mc pipe --quiet'.$resolveOptions.' '.escapeshellarg($destination).' >/dev/null)'
+ .' >/dev/null && ('.$archiveScript.' | mc pipe'.$resolveOptions.' '.escapeshellarg($destination).' >/dev/null 2>'.$mcPipeLog
+ .' || { status=$?; awk -F '.escapeshellarg('\r').' '.escapeshellarg('{ print $NF }').' '.$mcPipeLog.' >&2; exit $status; })'
.' && mc stat --json'.$resolveOptions.' '.escapeshellarg($destination)
.' | sed -n '.escapeshellarg('s/.*"size":\([0-9][0-9]*\).*/\1/p');
diff --git a/tests/Feature/VolumeBackupTest.php b/tests/Feature/VolumeBackupTest.php
index 799e067d3f..3eebee1e34 100644
--- a/tests/Feature/VolumeBackupTest.php
+++ b/tests/Feature/VolumeBackupTest.php
@@ -2023,8 +2023,10 @@ it('streams S3-only volume backups without creating or copying a local archive',
$expectedFilename = 'volume-app-data-1786795200.tar.gz';
Process::assertRan(fn ($process) => str_contains($process->command, 'tar -I')
&& str_contains($process->command, 'mc pipe')
+ && ! str_contains($process->command, '--quiet')
&& str_contains($process->command, '>/dev/null && (compressor=')
- && str_contains($process->command, '>/dev/null) && mc stat')
+ && str_contains($process->command, '>/dev/null 2>/tmp/mc-pipe.log || {')
+ && str_contains($process->command, '/tmp/mc-pipe.log >&2; exit $status; }) && mc stat')
&& str_contains($process->command, 'temporary/bucket/')
&& str_contains($process->command, $expectedFilename)
&& substr_count($process->command, '--resolve') === 3