Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't limit size when using OpenSSL password crypt #373

Merged
merged 4 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Backup/Crypter/OpenSSL.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function crypt(Target $target, Result $result)

$result->warn($name . ': The ' . $this->algorithm . ' algorithm is considered weak');
}
if ($target->getSize() > 1610612736) {
if (!empty($this->certFile) && $target->getSize() > 1610612736) {
throw new Exception('Backup to big to encrypt: OpenSSL SMIME can only encrypt files smaller 1.5GB.');
}
parent::crypt($target, $result);
Expand Down
3 changes: 2 additions & 1 deletion src/Backup/Target/Compression/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class Factory
'gzip' => 'Gzip',
'bzip2' => 'Bzip2',
'xz' => 'Xz',
'zip' => 'Zip'
'zip' => 'Zip',
'zstd' => 'Zstd'
];

/**
Expand Down
44 changes: 44 additions & 0 deletions src/Backup/Target/Compression/Zstd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace phpbu\App\Backup\Target\Compression;

/**
* Zstd
*
* @package phpbu
* @subpackage Backup
* @author Sebastian Feldmann <[email protected]>
* @copyright Sebastian Feldmann <[email protected]>
* @license https://opensource.org/licenses/MIT The MIT License (MIT)
* @link http://phpbu.de/
* @since Class available since Release 3.2.1
*/
class Zstd extends Abstraction
{
/**
* Command name
*
* @var string
*/
protected $cmd = 'zstd';

/**
* Suffix for compressed files
*
* @var string
*/
protected $suffix = 'zst';

/**
* MIME type for compressed files
*
* @var string
*/
protected $mimeType = 'application/zstd';

/**
* Can this compression compress piped output
*
* @var bool
*/
protected $pipeable = true;
}
17 changes: 11 additions & 6 deletions src/Cli/Executable/Tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ class Tar extends Abstraction implements Executable
* @var array
*/
private static $availableCompressions = [
'bzip2' => 'j',
'gzip' => 'z',
'xz' => 'J'
'bzip2',
'gzip',
'xz',
'zstd'
];

/**
Expand Down Expand Up @@ -142,7 +143,7 @@ public function __construct(string $path = '')
*/
protected function getCompressionOption(string $compressor) : string
{
return $this->isCompressionValid($compressor) ? self::$availableCompressions[$compressor] : '';
return $this->isCompressionValid($compressor) ? $compressor : '';
}

/**
Expand Down Expand Up @@ -323,7 +324,11 @@ protected function createCommandLine() : CommandLine
$tar->addOptionIfNotEmpty('-h', $this->dereference, false);
$tar->addOptionIfNotEmpty('--force-local', $this->local, false);
$tar->addOptionIfNotEmpty('--use-compress-program', $this->compressProgram);
$tar->addOption('-' . (empty($this->compressProgram) ? $this->compression : '') . $create);
if ($this->compression && empty($this->compressProgram)) {
$tar->addOption('--' . $this->compression);
}
$tar->addOption('-' . $create);


if ($this->isThrottled()) {
$pv = new Cmd('pv');
Expand Down Expand Up @@ -452,7 +457,7 @@ private function validateSetup()
*/
public static function isCompressionValid(string $compression) : bool
{
return isset(self::$availableCompressions[$compression]);
return in_array($compression, self::$availableCompressions);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpbu/Backup/Source/TarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public function testCompressedTarget()
$exec = $tar->getExecutable($target);

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/tar" -zcf \'/tmp/backup.tar.gz\' -C \''
'"' . PHPBU_TEST_BIN . '/tar" --gzip -cf \'/tmp/backup.tar.gz\' -C \''
. dirname(__DIR__) . '\' \''
. basename(__DIR__) . '\'',
$exec->getCommand()
Expand Down
8 changes: 4 additions & 4 deletions tests/phpbu/Cli/Executable/TarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function testCompressionGzip()
$tar->archiveDirectory($dir)->archiveTo('/tmp/foo.tar.gz')->useCompression('gzip');

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/tar" -zcf \'/tmp/foo.tar.gz\' -C \'' . $tarC . '\' \'' . $tarD . '\'',
'"' . PHPBU_TEST_BIN . '/tar" --gzip -cf \'/tmp/foo.tar.gz\' -C \'' . $tarC . '\' \'' . $tarD . '\'',
$tar->getCommand()
);
}
Expand All @@ -196,7 +196,7 @@ public function testCompressionBzip2()
$tar->archiveDirectory($dir)->archiveTo('/tmp/foo.tar.bzip2')->useCompression('bzip2');

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/tar" -jcf \'/tmp/foo.tar.bzip2\' -C \'' . $tarC . '\' \'' . $tarD . '\'',
'"' . PHPBU_TEST_BIN . '/tar" --bzip2 -cf \'/tmp/foo.tar.bzip2\' -C \'' . $tarC . '\' \'' . $tarD . '\'',
$tar->getCommand()
);
}
Expand All @@ -216,7 +216,7 @@ public function testThrottle()
->throttle('1m');

$this->assertEquals(
'"' . PHPBU_TEST_BIN . '/tar" -jc -C \'' . $tarC . '\' \'' . $tarD . '\''
'"' . PHPBU_TEST_BIN . '/tar" --bzip2 -c -C \'' . $tarC . '\' \'' . $tarD . '\''
. ' | "pv" -qL \'1m\' > /tmp/foo.tar.bzip2',
$tar->getCommand()
);
Expand All @@ -238,7 +238,7 @@ public function testThrottleAndRemoveSourceDir()
->throttle('1m');

$this->assertEquals(
'("' . PHPBU_TEST_BIN . '/tar" -jc -C \'' . $tarC . '\' \'' . $tarD . '\''
'("' . PHPBU_TEST_BIN . '/tar" --bzip2 -c -C \'' . $tarC . '\' \'' . $tarD . '\''
. ' && "rm" -rf \'' . $dir . '\')'
. ' | "pv" -qL \'1m\' > /tmp/foo.tar.bzip2',
$tar->getCommand()
Expand Down