GithubHelp home page GithubHelp logo

[Bug]: db:convert-type uses systemConfig instead of command line parameters for connection to new target database about server HOT 20 OPEN

ksmonkey123 avatar ksmonkey123 commented on September 25, 2024 2
[Bug]: db:convert-type uses systemConfig instead of command line parameters for connection to new target database

from server.

Comments (20)

Infamousbugg avatar Infamousbugg commented on September 25, 2024 3

I also have a migration on hold waiting for this issue to be resolved.

from server.

juliushaertl avatar juliushaertl commented on September 25, 2024 2

Possible patch candidate, but haven't had time to verify and test this yet:

diff --git a/core/Command/Db/ConvertType.php b/core/Command/Db/ConvertType.php
index 333f29625f6..078fd47965b 100644
--- a/core/Command/Db/ConvertType.php
+++ b/core/Command/Db/ConvertType.php
@@ -227,15 +227,22 @@ class ConvertType extends Command implements CompletionAwareInterface {
        protected function getToDBConnection(InputInterface $input, OutputInterface $output) {
                $type = $input->getArgument('type');
                $connectionParams = $this->connectionFactory->createConnectionParams();
-               $connectionParams = array_merge($connectionParams, [
+
+               $overrideConnectionParams = [
                        'host' => $input->getArgument('hostname'),
                        'user' => $input->getArgument('username'),
                        'password' => $input->getOption('password'),
                        'dbname' => $input->getArgument('database'),
-               ]);
+               ];
                if ($input->getOption('port')) {
-                       $connectionParams['port'] = $input->getOption('port');
+                       $overrideConnectionParams['port'] = $input->getOption('port');
                }
+
+               $connectionParams = array_merge($connectionParams, [
+                       'primary' => $overrideConnectionParams,
+                       'replica' => [$overrideConnectionParams],
+               ]);
+
                return $this->connectionFactory->getConnection($type, $connectionParams);
        }

from server.

jiriks74 avatar jiriks74 commented on September 25, 2024 2

@szaimen I'll be probably playing around with a new (old) server this evening. I'll back up my database and try the patch out. I'll know practically immediately as I get the duplicate entry error right at the start if it tries to write into the original DB.

from server.

zackgomez avatar zackgomez commented on September 25, 2024 2

Any progress?

Is the current guidance to create a fresh system losing an existing data?

from server.

joshtrichards avatar joshtrichards commented on September 25, 2024 1

Yes, unfortunately. 😢 The end result is the parameters get swapped so it likely dropped the source database.

Fortunately, recovery should be a simple matter of restoring from backup (just the db portion): https://docs.nextcloud.com/server/latest/admin_manual/maintenance/restore.html#restore-database (or whatever other mechanism you utilize in your environment for database backup/recovery)

from server.

joshtrichards avatar joshtrichards commented on September 25, 2024 1

@Delagen Mind pushing that as PR? I know there may be additional changes needed, but it'll start things in motion.

from server.

Delagen avatar Delagen commented on September 25, 2024 1

@joshtrichards I don't mind that my changes solve the problem correctly. It only makes possible for me successful conversion from MySQL to Postgres

from server.

rotdrop avatar rotdrop commented on September 25, 2024 1

Would not be it the simplest solution, if the ConnectionFactory::getConnection() method would first check if the $additionalConnectionParams argument contains explicit connection parameters and in that case simply skip that fancy primary / replica stuff? At least for the case were the explicitly specified connection differs from the "internal" database connection configured in config/config.php. In principle this should restore the previous behaviour when using the factory for alternate database connections.

from server.

szaimen avatar szaimen commented on September 25, 2024 1

Hi @intersectRaven @ksmonkey123 @Delagen @HammyHavoc @chimpboy @rotdrop are you able to test the above patch? Thanks in advance! :)

from server.

jiriks74 avatar jiriks74 commented on September 25, 2024 1

The conversion script gets stuck on this line

$toMS->migrate($currentMigration);

from server.

ksmonkey123 avatar ksmonkey123 commented on September 25, 2024

Logging the Parameter $additionalConnectionParams in ConnectionFactory.php on Line 166 shows the following values for the "fromDB" and the "toDB":

FromDB

