예제 #1
0
 /**
  * Backup current DB to file local/backup/update.sql
  * @return bool if it succeeds, false otherwise
  * @throws \Exception
  */
 public function backupDb()
 {
     $database = new Database($this->connection);
     if (!$this->checkBackupIsPossible()) {
         $message = 'Your database is too big for an automatic backup';
         $this->log('error', $message);
         throw new UpdateException($message);
     }
     $this->backupFile = THELIA_ROOT . $this->backupDir . 'update.sql';
     $backupDir = THELIA_ROOT . $this->backupDir;
     $fs = new Filesystem();
     try {
         $this->log('debug', sprintf('Backup database to file : %s', $this->backupFile));
         // test if backup dir exists
         if (!$fs->exists($backupDir)) {
             $fs->mkdir($backupDir);
         }
         if (!is_writable($backupDir)) {
             throw new \RuntimeException(sprintf('impossible to write in directory : %s', $backupDir));
         }
         // test if backup file already exists
         if ($fs->exists($this->backupFile)) {
             // remove file
             $fs->remove($this->backupFile);
         }
         $database->backupDb($this->backupFile);
     } catch (\Exception $ex) {
         $this->log('error', sprintf('error during backup process with message : %s', $ex->getMessage()));
         throw $ex;
     }
 }