You are here

public function GdprDumpGdprSqlMysql::dump in General Data Protection Regulation 7

Execute a SQL dump and return the path to the resulting dump file.

Parameters

string|bool $file: The path where the dump file should be stored. If TRUE, generate a path based on usual backup directory and current date.

File

modules/gdpr_dump/inc/GdprDumpGdprSqlMysql.inc, line 17

Class

GdprDumpGdprSqlMysql
Class GdprDumpGdprSqlMysql.

Code

public function dump($file = '') {
  $file_suffix = '';
  $table_selection = $this
    ->get_expanded_table_selection();
  $file = $this
    ->dumpFile($file);

  // @todo: Cross-platform check.
  $cmd = '{ ';
  $cmd .= $this
    ->dumpCmd($table_selection);

  // Append the RENAME commands at the end.
  $cmd .= ' ; ' . $this
    ->createRenameCommands($table_selection) . '}';

  // Gzip the output from dump command(s) if requested.
  if (drush_get_option('gzip')) {
    $cmd .= ' | gzip -f';
    $file_suffix .= '.gz';
  }
  if ($file) {
    $file .= $file_suffix;
    $cmd .= ' > ' . drush_escapeshellarg($file);
  }

  // Avoid the php memory of the $output array in drush_shell_exec().
  if (drush_op_system($cmd) === 0) {
    if ($file) {
      drush_log(dt('Database dump saved to !path', [
        '!path' => $file,
      ]), 'success');
      drush_backend_set_result($file);
    }
  }
  else {
    return drush_set_error('DRUSH_SQL_DUMP_FAIL', 'Database dump failed');
  }
}