Skip to content

Commit

Permalink
Merge pull request #17 from estrma/allow-different-mysql-hostname
Browse files Browse the repository at this point in the history
Allow different MySQL hostname
  • Loading branch information
dcblogdev authored Mar 12, 2024
2 parents 6e7de3f + 8166205 commit 6a512e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config/dbsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
*/
'username' => env('REMOTE_DATABASE_USERNAME', ''),

/*
* Database host (optional)
*/
'mysqlHostName' => env('REMOTE_DATABASE_MYSQL_HOSTNAME', 'localhost'),

/*
* Database port
*/
Expand Down
6 changes: 4 additions & 2 deletions src/Console/DbSyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ public function handle(): bool
return true;
}

$host = config('dbsync.host');
$useSsh = config('dbsync.useSsh');
$sshUsername = config('dbsync.sshUsername');
$sshPort = config('dbsync.sshPort');
$host = config('dbsync.host');

$mysqlHostName = config('dbsync.mysqlHostName');
$username = config('dbsync.username');
$database = config('dbsync.database');
$port = config('dbsync.port');
Expand Down Expand Up @@ -59,7 +60,8 @@ public function handle(): bool
}

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

0 comments on commit 6a512e4

Please sign in to comment.