Skip to content
Open
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
35 changes: 28 additions & 7 deletions src/Command/Backup/BackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __invoke(?string $filename, InputInterface $input)
// Make a new directory to back up in
$backupDirectory = Platform::tempDirectory(true);
/** @var string $directory */
$directory = $input->getOption('dir');
$directory = rtrim($input->getOption('dir'), '/');

if (!file_exists($directory)) {
mkdir($directory, 0777, true);
Expand Down Expand Up @@ -333,15 +333,36 @@ protected function compressDirectory(string $directory, string $outputDirectory,

$this->output->writeln(sprintf('Compressing directory: %s', $outputFile));

$build = new PharData($outputDirectory . '/' . $outputFile . '.tar', 0);
$build->buildFromDirectory($directory);
$compressed = $build->compress(Phar::GZ);
if (Phar::running() !== '') {
$build = new PharData($outputDirectory . '/' . $outputFile . '.tar', 0);
$build->buildFromDirectory($directory);
$compressed = $build->compress(Phar::GZ);

// Get rid of the uncompressed version
unlink($build->getPath());
// Get rid of the uncompressed version
unlink($build->getPath());

$compressedFile = $compressed->getPath();
} else {
$tarProcess = new Process(
[
'tar',
'-zcf',
$outputDirectory . '/' . $outputFile . '.tar.gz',
$directory
]
);
$tarProcess->setTimeout(null);
$tarProcess->run();

if (!$tarProcess->isSuccessful()) {
throw new \Exception($tarProcess->getErrorOutput());
}

$compressedFile = $outputDirectory . '/' . $outputFile . '.tar.gz';
}

$this->output->writeln(['<fg=green>', 'Successfully created backup file at:<fg=cyan>']);
$this->output->writeln($compressed->getPath(), OutputInterface::VERBOSITY_QUIET);
$this->output->writeln($compressedFile, OutputInterface::VERBOSITY_QUIET);
$this->output->writeln('</>');

if ($disablePhar && in_array('phar', stream_get_wrappers(), true)) {
Expand Down