/**
  * Create Backup
  *
  * @return Mage_Log_Model_Cron
  */
 public function scheduledBackup()
 {
     if (!Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_ENABLED)) {
         return $this;
     }
     if (Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE)) {
         Mage::helper('backup')->turnOnMaintenanceMode();
     }
     $type = Mage::getStoreConfig(self::XML_PATH_BACKUP_TYPE);
     $this->_errors = array();
     try {
         $backupManager = Mage_Backup::getBackupInstance($type)->setBackupExtension(Mage::helper('backup')->getExtensionByType($type))->setTime(time())->setBackupsDir(Mage::helper('backup')->getBackupsDir());
         Mage::register('backup_manager', $backupManager);
         if ($type != Mage_Backup_Helper_Data::TYPE_DB) {
             $backupManager->setRootDir(Mage::getBaseDir())->addIgnorePaths(Mage::helper('backup')->getBackupIgnorePaths());
         }
         $backupManager->create();
         Mage::log(Mage::helper('backup')->getCreateSuccessMessageByType($type));
     } catch (Exception $e) {
         $this->_errors[] = $e->getMessage();
         $this->_errors[] = $e->getTrace();
         Mage::log($e->getMessage(), Zend_Log::ERR);
         Mage::logException($e);
     }
     if (Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE)) {
         Mage::helper('backup')->turnOffMaintenanceMode();
     }
     return $this;
 }
 /**
  * Create Backup
  *
  * @param string $archiveType
  * @param string $archiveName
  * @return bool
  */
 protected function _createBackup($archiveType, $archiveName)
 {
     /** @var $connect Maged_Connect */
     $connect = $this->model('connect', true)->connect();
     $connect->runHtmlConsole('Creating backup...');
     $isSuccess = false;
     try {
         $type = $this->_getBackupTypeByCode($archiveType);
         $backupManager = Mage_Backup::getBackupInstance($type)->setBackupExtension(Mage::helper('backup')->getExtensionByType($type))->setTime(time())->setName($archiveName)->setBackupsDir(Mage::helper('backup')->getBackupsDir());
         Mage::register('backup_manager', $backupManager);
         if ($type != Mage_Backup_Helper_Data::TYPE_DB) {
             $backupManager->setRootDir(Mage::getBaseDir())->addIgnorePaths(Mage::helper('backup')->getBackupIgnorePaths());
         }
         $backupManager->create();
         $connect->runHtmlConsole($this->_getCreateBackupSuccessMessageByType($type));
         $isSuccess = true;
     } catch (Mage_Backup_Exception_NotEnoughFreeSpace $e) {
         $connect->runHtmlConsole('Not enough free space to create backup.');
         Mage::logException($e);
     } catch (Mage_Backup_Exception_NotEnoughPermissions $e) {
         $connect->runHtmlConsole('Not enough permissions to create backup.');
         Mage::logException($e);
     } catch (Exception $e) {
         $connect->runHtmlConsole('An error occurred while creating the backup.');
         Mage::logException($e);
     }
     return $isSuccess;
 }
