db-tools.php dump command does not work in multi-site scenario

Created on 12 August 2020, over 4 years ago
Updated 5 February 2023, almost 2 years ago

Problem/Motivation

Trying to use db-tools.php 'dump-database-d8-mysql' command while providing a database via the '--database-url' parameter in a multi-site scenario with no sites/default/settings.php fails.

Drupal\Core\Database\ConnectionNotDefinedException: The specified database connection is not defined: default in /var/www/html/docroot/core/lib/Drupal/Core/Database/Database.php on line 361 #0 /var/www/html/docroot/core/lib/Drupal/Core/Database/Database.php(166): Drupal\Core\Database\Database::openConnection('default', 'default')
#1 [internal function]: Drupal\Core\Database\Database::getConnection('default')
#2 /var/www/html/docroot/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(79): call_user_func_array('Drupal\\Core\\Dat...', Array)
#3 /var/www/html/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(173): Drupal\Component\DependencyInjection\PhpArrayContainer->createService(Array, 'database')
#4 /var/www/html/docroot/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(260): Drupal\Component\DependencyInjection\Container->get('database', 1)
#5 /var/www/html/docroot/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(62): Drupal\Component\DependencyInjection\PhpArrayContainer->resolveServicesAndParameters(Array)
#6 /var/www/html/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(173): Drupal\Component\DependencyInjection\PhpArrayContainer->createService(Array, 'cache.container')
#7 /var/www/html/docroot/core/lib/Drupal/Core/DrupalKernel.php(543): Drupal\Component\DependencyInjection\Container->get('cache.container')
#8 /var/www/html/docroot/core/lib/Drupal/Core/DrupalKernel.php(904): Drupal\Core\DrupalKernel->getCachedContainerDefinition()
#9 /var/www/html/docroot/core/lib/Drupal/Core/DrupalKernel.php(476): Drupal\Core\DrupalKernel->initializeContainer()
#10 /var/www/html/docroot/core/scripts/db-tools.php(25): Drupal\Core\DrupalKernel->boot()
#11 {main}

Steps to reproduce

Configure a second database in sites/default/settings.php, e.g.:

$databases['something']['default'] = array(
  'database' => "something",
  'username' => "db",
  'password' => "db",
  'host' => 'db',
  'driver' => "mysql",
  'prefix' => "",
);

Try using the db-tools.php script to load a fixtures file to this database:

$ php core/scripts/db-tools.php import --database=something core/modules/migrate_drupal/tests/fixtures/drupal7.php

What should happen:
The fixture file should be loaded into the "something" database.

What actually happens:
The import fails with the error message above.

Proposed resolution

Invalidate the service container before booting.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
OtherΒ  β†’

Last updated about 6 hours ago

Created by

πŸ‡©πŸ‡ͺGermany volkerk

Live updates comments and jobs are added and updated live.
  • testing

    Used for Documentation issues related to testing and test development

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Let me know if I did something wrong but I get this error with patch #9

    
    smustgrave@drupal-10-x-web:/var/www/html$ php web/core/scripts/db-tools.php import --database=test core/modules/migrate_drupal/tests/fixtures/drupal7.php
    Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The service file "core/core.services.yml" is not valid. in /var/www/html/web/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php on line 414 #0 /var/www/html/web/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php(69): Drupal\Core\DependencyInjection\YamlFileLoader->loadFile('core/core.servi...')
    #1 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(1277): Drupal\Core\DependencyInjection\YamlFileLoader->load('core/core.servi...')
    #2 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(910): Drupal\Core\DrupalKernel->compileContainer()
    #3 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(476): Drupal\Core\DrupalKernel->initializeContainer()
    #4 /var/www/html/web/core/scripts/db-tools.php(24): Drupal\Core\DrupalKernel->boot()
    #5 {main}
    Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The service file "core/core.services.yml" is not valid. in Drupal\Core\DependencyInjection\YamlFileLoader->loadFile() (line 414 of /var/www/html/web/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php).
    
    
  • Status changed to RTBC almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Scratch that my path was wrong.

    Fixed it and the database imported just fine.

  • last update about 1 year ago
    29,655 pass
Production build 0.71.5 2024