Skip to content

Commit 290ebfa

Browse files
committed
Fixed Database Backup and Restore command for multi tenancy database
1 parent 365298c commit 290ebfa

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/Commands/DatabaseBackup.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ public function backup(Dumper $dumper, array $data)
7575
$compressCommand = config('dbm.backup.compress_command', 'gzip');
7676
$compressExtension = config('dbm.backup.compress_extension', '.gz');
7777
$dumpBinaryPath = config('dbm.backup.'.$data['driver'].'.binary_path', '');
78+
$hostname = config('database.connections.'.$data['driver'].'.host', '127.0.0.1');
79+
$port = config('database.connections.'.$data['driver'].'.port', '3306');
80+
$database = config('database.connections.'.$data['driver'].'.database', 'dbm');
81+
$username = config('database.connections.'.$data['driver'].'.username', 'root');
82+
$password = config('database.connections.'.$data['driver'].'.password', '');
83+
84+
$dumper->setHost($hostname)
85+
->setPort($port)
86+
->setDbName($database)
87+
->setUserName($username)
88+
->setPassword($password);
7889

7990
switch ($data['driver']) {
8091
case 'mysql':

src/Commands/DatabaseRestore.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ public function handle(Filesystem $filesystem, Dumper $dumper)
6262
{
6363
$this->info('Restoring Database');
6464

65-
$hostname = config('database.connections.mysql.host', '127.0.0.1');
66-
$port = config('database.connections.mysql.port', '3306');
67-
$database = config('database.connections.mysql.database', 'dbm');
68-
$username = config('database.connections.mysql.username', 'root');
69-
$password = config('database.connections.mysql.password', '');
70-
7165
$driver = dbm_driver();
66+
$hostname = config('database.connections.'.$driver.'.host', '127.0.0.1');
67+
$port = config('database.connections.'.$driver.'.port', '3306');
68+
$database = config('database.connections.'.$driver.'.database', 'dbm');
69+
$username = config('database.connections.'.$driver.'.username', 'root');
70+
$password = config('database.connections.'.$driver.'.password', '');
71+
7272
$directory = 'backups'.DIRECTORY_SEPARATOR.$driver;
7373

7474
if ($this->option('path') != null) {
@@ -87,6 +87,12 @@ public function handle(Filesystem $filesystem, Dumper $dumper)
8787
$compressExtension = config('dbm.backup.compress_extension', '.gz');
8888
$dumpBinaryPath = config('dbm.backup.'.$driver.'.binary_path', '');
8989

90+
$dumper->setHost($hostname)
91+
->setPort($port)
92+
->setDbName($database)
93+
->setUserName($username)
94+
->setPassword($password);
95+
9096
try {
9197
switch ($driver) {
9298
case 'mongodb':

0 commit comments

Comments
 (0)