Skip to content

Commit

Permalink
Merge pull request #20 from m-popa/feature/restore-using-mysql
Browse files Browse the repository at this point in the history
Restore using the mysql binary to prevent memory errors.
  • Loading branch information
dcblogdev authored Mar 12, 2024
2 parents 30096cd + 9c2d6fc commit 6e7de3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ To specify a different local database connection:
LOCAL_TARGET_CONNECTION=different_mysql_connection
```

Set the mysql command path:

```
LOCAL_MYSQL_PATH=/usr/bin/mysql
```

For only mysqldump:
```
REMOTE_MYSQLDUMP_SKIP_TZ_UTC=true
Expand Down
2 changes: 2 additions & 0 deletions config/dbsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@
'targetConnection' => env('LOCAL_TARGET_CONNECTION', 'mysql'),

'mysqldumpSkipTzUtc' => env('REMOTE_MYSQLDUMP_SKIP_TZ_UTC', false),

'localMysqlPath' => env('LOCAL_MYSQL_PATH', '/usr/local/bin/mysql'),
];
12 changes: 11 additions & 1 deletion src/Console/DbSyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ 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');
$localPort = config('database.connections.mysql.port');
$localDatabase = config('database.connections.mysql.database');
$localMysqlPath = config('dbsync.localMysqlPath');

if (empty($host) || empty($username) || empty($database)) {
$this->error('DB credentials not set, have you published the config and set ENV variables?');
Expand All @@ -60,7 +67,10 @@ public function handle(): bool
$this->comment(implode(PHP_EOL, $output));

if ($importSqlFile === true) {
DB::connection($targetConnection)->unprepared(file_get_contents(base_path($fileName)));
$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);
}

if ($removeFileAfterImport === true) {
Expand Down

0 comments on commit 6e7de3f

Please sign in to comment.