Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backup option doesn't backup database #4225

Closed
Jimmi08 opened this issue Aug 3, 2020 · 7 comments
Closed

backup option doesn't backup database #4225

Jimmi08 opened this issue Aug 3, 2020 · 7 comments
Labels
type: bug A problem that should not be happening

Comments

@Jimmi08
Copy link
Contributor

Jimmi08 commented Aug 3, 2020

Bug Description

e107 is not able to backup database on live server

This is localhost:
image

This is live site:
image

As you can see SQL file is not created.

Live site:
PHP Version 5.6.40
10.1.38-MariaDB-1~xenial
PDO: Enabled
NO_ENGINE_SUBSTITUTION

Version 2.3.0 (git)

Admin log:

image

@Jimmi08 Jimmi08 added the type: bug A problem that should not be happening label Aug 3, 2020
@Jimmi08
Copy link
Contributor Author

Jimmi08 commented Aug 3, 2020

Reason:
This
$dump = new Ifsnop\Mysqldump\Mysqldump('mysql:host='.$config['mySQLserver'].';dbname='.$config['mySQLdefaultdb'], $config['mySQLuser'], $config['mySQLpassword'], $dumpSettings);

return error:

mysqldump-php error: Connection to mysql failed with message: SQLSTATE[HY000] [2005] Unknown MySQL server host 'mariadb101.websupport.sk:3312' (2)

but correct connection according my hosting should be:

$connection = new PDO("mysql:host=mariadb101.websupport.sk;port=3312;dbname=****", "****", "***");

After hardcoded those 2 values, backup was created:
'mysql:host=mariadb101.websupport.sk;port=3312;dbname=

image

@Jimmi08
Copy link
Contributor Author

Jimmi08 commented Aug 3, 2020

This was solved this way before:

		if(strpos($mySQLserver,':')!==false && substr_count($mySQLserver, ':')===1)
		{
			list($this->mySQLserver,$this->mySQLport) = explode(':',$mySQLserver,2);
		}

2420c97

@Moc
Copy link
Member

Moc commented Aug 3, 2020

@Deltik do we need to apply the same fix to the pdo handler?

@Jimmi08
Copy link
Contributor Author

Jimmi08 commented Aug 3, 2020

@Moc just for backup, connect() works this way. At least I hope and it didn't fall back to mysql connect.

@Deltik
Copy link
Member

Deltik commented Aug 3, 2020

@Moc: No, the hostname and port are already parsed by the time e_db_pdo::backup() is called. This patch should fix the issue:

diff --git a/e107_handlers/e_db_pdo_class.php b/e107_handlers/e_db_pdo_class.php
index 1e73bf01b..511f45690 100644
--- a/e107_handlers/e_db_pdo_class.php
+++ b/e107_handlers/e_db_pdo_class.php
@@ -2455,8 +2455,6 @@ class e_db_pdo implements e_db
 
    //     include_once(dirname(__FILE__) . '/Ifsnop/Mysqldump/Mysqldump.php');
 
-        $config = e107::getMySQLConfig();
-
                $dumpSettings = array(
                'compress'                      => !empty($options['gzip']) ? Ifsnop\Mysqldump\Mysqldump::GZIP : Ifsnop\Mysqldump\Mysqldump::NONE,
                'include-tables'                => array(),
@@ -2477,13 +2475,13 @@ class e_db_pdo implements e_db
 
         foreach($tableList as $tab)
         {
-            $dumpSettings['include-tables'][] = $config['mySQLprefix'].trim($tab);
+            $dumpSettings['include-tables'][] = $this->mySQLPrefix.trim($tab);
         }
 
 
         try
         {
-            $dump = new Ifsnop\Mysqldump\Mysqldump('mysql:host='.$config['mySQLserver'].';dbname='.$config['mySQLdefaultdb'], $config['mySQLuser'], $config['mySQLpassword'], $dumpSettings);
+            $dump = new Ifsnop\Mysqldump\Mysqldump("mysql:host={$this->mySQLserver};port={$this->mySQLport};dbname={$this->mySQLdefaultdb}", $this->mySQLuser, $this->mySQLpassword, $dumpSettings);
                    $dump->start($backupFile);
                    return $backupFile;
                }

@Jimmi08: Can you try this patch to see if it works for your setup with the custom hostname and port?

@Jimmi08
Copy link
Contributor Author

Jimmi08 commented Aug 4, 2020

@Deltik I am getting error:
mysqldump-php error: Missing database name from DSN string

This version works (I just replaced $config), but I have no idea what is wrong/different with yours (I checked it, string is correct, db is there):
$dump = new Ifsnop\Mysqldump\Mysqldump('mysql:host='.$this->mySQLserver.';port='.$this->mySQLport.';dbname='.$this->mySQLdefaultdb, $this->mySQLuser, $this->mySQLpassword, $dumpSettings);

@Deltik
Copy link
Member

Deltik commented Aug 4, 2020

@Jimmi08: Sorry, I had some extraneous spacing in the DSN string. Here's the updated patch. I tested it myself this time, and the data got exported as expected.

@Deltik Deltik closed this as completed in f655847 Aug 4, 2020
Reconix pushed a commit to Reconix/e107 that referenced this issue Aug 30, 2020
e_db_pdo::backup() now supports MySQL servers with custom ports

Fixes: e107inc#4225
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A problem that should not be happening
Projects
None yet
Development

No branches or pull requests

3 participants