/** * Files rollback implementation via ftp * * @see Mage_Backup_Filesystem_Rollback_Abstract::run() * @throws Mage_Exception */ public function run() { $snapshotPath = $this->_snapshot->getBackupPath(); if (!is_file($snapshotPath) || !is_readable($snapshotPath)) { throw new Mage_Backup_Exception_CantLoadSnapshot('Cant load snapshot archive'); } $this->_initFtpClient(); $this->_validateFtp(); $tmpDir = $this->_createTmpDir(); $this->_unpackSnapshot($tmpDir); $fsHelper = new Mage_Backup_Filesystem_Helper(); $this->_cleanupFtp(); $this->_uploadBackupToFtp($tmpDir); $fsHelper->rm($tmpDir, array(), true); }
/** * Files rollback implementation via local filesystem * * @see Mage_Backup_Filesystem_Rollback_Abstract::run() * @throws Mage_Exception */ public function run() { $snapshotPath = $this->_snapshot->getBackupPath(); if (!is_file($snapshotPath) || !is_readable($snapshotPath)) { throw new Mage_Backup_Exception_CantLoadSnapshot('Cant load snapshot archive'); } $fsHelper = new Mage_Backup_Filesystem_Helper(); $filesInfo = $fsHelper->getInfo($this->_snapshot->getRootDir(), Mage_Backup_Filesystem_Helper::INFO_WRITABLE, $this->_snapshot->getIgnorePaths()); if (!$filesInfo['writable']) { throw new Mage_Backup_Exception_NotEnoughPermissions('Unable to make rollback because not all files are writable'); } $archiver = new Mage_Archive(); /** * we need these fake initializations because all magento's files in filesystem will be deleted and autoloader * wont be able to load classes that we need for unpacking */ new Mage_Archive_Tar(); new Mage_Archive_Gz(); new Mage_Archive_Helper_File(''); new Mage_Archive_Helper_File_Gz(''); $fsHelper->rm($this->_snapshot->getRootDir(), $this->_snapshot->getIgnorePaths()); $archiver->unpack($snapshotPath, $this->_snapshot->getRootDir()); }
/** * Implementation Create Backup functionality for Filesystem * * @throws Mage_Exception * @return boolean */ public function create() { set_time_limit(0); ignore_user_abort(true); $this->_lastOperationSucceed = false; $this->_checkBackupsDir(); $fsHelper = new Mage_Backup_Filesystem_Helper(); $filesInfo = $fsHelper->getInfo($this->getRootDir(), Mage_Backup_Filesystem_Helper::INFO_READABLE | Mage_Backup_Filesystem_Helper::INFO_SIZE, $this->getIgnorePaths()); if (!$filesInfo['readable']) { throw new Mage_Backup_Exception_NotEnoughPermissions('Not enough permissions to read files for backup'); } $freeSpace = disk_free_space($this->getBackupsDir()); if (2 * $filesInfo['size'] > $freeSpace) { throw new Mage_Backup_Exception_NotEnoughFreeSpace('Not enough free space to create backup'); } $tarTmpPath = $this->_getTarTmpPath(); $tarPacker = new Mage_Backup_Archive_Tar(); $tarPacker->setSkipFiles($this->getIgnorePaths())->pack($this->getRootDir(), $tarTmpPath, true); if (!is_file($tarTmpPath) || filesize($tarTmpPath) == 0) { throw new Mage_Exception('Failed to create backup'); } $backupPath = $this->getBackupPath(); $gzPacker = new Mage_Archive_Gz(); $gzPacker->pack($tarTmpPath, $backupPath); if (!is_file($backupPath) || filesize($backupPath) == 0) { throw new Mage_Exception('Failed to create backup'); } @unlink($tarTmpPath); $this->_lastOperationSucceed = true; }