diff --git a/core/lib/Drupal/Core/Command/DbDump.php b/core/lib/Drupal/Core/Command/DbDump.php
new file mode 100644
index 0000000..8a5632c
--- /dev/null
+++ b/core/lib/Drupal/Core/Command/DbDump.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Command\DbDump.
+ */
+
+namespace Drupal\Core\Command;
+
+use Drupal\Core\Database\Connection;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Symfony\Component\Console\Application;
+use Symfony\Component\Console\Input\InputInterface;
+
+/**
+ * Provides a command to dump a database generation script.
+ */
+class DbDump extends Application {
+
+  /**
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $connection;
+
+  /**
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface
+   */
+  protected $moduleHandler;
+
+  /**
+   * @param \Drupal\Core\Database\Connection $connection
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+   */
+  function __construct(Connection $connection, ModuleHandlerInterface $module_handler) {
+    $this->connection = $connection;
+    $this->moduleHandler = $module_handler;
+    parent::__construct();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getCommandName(InputInterface $input) {
+    return 'db-dump';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getDefaultCommands() {
+    // Even though this is a single command, keep the HelpCommand (--help).
+    $default_commands = parent::getDefaultCommands();
+    $default_commands[] = new DbDumpCommand($this->connection, $this->moduleHandler);
+    return $default_commands;
+  }
+
+  /**
+   * {@inheritdoc}
+   *
+   * Overridden so the application doesn't expect the command name as the first
+   * argument.
+   */
+  public function getDefinition() {
+    $definition = parent::getDefinition();
+    // Clears the normal first argument (the command name).
+    $definition->setArguments();
+    return $definition;
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Command/DbDumpCommand.php b/core/lib/Drupal/Core/Command/DbDumpCommand.php
new file mode 100644
index 0000000..4002729
--- /dev/null
+++ b/core/lib/Drupal/Core/Command/DbDumpCommand.php
@@ -0,0 +1,311 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Command\DbDumpCommand.
+ */
+
+namespace Drupal\Core\Command;
+
+use Drupal\Component\Utility\Variable;
+use Drupal\Core\Database\Connection;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Provides a command to dump the current database to a script.
+ *
+ * @see \Drupal\Core\Command\DbDump
+ */
+class DbDumpCommand extends Command {
+
+  /**
+   * @var \Drupal\Core\Database\Connection $connection
+   */
+  protected $connection;
+
+  /**
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface
+   */
+  protected $moduleHandler;
+
+  /**
+   * An array of table patterns to exclude completely.
+   *
+   * This excludes any lingering simpletest tables generated during test runs.
+   *
+   * @var array
+   */
+  protected $excludeTables = ['simpletest.+'];
+
+  /**
+   * Table patterns for which to only dump the schema, no data.
+   *
+   * @var array
+   */
+  protected $schemaOnly = ['cache.*', 'sessions', 'watchdog'];
+
+  /**
+   * @param \Drupal\Core\Database\Connection $connection
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+   */
+  function __construct(Connection $connection, ModuleHandlerInterface $module_handler) {
+    $this->connection = $connection;
+    $this->moduleHandler = $module_handler;
+    parent::__construct();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function configure() {
+    $this->setName('db-dump')
+      ->setDescription('Dump the current database to a generation script');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function execute(InputInterface $input, OutputInterface $output) {
+    $output->writeln($this->generateScript());
+  }
+
+  /**
+   * Generates the database script.
+   *
+   * @return string
+   *   The PHP script.
+   */
+  protected function generateScript() {
+    $tables = '';
+    foreach ($this->getTables() as $table) {
+      $schema = $this->getTableSchema($table);
+      $data = $this->getTableData($table);
+      $tables .= $this->getTableScript($table, $schema, $data);
+    }
+    $script = $this->getTemplate();
+    // Substitute in the tables.
+    $script = str_replace('{{TABLES}}', trim($tables), $script);
+    // Modules.
+    $script = str_replace('{{MODULES}}', $this->getModulesScript(), $script);
+    return trim($script);
+  }
+
+  /**
+   * Returns a list of tables, not included those set to be excluded.
+   *
+   * @return array
+   *   An array of table names.
+   */
+  protected function getTables() {
+    $pattern = $this->connection->tablePrefix() . '%';
+    $tables = array_values($this->connection->schema()->findTables($pattern));
+    foreach ($tables as $key => $table) {
+      // The prefix is removed for the resultant script.
+      $table = $tables[$key] = str_replace($this->connection->tablePrefix(), '', $table);
+
+      // Remove any explicitly excluded tables.
+      foreach ($this->excludeTables as $pattern) {
+        if (preg_match('/^' . $pattern . '$/', $table)) {
+          unset($tables[$key]);
+        }
+      }
+    }
+    return $tables;
+  }
+
+  /**
+   * Returns a schema array for a given table.
+   *
+   * @param string $table
+   *   The table name
+   *
+   * @return array
+   *   A schema array (as defined by hook_schema()).
+   */
+  protected function getTableSchema($table) {
+    // @todo this implementation is hard-coded for MySQL.
+    $query = $this->connection->query("SHOW COLUMNS FROM {" . $table . "}");
+    $definition = [];
+    while (($row = $query->fetchAssoc()) !== FALSE) {
+      $name = $row['Field'];
+      // Parse out the field type and meta information.
+      preg_match('@([a-z]+)(?:\((\d+)(?:,(\d+))?\))?\s*(unsigned)?@', $row['Type'], $matches);
+      $type  = $this->fieldTypeMap($matches[1]);
+      if ($row['Extra'] === 'auto_increment') {
+        // If this is an auto increment, then the type is 'serial'.
+        $type = 'serial';
+      }
+      // Add primary key information.
+      if ($row['Key'] === 'PRI') {
+        $definition['primary key'][] = $name;
+      }
+      $definition['fields'][$name] = [
+        'type' => $type,
+        'not null' => $row['Null'] === 'NO',
+      ];
+      if (isset($matches[2]) && $type === 'numeric') {
+        // Add precision and scale.
+        $definition['fields'][$name]['precision'] = $matches[2];
+        $definition['fields'][$name]['scale'] = $matches[3];
+      }
+      elseif ($type === 'time' || $type === 'datetime') {
+        // @todo Core doesn't support these, but copied from `migrate-db.sh` for now.
+        // Convert to varchar.
+        $definition['fields'][$name]['type'] = 'varchar';
+        $definition['fields'][$name]['length'] = '100';
+      }
+      else {
+        // Try use the provided length, if it doesn't exist default to 100. It's
+        // not great but good enough for our dumps at this point.
+        $definition['fields'][$name]['length'] = isset($matches[2]) ? $matches[2] : 100;
+      }
+
+      if (isset($row['Default'])) {
+        $definition['fields'][$name]['default'] = $row['Default'];
+      }
+
+      if (isset($matches[4])) {
+        $definition['fields'][$name]['unsigned'] = TRUE;
+      }
+    }
+    return $definition;
+  }
+
+  /**
+   * Gets all data from a given table.
+   *
+   * If a table is set to be schema only, and empty array is returned.
+   *
+   * @param string $table
+   *   The table to query.
+   * @return array
+   *   The data from the table as an array.
+   */
+  protected function getTableData($table) {
+    // Check for schema only.
+    foreach ($this->schemaOnly as $schema_only) {
+      if (preg_match('/^' . $schema_only . '$/', $table)) {
+        return [];
+      }
+    }
+    $order = $this->getFieldOrder($table);
+    $query = $this->connection->query("SELECT * FROM {" . $table . "} " . $order );
+    $results = [];
+    while (($row = $query->fetchAssoc()) !== FALSE) {
+      $results[] = $row;
+    }
+    return $results;
+  }
+
+  /**
+   * Given a database field type, return a Drupal type.
+   *
+   * @param string $type
+   *   The MySQL field type.
+   *
+   * @return string
+   *   The Drupal schema field type. If there is no mapping, the original field
+   *   type is returned.
+   */
+  protected function fieldTypeMap($type) {
+    $map = array_flip($this->connection->schema()->getFieldTypeMap());
+    return isset($map[$type]) ? $map[$type] : $type;
+  }
+
+  /**
+   * Gets field ordering for a given table.
+   */
+  protected function getFieldOrder($table) {
+    // @todo this is MySQL only since there are no Database API functions for
+    // table column data.
+    // @todo this code is duplicated in `core/scripts/migrate-db.sh`.
+    $connection_info = $this->connection->getConnectionOptions();
+    // Order by primary keys.
+    $order = '';
+    $query = "SELECT `COLUMN_NAME` FROM `information_schema`.`COLUMNS`
+    WHERE (`TABLE_SCHEMA` = '" . $connection_info['database'] . "')
+    AND (`TABLE_NAME` = '{" . $table . "}') AND (`COLUMN_KEY` = 'PRI')
+    ORDER BY COLUMN_NAME";
+    $results = $this->connection->query($query);
+    while (($row = $results->fetchAssoc()) !== FALSE) {
+      $order .= $row['COLUMN_NAME'] . ', ';
+    }
+    if (!empty($order)) {
+      $order = ' ORDER BY ' . rtrim($order, ', ');
+    }
+    return $order;
+  }
+
+  /**
+   * The script template.
+   *
+   * @return string
+   */
+  protected function getTemplate() {
+    $script = <<<'ENDOFSCRIPT'
+<?php
+/**
+ * @file
+ * Filled installation of Drupal 8.0, for test purposes.
+ *
+ * This file was generated by the dump-database-d8.php script, from an
+ * installation of Drupal 8. It has the following modules installed:
+ *
+{{MODULES}}
+ */
+
+ use Drupal\Core\Database\Database;
+
+ $connection = Database::getConnection();
+
+{{TABLES}}
+
+ENDOFSCRIPT;
+    return $script;
+  }
+
+  /**
+   * The part of the script for each table.
+   *
+   * @param string $table
+   *   Table name.
+   * @param array $schema
+   *   Drupal schema definition.
+   * @param array $data
+   *   Data for the table.
+   */
+  protected function getTableScript($table, array $schema, array $data) {
+    $output = '';
+    $output .= "\$connection->schema()->createTable('" . $table . "', " . Variable::export($schema) . ");\n\n";
+    if (!empty($data)) {
+      $insert = '';
+      foreach ($data as $record) {
+        $insert .= "->values(" . Variable::export($record) . ")\n";
+      }
+      $output .= "\$connection->insert('" . $table . "')\n"
+        . "->fields(" . Variable::export($schema['fields']) . ")\n"
+        . $insert
+        . "->execute();\n\n";
+    }
+    return $output;
+  }
+
+  /**
+   * List of modules enabled for insertion into the script docblock.
+   *
+   * @return string
+   */
+  protected function getModulesScript() {
+    $output = '';
+    $modules = $this->moduleHandler->getModuleList();
+    ksort($modules);
+    foreach ($modules as $module => $filename) {
+      $output .= " *  - $module\n";
+    }
+    return rtrim($output, "\n");
+  }
+
+}
diff --git a/core/modules/system/src/Tests/Update/DbDumpTest.php b/core/modules/system/src/Tests/Update/DbDumpTest.php
new file mode 100644
index 0000000..5da7258
--- /dev/null
+++ b/core/modules/system/src/Tests/Update/DbDumpTest.php
@@ -0,0 +1,82 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\system\Tests\Update\DbDumpTest.
+ */
+
+namespace Drupal\system\Tests\Update;
+use Drupal\Core\Command\DbDump;
+use Drupal\Core\Config\Config;
+use Drupal\Core\Config\DatabaseStorage;
+use Drupal\Core\Database\Database;
+use Drupal\simpletest\KernelTestBase;
+use Symfony\Component\Console\Tester\CommandTester;
+
+/**
+ * Tests for the database dump commands.
+ *
+ * @group Update
+ */
+class DbDumpTest extends KernelTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static $modules = ['system', 'config'];
+
+  /**
+   * Test data to write into config.
+   *
+   * @var array
+   */
+  protected $data;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+
+    // Create some schemas so our export contains tables.
+    $this->installSchema('system', ['sessions', 'url_alias']);
+
+    // Place some sample config to test for in the export.
+    $this->data = ['foo' => $this->randomString(), 'bar' => $this->randomString()];
+    $storage = new DatabaseStorage(Database::getConnection(), 'config');
+    $storage->write('test_config', $this->data);
+  }
+
+  /**
+   * Test the command directly.
+   */
+  public function testDbDumpCommand() {
+    $application = new DbDump(Database::getConnection(), $this->container->get('module_handler'));
+    $command = $application->find('db-dump');
+    $command_tester = new CommandTester($command);
+    $command_tester->execute([]);
+
+    // The enabled modules should be present in the docblock.
+    $modules = static::$modules;
+    asort($modules);
+    $pattern = preg_quote(implode("\n *  - ", $modules));
+    $this->assertTrue(preg_match('/' . $pattern . '/', $command_tester->getDisplay()), 'Module list is contained in the docblock of the script.');
+
+    // A module that is not enabled should not be listed.
+    $pattern = preg_quote(" *  - block_content");
+    $this->assertFalse(preg_match('/'. $pattern . '/', $command_tester->getDisplay()), 'Disabled modules do not appear in the docblock of the script.');
+
+    // Tables that are schema-only should not have data exported.
+    $pattern = preg_quote("\$connection->insert('sessions')");
+    $this->assertFalse(preg_match('/' . $pattern . '/', $command_tester->getDisplay()), 'Tables defined as schema-only do not have data exported to the script.');
+
+    // Table data is exported.
+    $pattern = preg_quote("\$connection->insert('config')");
+    $this->assertTrue(preg_match('/' . $pattern . '/', $command_tester->getDisplay()), 'Table data is properly exported to the script.');
+
+    // The test data are in the dump (serialized).
+    $pattern = preg_quote(serialize($this->data));
+    $this->assertTrue(preg_match('/' . $pattern . '/', $command_tester->getDisplay()), 'Generated data is found in the exported script.');
+  }
+
+}
diff --git a/core/scripts/dump-database-d8.php b/core/scripts/dump-database-d8.php
new file mode 100755
index 0000000..4a83b92
--- /dev/null
+++ b/core/scripts/dump-database-d8.php
@@ -0,0 +1,23 @@
+#!/usr/bin/env php
+<?php
+
+use Drupal\Core\Command\DbDump;
+use Drupal\Core\Database\Database;
+use Drupal\Core\DrupalKernel;
+use Drupal\Core\Site\Settings;
+use Symfony\Component\HttpFoundation\Request;
+
+if (PHP_SAPI !== 'cli') {
+  return;
+}
+
+// Bootstrap.
+$autoloader = require __DIR__ . '/../../autoload.php';
+require_once __DIR__ . '/../includes/bootstrap.inc';
+$request = Request::createFromGlobals();
+Settings::initialize(dirname(dirname(__DIR__)), DrupalKernel::findSitePath($request), $autoloader);
+$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
+
+// Run the database dump command.
+$application = new DbDump(Database::getConnection(), \Drupal::moduleHandler());
+$application->run();
