/** * Create Backup * * @return $this */ public function execute() { 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(); $this->_logger->info($e->getMessage()); $this->_logger->critical($e); } if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) { $this->maintenanceMode->set(false); } return $this; }
/** * Create Backup * * @return \Magento\Log\Model\Cron */ public function scheduledBackup() { 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->turnOn(); } $type = $this->_scopeConfig->getValue(self::XML_PATH_BACKUP_TYPE, ScopeInterface::SCOPE_STORE); $this->_errors = array(); 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->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR))->addIgnorePaths($this->_backupData->getBackupIgnorePaths()); } $backupManager->create(); $message = $this->_backupData->getCreateSuccessMessageByType($type); $this->_logger->log($message); } catch (\Exception $e) { $this->_errors[] = $e->getMessage(); $this->_errors[] = $e->getTrace(); $this->_logger->log($e->getMessage(), \Zend_Log::ERR); $this->_logger->logException($e); } if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) { $this->maintenanceMode->turnOff(); } return $this; }
public function testGetBackupIgnorePaths() { $this->assertEquals(['.git', '.svn', MaintenanceMode::FLAG_DIR . '/' . MaintenanceMode::FLAG_FILENAME, DirectoryList::SESSION, DirectoryList::CACHE, DirectoryList::LOG, DirectoryList::VAR_DIR . '/full_page_cache', DirectoryList::VAR_DIR . '/locks', DirectoryList::VAR_DIR . '/report'], $this->helper->getBackupIgnorePaths()); }
public function testGetBackupIgnorePaths() { $this->filesystem->expects($this->any())->method('getPath')->will($this->returnValueMap([[MaintenanceMode::FLAG_DIR, MaintenanceMode::FLAG_DIR], [Filesystem::SESSION_DIR, Filesystem::SESSION_DIR], [Filesystem::CACHE_DIR, Filesystem::CACHE_DIR], [Filesystem::LOG_DIR, Filesystem::LOG_DIR], [Filesystem::VAR_DIR, Filesystem::VAR_DIR]])); $this->assertEquals(['.git', '.svn', 'var/maintenance.flag', Filesystem::SESSION_DIR, Filesystem::CACHE_DIR, Filesystem::LOG_DIR, Filesystem::VAR_DIR . '/full_page_cache', Filesystem::VAR_DIR . '/locks', Filesystem::VAR_DIR . '/report'], $this->helper->getBackupIgnorePaths()); }