Skip to content

Commit

Permalink
Merge pull request #23 from dcblogdev/add-progress-bars
Browse files Browse the repository at this point in the history
added Progress bars and the options single-transaction and set-gtid-p…
  • Loading branch information
dcblogdev authored May 2, 2024
2 parents 8025622 + d7741be commit e28c4af
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/Console/DbSyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function handle(): bool
$mysqldumpSkipTzUtc = config('dbsync.mysqldumpSkipTzUtc') ? '--skip-tz-utc' : '';

$targetConnection = config('dbsync.targetConnection');

$localUsername = config('database.connections.mysql.username');
$localPassword = config('database.connections.mysql.password');
$localHostname = config('database.connections.mysql.host');
Expand All @@ -59,28 +59,32 @@ public function handle(): bool
$ignoreString .= " --ignore-table=$database.$name";
}

$totalSteps = 2;
$progressBar = $this->output->createProgressBar($totalSteps);

if ($useSsh === true) {
echo($mysqlHostName . PHP_EOL);
exec("ssh $sshUsername@$host -p$sshPort mysqldump -P$port -h$mysqlHostName -u$username -p$password $database $ignoreString > $fileName", $output);
exec("ssh $sshUsername@$host -p$sshPort mysqldump --single-transaction --set-gtid-purged=OFF --port=$port --host=$mysqlHostName --user=$username --password=$password $database $ignoreString > $fileName", $output);
} else {
exec("mysqldump -h$host -P$port -u$username -p$password $database $ignoreString $mysqldumpSkipTzUtc --column-statistics=0 > $fileName", $output);
exec("mysqldump --single-transaction --set-gtid-purged=OFF --port=$port --host=$mysqlHostName --user=$username --password=$password $database $ignoreString $mysqldumpSkipTzUtc --column-statistics=0 > $fileName", $output);
}

$this->comment(implode(PHP_EOL, $output));
$progressBar->advance();

if ($importSqlFile === true) {
$command = $localPassword
? "$localMysqlPath -u$localUsername -h$localHostname -p$localPassword -P$localPort $localDatabase < $fileName"
: "$localMysqlPath -u$localUsername -h$localHostname -P$localPort $localDatabase < $fileName";
exec($command, $output);
}
$command = $localPassword
? "$localMysqlPath -u$localUsername -h$localHostname -p$localPassword -P$localPort $localDatabase < $fileName"
: "$localMysqlPath -u$localUsername -h$localHostname -P$localPort $localDatabase < $fileName";
exec($command, $output);

$progressBar->advance();
$progressBar->finish();

if ($removeFileAfterImport === true) {
unlink($fileName);
}
}

$this->comment('DB Synced');
$this->comment("\nDB Synced");

return true;
}
Expand Down

0 comments on commit e28c4af

Please sign in to comment.