diff --git a/src/Backup/Crypter/OpenSSL.php b/src/Backup/Crypter/OpenSSL.php index dd88d735..1f446a27 100644 --- a/src/Backup/Crypter/OpenSSL.php +++ b/src/Backup/Crypter/OpenSSL.php @@ -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); diff --git a/src/Backup/Target/Compression/Factory.php b/src/Backup/Target/Compression/Factory.php index 231e4ce7..eb9f92d0 100644 --- a/src/Backup/Target/Compression/Factory.php +++ b/src/Backup/Target/Compression/Factory.php @@ -25,7 +25,8 @@ class Factory 'gzip' => 'Gzip', 'bzip2' => 'Bzip2', 'xz' => 'Xz', - 'zip' => 'Zip' + 'zip' => 'Zip', + 'zstd' => 'Zstd' ]; /** diff --git a/src/Backup/Target/Compression/Zstd.php b/src/Backup/Target/Compression/Zstd.php new file mode 100644 index 00000000..06a381ee --- /dev/null +++ b/src/Backup/Target/Compression/Zstd.php @@ -0,0 +1,44 @@ + + * @copyright Sebastian Feldmann + * @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; +} diff --git a/src/Cli/Executable/Tar.php b/src/Cli/Executable/Tar.php index 31d228ab..6e282df5 100644 --- a/src/Cli/Executable/Tar.php +++ b/src/Cli/Executable/Tar.php @@ -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' ]; /** @@ -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 : ''; } /** @@ -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'); @@ -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); } /** diff --git a/tests/phpbu/Backup/Source/TarTest.php b/tests/phpbu/Backup/Source/TarTest.php index 2ce0b3b7..8e1c908b 100644 --- a/tests/phpbu/Backup/Source/TarTest.php +++ b/tests/phpbu/Backup/Source/TarTest.php @@ -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() diff --git a/tests/phpbu/Cli/Executable/TarTest.php b/tests/phpbu/Cli/Executable/TarTest.php index 6df09629..12f40e4e 100644 --- a/tests/phpbu/Cli/Executable/TarTest.php +++ b/tests/phpbu/Cli/Executable/TarTest.php @@ -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() ); } @@ -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() ); } @@ -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() ); @@ -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()