You are here

function backup_migrate_destination_db_mysql::_backup_db_to_file_mysqldump in Backup and Migrate 8.2

Same name and namespace in other branches
  1. 8.3 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::_backup_db_to_file_mysqldump()
  2. 7.3 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::_backup_db_to_file_mysqldump()
  3. 7.2 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::_backup_db_to_file_mysqldump()

Backup the databases to a file using the mysqldump command.

1 call to backup_migrate_destination_db_mysql::_backup_db_to_file_mysqldump()
backup_migrate_destination_db_mysql::_backup_db_to_file in includes/destinations.db.mysql.inc
Backup the databases to a file.

File

includes/destinations.db.mysql.inc, line 141
Functions to handle the direct to database destination.

Class

backup_migrate_destination_db_mysql
A destination type for saving to a database server.

Code

function _backup_db_to_file_mysqldump($file, $settings) {
  $success = FALSE;
  $nodata_tables = array();
  $alltables = $this
    ->_get_tables();
  $command = 'mysqldump --result-file=%file --opt -Q --host=%host --port=%port --user=%user --password=%pass %db';
  $args = array(
    '%file' => $file
      ->filepath(),
    '%host' => $this->dest_url['host'],
    '%port' => !empty($this->dest_url['port']) ? $this->dest_url['port'] : '3306',
    '%user' => $this->dest_url['user'],
    '%pass' => $this->dest_url['pass'],
    '%db' => $this->dest_url['path'],
  );

  // Ignore the excluded and no-data tables.
  if (!empty($settings->filters['exclude_tables'])) {
    $db = $this->dest_url['path'];
    foreach ((array) $settings->filters['exclude_tables'] as $table) {
      if (isset($alltables[$table])) {
        $command .= ' --ignore-table=' . $db . '.' . $table;
      }
    }
    foreach ((array) $settings->filters['nodata_tables'] as $table) {
      if (isset($alltables[$table])) {
        $nodata_tables[] = $table;
        $command .= ' --ignore-table=' . $db . '.' . $table;
      }
    }
  }
  $success = backup_migrate_exec($command, $args);

  // Get the nodata tables.
  if ($success && !empty($nodata_tables)) {
    $tables = implode(' ', array_unique($nodata_tables));
    $command = "mysqldump --no-data --opt -Q --host=%host --port=%port --user=%user --password=%pass %db {$tables} >> %file";
    $success = backup_migrate_exec($command, $args);
  }
  return $success;
}