Array
(
    [adapter] => OC\DB\AdapterMySQL
    [charset] => utf8mb4
    [driver] => pdo_mysql
    [wrapperClass] => OC\DB\Connection
    [driverOptions] => Array
        (
            [1005] => 1
        )

    [user] => nextcloud
    [password] => *************
    [host] => nextcloud-db
    [dbname] => nextcloud
    [tablePrefix] => oc_
    [sqlite.journal_mode] => WAL
    [defaultTableOptions] => Array
        (
            [collate] => utf8mb4_bin
            [charset] => utf8mb4
            [tablePrefix] => oc_
        )

    [primary] => Array
        (
            [adapter] => OC\DB\AdapterMySQL
            [charset] => utf8mb4
            [driver] => pdo_mysql
            [wrapperClass] => OC\DB\Connection
            [driverOptions] => Array
                (
                    [1005] => 1
                )

            [user] => nextcloud
            [password] => ****************
            [host] => nextcloud-db
            [dbname] => nextcloud
            [tablePrefix] => oc_
            [sqlite.journal_mode] => WAL
            [defaultTableOptions] => Array
                (
                    [collate] => utf8mb4_bin
                    [charset] => utf8mb4
                    [tablePrefix] => oc_
                )

        )

    [replica] => Array
        (
            [0] => Array
                (
                    [adapter] => OC\DB\AdapterMySQL
                    [charset] => utf8mb4
                    [driver] => pdo_mysql
                    [wrapperClass] => OC\DB\Connection
                    [driverOptions] => Array
                        (
                            [1005] => 1
                        )

                    [user] => nextcloud
                    [password] => *************
                    [host] => nextcloud-db
                    [dbname] => nextcloud
                    [tablePrefix] => oc_
                    [sqlite.journal_mode] => WAL
                    [defaultTableOptions] => Array
                        (
                            [collate] => utf8mb4_bin
                            [charset] => utf8mb4
                            [tablePrefix] => oc_
                        )

                )

        )

)

ToDB

Array
(
    [adapter] => OC\DB\AdapterMySQL
    [charset] => utf8mb4
    [driver] => pdo_mysql
    [wrapperClass] => OC\DB\Connection
    [driverOptions] => Array
        (
            [1005] => 1
        )

    [user] => nextcloud_app
    [password] => ***************
    [host] => postgres
    [dbname] => nextcloud
    [tablePrefix] => oc_
    [sqlite.journal_mode] => WAL
    [defaultTableOptions] => Array
        (
            [collate] => utf8mb4_bin
            [charset] => utf8mb4
            [tablePrefix] => oc_
        )

    [primary] => Array
        (
            [adapter] => OC\DB\AdapterMySQL
            [charset] => utf8mb4
            [driver] => pdo_mysql
            [wrapperClass] => OC\DB\Connection
            [driverOptions] => Array
                (
                    [1005] => 1
                )

            [user] => nextcloud
            [password] => *************
            [host] => nextcloud-db
            [dbname] => nextcloud
            [tablePrefix] => oc_
            [sqlite.journal_mode] => WAL
            [defaultTableOptions] => Array
                (
                    [collate] => utf8mb4_bin
                    [charset] => utf8mb4
                    [tablePrefix] => oc_
                )

        )

    [replica] => Array
        (
            [0] => Array
                (
                    [adapter] => OC\DB\AdapterMySQL
                    [charset] => utf8mb4
                    [driver] => pdo_mysql
                    [wrapperClass] => OC\DB\Connection
                    [driverOptions] => Array
                        (
                            [1005] => 1
                        )

                    [user] => nextcloud
                    [password] => **********
                    [host] => nextcloud-db
                    [dbname] => nextcloud
                    [tablePrefix] => oc_
                    [sqlite.journal_mode] => WAL
                    [defaultTableOptions] => Array
                        (
                            [collate] => utf8mb4_bin
                            [charset] => utf8mb4
                            [tablePrefix] => oc_
                        )

                )

        )

    [port] => 5432
)

It is notable that in the second case (which should be the postgres-database configured via the CLI arguments), the host, dbname and port in the top-level array are set correctly from the CLI, Both the primary and the replica fields and even some top-level fields obviously use the DB-configs from config.php

from server.

joshtrichards avatar joshtrichards commented on September 25, 2024

Possibly related: #45097

I don't have time to look tonight, but your analysis seems sound (and, given the added evidence from the log output, even more so).

Cc: @juliushaertl

from server.

intersectRaven avatar intersectRaven commented on September 25, 2024

I can verify but can't contribute logs. I used the --clear-schema option in my attempt and my original MariaDB DB got deleted. Good thing I have backups.

from server.

Delagen avatar Delagen commented on September 25, 2024

I modified https://github.com/nextcloud/server/blob/master/core/Command/Db/ConvertType.php#L247
to

$connectionParams = $this->connectionFactory->getDefaultConnectionParams($type);

and seems all converted

Also have to remove mysql.utf8mb4 parameter from config.php to perform conversion to remove client_encoding from params of DbFactory

from server.

HammyHavoc avatar HammyHavoc commented on September 25, 2024

Got hit by this a week ago. Is that particular Nextcloud instance completely screwed?

from server.

chimpboy avatar chimpboy commented on September 25, 2024

I have just experienced this problem on a new installation.

from server.

szaimen avatar szaimen commented on September 25, 2024

Hi, is this #45013 fixing the problem?

from server.

jiriks74 avatar jiriks74 commented on September 25, 2024

I just looked into it a bit and so far it looks like the databases get mixed up somewhere in the script.

When I hardcoded the toDB values it tried to connect to the target database (PostgreSQL) with the credentials of my current database (MariaDB/MySQL). It used the username from the old database on the new one.

from server.

jiriks74 avatar jiriks74 commented on September 25, 2024

I tried it out, it doesn't work. I get stuck on Creating schema in new database even after hardcoding the connections for my databases to be sure that it's passed right. I'll try to find out where the issue is.

from server.

leon1995 avatar leon1995 commented on September 25, 2024

Are there any new information on this?

from server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.