You are here

function backup_migrate_backup_db_to_file_mysql in Backup and Migrate 8.2

Get the sql dump file.

Returns a list of sql commands, one command per line. That makes it easier to import without loading the whole file into memory. The files are a little harder to read, but human-readability is not a priority

File

includes/db.mysql.inc, line 12

Code

function backup_migrate_backup_db_to_file_mysql($file, $settings) {
  $lines = 0;
  $exclude = !empty($settings->exclude_tables) ? $settings->exclude_tables : array();
  $nodata = !empty($settings->nodata_tables) ? $settings->nodata_tables : array();
  if ($file
    ->open(TRUE)) {
    $file
      ->write(_backup_migrate_get_sql_file_header_mysql());
    $alltables = _backup_migrate_get_tables_mysql();
    foreach ($alltables as $table) {
      if (_backup_migrate_check_timeout()) {
        return FALSE;
      }
      if ($table->name && !isset($exclude[$table->name])) {
        $file
          ->write(_backup_migrate_get_table_structure_sql_mysql($table));
        $lines++;
        if (!in_array($table->name, $nodata)) {
          $lines += _backup_migrate_dump_table_data_sql_to_file($file, $table);
        }
      }
    }
    $file
      ->write(_backup_migrate_get_sql_file_footer_mysql());
    $file
      ->close();
    return $lines;
  }
  else {
    return FALSE;
  }
}