_backupData = $backupData; $this->_coreRegistry = $coreRegistry; $this->_logger = $logger; $this->_scopeConfig = $scopeConfig; $this->_filesystem = $filesystem; $this->_backupFactory = $backupFactory; $this->maintenanceMode = $maintenanceMode; } /** * Create Backup * * @return $this * @throws \Exception */ public function execute() { if (!$this->_backupData->isEnabled()) { return $this; } if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) { return $this; } if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) { $this->maintenanceMode->set(true); } $type = $this->_scopeConfig->getValue(self::XML_PATH_BACKUP_TYPE, ScopeInterface::SCOPE_STORE); $this->_errors = []; try { $backupManager = $this->_backupFactory->create( $type )->setBackupExtension( $this->_backupData->getExtensionByType($type) )->setTime( time() )->setBackupsDir( $this->_backupData->getBackupsDir() ); $this->_coreRegistry->register('backup_manager', $backupManager); if ($type != \Magento\Framework\Backup\Factory::TYPE_DB) { $backupManager->setRootDir( $this->_filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath() )->addIgnorePaths( $this->_backupData->getBackupIgnorePaths() ); } $backupManager->create(); $message = $this->_backupData->getCreateSuccessMessageByType($type); $this->_logger->info($message); } catch (\Exception $e) { $this->_errors[] = $e->getMessage(); $this->_errors[] = $e->getTrace(); throw $e; } if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) { $this->maintenanceMode->set(false); } return $this; } }