Пример #1
0
 /**
  * Create backup using native mysqldump
  * 
  * Same signature as the core version.
  *
  * @param Mage_Backup_Model_Backup $backup
  * @return Mage_Backup_Model_Db
  */
 public function createBackup(Mage_Backup_Model_Backup $backup)
 {
     $db = Mage::getResourceModel('sales/order')->getReadConnection()->getConfig();
     $host = $db['host'];
     $user = $db['username'];
     $pass = $db['password'];
     $db = $db['dbname'];
     // Based on http://php.net/manual/en/function.system.php
     $cmd = sprintf('%smysqldump --opt -h %s -u %s -p%s %s | gzip > %s', $this->PATH_TO_MYSQLDUMP, $host, $user, $pass, $db, $backup->getPath() . DS . $backup->getFileName());
     Mage::log("Running native backup command: {$cmd}");
     system($cmd);
     Mage::log("Created backup natively");
 }
Пример #2
0
 /**
  * Generate backup download name
  *
  * @param Mage_Backup_Model_Backup $backup
  * @return string
  */
 public function generateBackupDownloadName(Mage_Backup_Model_Backup $backup)
 {
     $additionalExtension = $backup->getType() == self::TYPE_DB ? '.sql' : '';
     return $backup->getType() . '-' . date('YmdHis', $backup->getTime()) . $additionalExtension . '.' . $this->getExtensionByType($backup->getType());
 }
Пример #3
0
 /**
  * Create backup and stream write to adapter
  *
  * @param Mage_Backup_Model_Backup $backup
  * @return Mage_Backup_Model_Db
  */
 public function createBackup(Mage_Backup_Model_Backup $backup)
 {
     $backup->open(true);
     $this->getResource()->beginTransaction();
     $tables = $this->getResource()->getTables();
     $backup->write($this->getResource()->getHeader());
     $ignoreDataTablesList = $this->getIgnoreDataTablesList();
     foreach ($tables as $table) {
         $backup->write($this->getResource()->getTableHeader($table) . $this->getResource()->getTableDropSql($table) . "\n");
         $backup->write($this->getResource()->getTableCreateSql($table, false) . "\n");
         $tableStatus = $this->getResource()->getTableStatus($table);
         if ($tableStatus->getRows() && !in_array($table, $ignoreDataTablesList)) {
             $backup->write($this->getResource()->getTableDataBeforeSql($table));
             if ($tableStatus->getDataLength() > self::BUFFER_LENGTH) {
                 if ($tableStatus->getAvgRowLength() < self::BUFFER_LENGTH) {
                     $limit = floor(self::BUFFER_LENGTH / $tableStatus->getAvgRowLength());
                     $multiRowsLength = ceil($tableStatus->getRows() / $limit);
                 } else {
                     $limit = 1;
                     $multiRowsLength = $tableStatus->getRows();
                 }
             } else {
                 $limit = $tableStatus->getRows();
                 $multiRowsLength = 1;
             }
             for ($i = 0; $i < $multiRowsLength; $i++) {
                 $backup->write($this->getResource()->getTableDataSql($table, $limit, $i * $limit));
             }
             $backup->write($this->getResource()->getTableDataAfterSql($table));
         }
     }
     $backup->write($this->getResource()->getTableForeignKeysSql());
     $backup->write($this->getResource()->getFooter());
     $this->getResource()->commitTransaction();
     $backup->close();
     return $this;
 }