Drupal 8 - Drush Cheat Sheet

Submitted by TheMain on Thu, 04/06/2017 - 18:11

Selection of useful Drush commands for Drupal 8.


# Backup site database into a folder ~/db_dumps (sql-dump):

drush sql-dump > ~/db_dumps/MYSITEBACKUP.sql

# Import database (sql-cli):

drush sqlc < ~/db_dumps/MYSITEBACKUP.sql

# Flush caches and backup site database into a folder ~/db_dumps archiving the packet with gzip and using the current date in the filename:

drush cr && drush sql-dump | gzip -9 > ~/db_dumps/MYSITEBACKUP-$(date +%Y-%m-%d-%H.%M.%S).sql.gz

# Import gz archived dump:

gunzip < ~/db_dumps/MYSITEBACKUP.sql.gz | drush sqlc

# Create archive (backup database, files and code). Stored by default in ~/drush-backups (archive-dump):

drush ard

# Restore archive (archive-restore):

drush arr ARCHIVEFILE.tar.gz


# Rebuild and clear caches (cache-rebuild):

drush cr

# Clear a specific cache (or all) (cache-clear):

drush cc

# Clear CSS & JS:

drush cc css-js


# List configuration names (config-list):

drush cli

# Export configuration (config-export):

drush cex

# Import configuration (config-import):

drush cim


(These require the Devel module: https://www.drupal.org/project/devel)

# Generate nodes (10 nodes with maximum of 5 comments) (generate-content):

drush genc 10 5

# Generate menus (2 menus with 2 links) (generate-menus):

drush genm 2 2

# Generate terms (2 terms for tags vocabulary) (generate-terms):

drush gent tags 2

# Generate users (10 users) (generate-users):

drush genu 10

# Generate vocabularies (2 vocabularies) (generate-vocabs):

drush genv 2

Download and Installation

# Download and install one module (pm-enable):

drush -y en devel

# Download and install multiple useful modules (run twice):

drush -y en admin_toolbar admin_toolbar_tools fpa coffee

# Download admin_toolbar module to the /modules folder (pm-download):

drush dl admin_toolbar

# Download latest stable Drupal to a folder mysite:

drush dl drupal --drupal-project-rename=mysite

# Download latest stable Drupal 7 to a folder mysite:

drush dl drupal-7 --drupal-project-rename=mysite

# Install Drupal using standard profile (site-install):

drush si standard --db-url='mysql://root:root@localhost/MYDATABASE' --site-name=MYSITENAME --account-name=admin --account-pass=admin


# Get temporary login url (user-login):

drush uli

# Show Drush version:

drush version


# Update database (RUN THIS AFTER UPDATES) (updatedb):

drush updb

# Update core (pm-update):

drush up drupal

# Update a module:

drush up admin_toolbar

# Update all modules EXCEPT core (pm-updatecode):

drush upc --no-core

# Update all modules AND core:

drush upc

More commands and options: https://drushcommands.com/

Posted by Samuli Natri on 06 April 2017