Skip to content

sql:dump

Export the Drupal DB as SQL using mysqldump or equivalent.

Without --result-file the dump is written to standard output. With it, the path of the file is printed, as plain text or with --format as json or yaml, so that a caller can find the dump. There is no automatic file naming; let the shell build a dated path, as in the examples.

Examples

  • sql:dump --result-file=../18.sql
  • sql:dump --result-file=$HOME/drush-backups/$(date -I).sql --gzip
  • sql:dump --skip-tables-list=cache*,sessions,watchdog
  • sql:dump --structure-tables-list=cache*,sessions --result-file=../18.sql --format=json
  • sql:dump --extra-dump=--no-data

Options

  • --result-file=RESULT-FILE. Save to a file instead of writing the dump to standard output. A relative path is relative to the Drupal root.
  • --create-db. Omit DROP TABLE statements. Used by Postgres only, when importing into a freshly created database.
  • --data-only. Dump data without statements to create any of the schema.
  • --ordered-dump. Order by primary key and add line breaks for efficient diffs. Slows down the dump. Mysql only.
  • --gzip. Compress the dump using the gzip program which must be in your $PATH.
  • --extra-dump=EXTRA-DUMP. Add custom arguments/options to the dumping of the database (e.g. mysqldump command).
  • --skip-tables-list=SKIP-TABLES-LIST. A comma-separated list of tables to exclude completely. Wildcards (*) are allowed.
  • --structure-tables-list=STRUCTURE-TABLES-LIST. A comma-separated list of tables to include for structure, but not data. Wildcards (*) are allowed.
  • --tables-list=TABLES-LIST. A comma-separated list of tables to transfer. Wildcards (*) are allowed.
  • --format=FORMAT. Print the path of the dump file as json or yaml. [possible values: yaml, json]
  • --database=DATABASE. The DB connection key if using multiple connections in settings.php. [default: default]
  • --target=TARGET. The name of a target within the specified database connection. [default: default]
  • --db-url=DB-URL. A database URL such as mysql://root:pass@localhost:3306/dbname, used instead of the site's settings.

Global Options

  • -h, --help. Display help for the given command. When no command is given display help for the list command
  • --silent. Do not output any message
  • -q, --quiet. Only errors are displayed. All other output is suppressed
  • -v|vv|vvv, --verbose. Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  • -V, --version. Display this application version
  • --ansi. Force (or disable --no-ansi) ANSI output
  • --no-ansi. Negate the --ansi option.
  • -n, --no-interaction. Do not ask any interactive question
  • --url=URL. A base URL (e.g. example.com). Used for building links, selecting a multi-site, etc.
  • -e, --env=ENV. The Environment name. [default: prod]
  • --no-debug. Switches off debug mode.

Aliases

  • sql-dump

Legend

  • An argument or option with square brackets is optional.
  • Any default value is listed at end of arg/option description.
  • An ellipsis indicates that an argument accepts multiple values separated by a space.