Skip to content

Commit

Permalink
fix: unknown variable column-statistics=0 with MariaDB 10
Browse files Browse the repository at this point in the history
  • Loading branch information
alexislefebvre committed Jan 14, 2024
1 parent 0ae684e commit c30c948
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Services/DatabaseBackup/MysqlDatabaseBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,24 @@ public function backup(AbstractExecutor $executor): void
$executor->getReferenceRepository()->save($this->getBackupFilePath());
self::$metadata = $em->getMetadataFactory()->getLoadedMetadata();

exec("{$dbPass} mysqldump --host {$dbHost} {$port} --user {$dbUser} --no-create-info --skip-triggers --no-create-db --no-tablespaces --compact --column-statistics=0 {$dbName} > {$this->getBackupFilePath()}");
$mysqldumpOptions = '--no-create-info --skip-triggers --no-create-db --no-tablespaces --compact';
$mysqldumpCommand = 'mysqldump --host '.$dbHost.' '.$port.' --user '.$dbUser.' '.$dbName.' '.$mysqldumpOptions;
$columnStatistics0 = '--column-statistics=0';

// ignore the E_WARNING if “--column-statistics=0” is not a valid option
$execWithColumnStatistics = @exec(
$dbPass.' '.$mysqldumpCommand.' '.$columnStatistics0.' > '.$this->getBackupFilePath()
);

if (false !== $execWithColumnStatistics) {
return;
}

// when mysqldump is provided by MariaDB 10, “--column-statistics=0” is not a valid option,
// we call mysqldump without this option
exec(
$dbPass.' '.$mysqldumpCommand.' > '.$this->getBackupFilePath()
);
}

public function restore(AbstractExecutor $executor, array $excludedTables = []): void
Expand Down

0 comments on commit c30c948

Please sign in to comment.