/** * @param array $tables * @param $mysqldump * * @return Symfony_Process_ProcessBuilder */ protected function createProcessBuilder(array $tables, $mysqldump) { $processBuilder = Symfony_Process_ProcessBuilder::create()->setWorkingDirectory(untrailingslashit(ABSPATH))->setTimeout(3600)->setPrefix($mysqldump)->add('--force')->add('--user='******'--password='******'--add-drop-table'); if ($this->options->isSkipLockTables()) { // Don't lock all tables for read. $processBuilder->add('--lock-tables=false'); } if ($this->options->isSkipExtendedInsert()) { $processBuilder->add('--extended-insert=false'); } $processBuilder->add($this->configuration->getDatabase()); // Dump only specific tables foreach ($tables as $table) { $processBuilder->add($table); } if ($this->configuration->isSocket()) { $processBuilder->add('--socket=' . $this->configuration->getSocketPath()); } else { $processBuilder->add('--host=' . $this->configuration->getHost()); if (($port = $this->configuration->getPort()) !== null) { $processBuilder->add('--port=' . $port); } } return $processBuilder; }
/** * {@inheritdoc} */ public function createStream(array $tables = array()) { if ($this->environment->isPdoEnabled()) { $connection = new MWP_IncrementalBackup_Database_PdoConnection($this->configuration); } elseif ($this->environment->isMysqliEnabled()) { $connection = new MWP_IncrementalBackup_Database_MysqliConnection($this->configuration); } elseif ($this->environment->isMysqlEnabled()) { $connection = new MWP_IncrementalBackup_Database_MysqlConnection($this->configuration); } else { throw new MWP_IncrementalBackup_Database_Exception_ConnectionException("No mysql drivers available."); } $this->options->setTables($tables); $dumper = new MWP_IncrementalBackup_Database_StreamableQuerySequenceDump($connection, $this->options); return $dumper->createStream(); }
private function createConnection() { $connectionMethods = $this->options->getConnectionMethods(); if (!empty($connectionMethods) && is_array($connectionMethods)) { $this->getPreferredConnection($connectionMethods); if ($this->connection !== null) { return $this->connection; } } if ($this->environment->isPdoEnabled()) { $this->connection = new MWP_IncrementalBackup_Database_PdoConnection($this->configuration); } elseif ($this->environment->isMysqliEnabled()) { $this->connection = new MWP_IncrementalBackup_Database_MysqliConnection($this->configuration); } elseif ($this->environment->isMysqlEnabled()) { $this->connection = new MWP_IncrementalBackup_Database_MysqlConnection($this->configuration); } else { throw new MWP_IncrementalBackup_Database_Exception_ConnectionException("No mysql drivers available."); } return $this->connection; }
public function createExportTableStream($length, $tableName) { $stream = new MWP_Stream_Append(); $columns = $this->getConnection()->query("SHOW COLUMNS IN `{$tableName}`;")->fetchAll(); if (is_array($columns)) { $columns = $this->repack($columns, 'Field'); } $query = $this->selectAllDataQuery($tableName, $columns); $statement = $this->getConnection()->query($query, true); // Go through row by row if (!$this->options->isSkipLockTables()) { $stream->addStream(MWP_Stream_Stream::factory("LOCK TABLES `{$tableName}` WRITE;\n")); } $stream->addStream(MWP_Stream_Stream::factory("/*!40000 ALTER TABLE `{$tableName}` DISABLE KEYS */;\n")); $stream->addStream(new MWP_Stream_Callable(array($this, 'createExportRowStream'), array($statement, $tableName, $columns))); $stream->addStream(MWP_Stream_Stream::factory("\n")); $stream->addStream(MWP_Stream_Stream::factory("/*!40000 ALTER TABLE `{$tableName}` ENABLE KEYS */;\n")); if (!$this->options->isSkipLockTables()) { $stream->addStream(MWP_Stream_Stream::factory("UNLOCK TABLES;\n")); } return $stream; }
/** * @param string $method * * @param array $options * * @throws MWP_Worker_Exception * @return MWP_IncrementalBackup_Database_DumperInterface */ protected function createDumper($method, array $options = array()) { $dumperOptions = MWP_IncrementalBackup_Database_DumpOptions::createFromArray($options); switch ($method) { case self::METHOD_MYSQLDUMP: $configuration = MWP_IncrementalBackup_Database_Configuration::createFromWordPressContext(mwp_context()); $dumper = new MWP_IncrementalBackup_Database_MysqlDumpDumper($configuration, $dumperOptions); return $dumper; case self::METHOD_PHPDUMPER: $configuration = MWP_IncrementalBackup_Database_Configuration::createFromWordPressContext(mwp_context()); $dumper = new MWP_IncrementalBackup_Database_PhpDumper($configuration, mwp_container()->getSystemEnvironment(), $dumperOptions); return $dumper; default: throw new MWP_Worker_Exception(MWP_Worker_Exception::BACKUP_DATABASE_METHOD_NOT_AVAILABLE); break; } }