Beispiel #3
0
 /**
  * Create Db Instance
  *
  * @return Mage_Backup_Interface
  */
 protected function _createDbBackupInstance()
 {
     return Mage_Backup::getBackupInstance(Mage_Backup_Helper_Data::TYPE_DB)->setBackupExtension(Mage::helper('Mage_Backup_Helper_Data')->getExtensionByType(Mage_Backup_Helper_Data::TYPE_DB))->setTime($this->getTime())->setBackupsDir(Mage::getBaseDir("var"))->setResourceModel($this->getResourceModel());
 }
 /**
  * Rollback Action
  *
  * @return Mage_Adminhtml_Controller_Action
  */
 public function rollbackAction()
 {
     if (!Mage::helper('backup')->isRollbackAllowed()) {
         return $this->_forward('denied');
     }
     if (!$this->getRequest()->isAjax()) {
         return $this->getUrl('*/*/index');
     }
     $helper = Mage::helper('backup');
     $response = new Varien_Object();
     try {
         /* @var $backup Mage_Backup_Model_Backup */
         $backup = Mage::getModel('backup/backup')->loadByTimeAndType($this->getRequest()->getParam('time'), $this->getRequest()->getParam('type'));
         if (!$backup->getTime() || !$backup->exists()) {
             return $this->_redirect('*/*');
         }
         if (!$backup->getTime()) {
             throw new Mage_Backup_Exception_CantLoadSnapshot();
         }
         $type = $backup->getType();
         $backupManager = Mage_Backup::getBackupInstance($type)->setBackupExtension($helper->getExtensionByType($type))->setTime($backup->getTime())->setBackupsDir($helper->getBackupsDir())->setName($backup->getName(), false)->setResourceModel(Mage::getResourceModel('backup/db'));
         Mage::register('backup_manager', $backupManager);
         $passwordValid = Mage::getModel('backup/backup')->validateUserPassword($this->getRequest()->getParam('password'));
         if (!$passwordValid) {
             $response->setError(Mage::helper('backup')->__('Invalid Password.'));
             $backupManager->setErrorMessage(Mage::helper('backup')->__('Invalid Password.'));
             return $this->getResponse()->setBody($response->toJson());
         }
         if ($this->getRequest()->getParam('maintenance_mode')) {
             $turnedOn = $helper->turnOnMaintenanceMode();
             if (!$turnedOn) {
                 $response->setError(Mage::helper('backup')->__('You do not have sufficient permissions to enable Maintenance Mode during this operation.') . ' ' . Mage::helper('backup')->__('Please either unselect the "Put store on the maintenance mode" checkbox or update your permissions to proceed with the rollback."'));
                 $backupManager->setErrorMessage(Mage::helper('backup')->__("System couldn't put store on the maintenance mode"));
                 return $this->getResponse()->setBody($response->toJson());
             }
         }
         if ($type != Mage_Backup_Helper_Data::TYPE_DB) {
             $backupManager->setRootDir(Mage::getBaseDir())->addIgnorePaths($helper->getRollbackIgnorePaths());
             if ($this->getRequest()->getParam('use_ftp', false)) {
                 $backupManager->setUseFtp($this->getRequest()->getParam('ftp_host', ''), $this->getRequest()->getParam('ftp_user', ''), $this->getRequest()->getParam('ftp_pass', ''), $this->getRequest()->getParam('ftp_path', ''));
             }
         }
         $backupManager->rollback();
         $helper->invalidateCache()->invalidateIndexer();
         $adminSession = $this->_getSession();
         $adminSession->unsetAll();
         $adminSession->getCookie()->delete($adminSession->getSessionName());
         $response->setRedirectUrl($this->getUrl('*'));
     } catch (Mage_Backup_Exception_CantLoadSnapshot $e) {
         $errorMsg = Mage::helper('backup')->__('Backup file not found');
     } catch (Mage_Backup_Exception_FtpConnectionFailed $e) {
         $errorMsg = Mage::helper('backup')->__('Failed to connect to FTP');
     } catch (Mage_Backup_Exception_FtpValidationFailed $e) {
         $errorMsg = Mage::helper('backup')->__('Failed to validate FTP');
     } catch (Mage_Backup_Exception_NotEnoughPermissions $e) {
         Mage::log($e->getMessage());
         $errorMsg = Mage::helper('backup')->__('Not enough permissions to perform rollback');
     } catch (Exception $e) {
         Mage::log($e->getMessage());
         $errorMsg = Mage::helper('backup')->__('Failed to rollback');
     }
     if (!empty($errorMsg)) {
         $response->setError($errorMsg);
         $backupManager->setErrorMessage($errorMsg);
     }
     if ($this->getRequest()->getParam('maintenance_mode')) {
         $helper->turnOffMaintenanceMode();
     }
     $this->getResponse()->setBody($response->toJson());
 }