|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / dev2.destoffenstraat.com / update / app / code / Magento / Update / |
Filename | /home/dev2.destoffenstraat.com/update/app/code/Magento/Update/Backup.php |
Size | 2.41 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 06-Apr-2021 18:06 |
Last accessed | 23-Aug-2025 03:55 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Update;
use Magento\Update\Backup\BackupInfo;
use Magento\Update\Status;
/**
* Class for creating Magento codebase backups.
*/
class Backup
{
/**
* @var BackupInfo
*/
protected $backupInfo;
/**
* @var Status
*/
protected $status;
/**
* Initialize dependencies.
*
* @param BackupInfo|null $backupInfo
* @param Status|null $status
*/
public function __construct(BackupInfo $backupInfo = null, Status $status = null)
{
$this->backupInfo = $backupInfo ? $backupInfo : new BackupInfo();
$this->status = $status ? $status : new Status();
}
/**
* Create backup archive using unix zip tool.
*
* @return $this
* @throws \RuntimeException
*/
public function execute()
{
$backupFilePath = $this->backupInfo->getBackupPath() . $this->backupInfo->generateBackupFilename();
$command = $this->buildShellCommand($backupFilePath);
$this->status->add(sprintf('Creating backup archive "%s" ...', $backupFilePath), \Psr\Log\LogLevel::INFO);
exec($command, $output, $return);
if ($return) {
throw new \RuntimeException(
sprintf('Cannot create backup with command "%s": %s', $command, implode("\n", $output),
\Psr\Log\LogLevel::ERROR
)
);
}
$this->status->add(sprintf('Backup archive "%s" has been created.', $backupFilePath), \Psr\Log\LogLevel::INFO);
return $this;
}
/**
* Construct shell command for creating backup archive.
*
* @param string $backupFilePath
* @return string
*/
protected function buildShellCommand($backupFilePath)
{
$excludedElements = '';
foreach ($this->backupInfo->getBlacklist() as $excludedElement) {
$elementPath = $excludedElement;
$fullPath = $this->backupInfo->getArchivedDirectory() . '/' . $elementPath;
$excludedElements .= is_dir($fullPath) ? $elementPath . '\* ' : $elementPath . ' ';
}
$changeDirectoryCommand = sprintf("cd %s", $this->backupInfo->getArchivedDirectory());
$zipCommand = sprintf("zip -r %s . -x %s", $backupFilePath, $excludedElements);
return $changeDirectoryCommand . ' && ' . $zipCommand;
}
}
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Update;
use Magento\Update\Backup\BackupInfo;
use Magento\Update\Status;
/**
* Class for creating Magento codebase backups.
*/
class Backup
{
/**
* @var BackupInfo
*/
protected $backupInfo;
/**
* @var Status
*/
protected $status;
/**
* Initialize dependencies.
*
* @param BackupInfo|null $backupInfo
* @param Status|null $status
*/
public function __construct(BackupInfo $backupInfo = null, Status $status = null)
{
$this->backupInfo = $backupInfo ? $backupInfo : new BackupInfo();
$this->status = $status ? $status : new Status();
}
/**
* Create backup archive using unix zip tool.
*
* @return $this
* @throws \RuntimeException
*/
public function execute()
{
$backupFilePath = $this->backupInfo->getBackupPath() . $this->backupInfo->generateBackupFilename();
$command = $this->buildShellCommand($backupFilePath);
$this->status->add(sprintf('Creating backup archive "%s" ...', $backupFilePath), \Psr\Log\LogLevel::INFO);
exec($command, $output, $return);
if ($return) {
throw new \RuntimeException(
sprintf('Cannot create backup with command "%s": %s', $command, implode("\n", $output),
\Psr\Log\LogLevel::ERROR
)
);
}
$this->status->add(sprintf('Backup archive "%s" has been created.', $backupFilePath), \Psr\Log\LogLevel::INFO);
return $this;
}
/**
* Construct shell command for creating backup archive.
*
* @param string $backupFilePath
* @return string
*/
protected function buildShellCommand($backupFilePath)
{
$excludedElements = '';
foreach ($this->backupInfo->getBlacklist() as $excludedElement) {
$elementPath = $excludedElement;
$fullPath = $this->backupInfo->getArchivedDirectory() . '/' . $elementPath;
$excludedElements .= is_dir($fullPath) ? $elementPath . '\* ' : $elementPath . ' ';
}
$changeDirectoryCommand = sprintf("cd %s", $this->backupInfo->getArchivedDirectory());
$zipCommand = sprintf("zip -r %s . -x %s", $backupFilePath, $excludedElements);
return $changeDirectoryCommand . ' && ' . $zipCommand;
}
}