Skip to content

Commit 6e7de3f

Browse files
authored
Merge pull request #20 from m-popa/feature/restore-using-mysql
Restore using the mysql binary to prevent memory errors.
2 parents 30096cd + 9c2d6fc commit 6e7de3f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ To specify a different local database connection:
7272
LOCAL_TARGET_CONNECTION=different_mysql_connection
7373
```
7474

75+
Set the mysql command path:
76+
77+
```
78+
LOCAL_MYSQL_PATH=/usr/bin/mysql
79+
```
80+
7581
For only mysqldump:
7682
```
7783
REMOTE_MYSQLDUMP_SKIP_TZ_UTC=true

config/dbsync.php

+2
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@
6868
'targetConnection' => env('LOCAL_TARGET_CONNECTION', 'mysql'),
6969

7070
'mysqldumpSkipTzUtc' => env('REMOTE_MYSQLDUMP_SKIP_TZ_UTC', false),
71+
72+
'localMysqlPath' => env('LOCAL_MYSQL_PATH', '/usr/local/bin/mysql'),
7173
];

src/Console/DbSyncCommand.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ public function handle(): bool
3737
$mysqldumpSkipTzUtc = config('dbsync.mysqldumpSkipTzUtc') ? '--skip-tz-utc' : '';
3838

3939
$targetConnection = config('dbsync.targetConnection');
40+
41+
$localUsername = config('database.connections.mysql.username');
42+
$localPassword = config('database.connections.mysql.password');
43+
$localHostname = config('database.connections.mysql.host');
44+
$localPort = config('database.connections.mysql.port');
45+
$localDatabase = config('database.connections.mysql.database');
46+
$localMysqlPath = config('dbsync.localMysqlPath');
4047

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

6269
if ($importSqlFile === true) {
63-
DB::connection($targetConnection)->unprepared(file_get_contents(base_path($fileName)));
70+
$command = $localPassword
71+
? "$localMysqlPath -u$localUsername -h$localHostname -p$localPassword -P$localPort $localDatabase < $fileName"
72+
: "$localMysqlPath -u$localUsername -h$localHostname -P$localPort $localDatabase < $fileName";
73+
exec($command, $output);
6474
}
6575

6676
if ($removeFileAfterImport === true) {

0 commit comments

Comments
 (0)