Bobcares

Drupal Drush Import Database: How to?

by | Jun 10, 2023

Let us learn how to do the drupal drush import database with the support of our Drupal support services at Bobcares.

drupal drush import database?

Consider that we have Drush set for the source version of the application; we can synchronize them using drush.

Use the drush sql:sync command to import a single website’s database from a drush alias source, substituting [source] and [target] with the Drush aliases for the source and target databases.

Due to the fact that Drush 9 and later no longer allow two remote targets, you must configure one Drush alias to be local by issuing the command from either application.

drupal drush import database

After the import is finished, use the drush @[target] cr command to rebuild caches.

Dump and restore databases

To import a database using command-line tools, follow these steps:

  1. Firstly we have to create a dump file of the database.
  2. After that, in the new database, import the dump file.
  3. Configure database connections.

Creating a database dump file

To export the data contained in the website’s database, use the command line to produce a database dump file by executing Drush or mysqldump from the Drupal directory.

A dump from aliases wont generate reliably in Drush 9 and later because it ignores output redirection.

Instead, we must navigate to the Drupal source directory and execute the following command:

drupal drush import database

Drush saves the mysite.sql.gz site archive file relative to the current Drupal docroot.

If needed, move the file to a location that has access to the target environment.

When the command returns error messages, ensure Drush has the required permissions to save files in the docroot directory.

If we are not sourcing from the default site, we must provide a matching URI for Drush to choose the relevant site database.

drupal drush import database

Finally, import the database dump file created from the existing database into the new database when we create it.

Importing the database dump file

Follow the steps given below for importing a database dump file into a Cloud Platform subscription:

  • Firstly we have to use the SSH to connect to the Cloud Platform.
  • After that, upload the database backup to Cloud Platform with instructions similar to those shown in the Downloading backups with command line tools section.

    Change the command to upload from the local computer to Cloud Platform.

  • Import the database dump file using one of the techniques listed below:

    A: Use the drush sql:cli command to import a database dump file to the default site, substituting [target] with the Drush alias for the target site:

    drupal drush import database

    B: If we’re not using the default site, we’ll need to supply URI as a CLI option or via a custom Drush alias:

    drupal drush import database

    We may now use Secure File Transfer Protocol (SFTP), Secure Copy (SCP), or rsync to import files.

Variable legend

The values of the variables used in the preceding commands are listed in the legend below.

  • [site]: The name of the Cloud Platform application.
  • [env]: The environment into which the database will be imported. Dev (Development), test (Staging), and prod (Production) are acceptable options.
  • [db_name]: The database’s name. For the environment, use the database name from the Databases page rather than an environment-specific name.

    For example, if the sitename is an example, the default database name is likely to be example, and we should use it instead of an environment-specific name (such as exampledev or exampletest).

[Need assistance with similar queries? We are here to help]

Conclusion

To sum up we have now seen how to do the drupal drush import database with the support of our tech support team.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.