-
Notifications
You must be signed in to change notification settings - Fork 19
Backing up and Restoring Database Snapshots
Outside of Docker, you may be accustomed to using Drush commands like sql-dump
, sql-connect
, and sql-cli
to back-up and restore database snapshots through the CLI. When you start using Drush in a container, these commands are still available but the way you invoke them changes a bit.
Use a command like the following, and run it from within your Drupal install:
docker run -v $(pwd):/app drush/drush sql-dump > my-snapshot.sql
This will create a file called my-snapshot.sql
outside the container in the current working directory.
Use a command like the following, and run it from within your Drupal install:
MYSQL_COMMAND=$(docker run -v $(pwd):/app drush/drush sql-connect)
docker run -v $(pwd):/app run --entrypoint "${MYSQL_COMMAND}" drush/drush < snapshot.sql
This command first invokes sql-connect
to get the command needed to invoke the MySQL CLI client and connect it to the Drupal database. Then it executes that command inside the Drush container and pipes-in the database snapshot.