A collection of Drupal Drush one liners and commands

Some quick one-liners that can come in handy when using drush, Drupal’s command line interface.

These were originally written for Drush 7 on Drupal 7, where almost everything was a variable_set (vset). Drupal 8 dropped the variable system in favour of config and state, so on a current site (Drush 9 and up) you use state:set, config:set and cache:rebuild instead. Both forms are listed below.

Place all websites in Drupal maintenance mode#

# Drupal 8+ (Drush 9+)
$ drush @sites state:set system.maintenance_mode 1 --input-format=integer

# Drupal 7 (Drush 7)
$ drush @sites vset site_offline 1

Place a specific multi-site website in maintenance mode#

# Drupal 8+ (Drush 9+)
$ drush -l site_alias_name state:set system.maintenance_mode 1 --input-format=integer

# Drupal 7 (Drush 7)
$ drush -l site_alias_name vset site_offline 1

Take all sites out of maintenance mode#

# Drupal 8+ (Drush 9+)
$ drush @sites state:set system.maintenance_mode 0 --input-format=integer

# Drupal 7 (Drush 7)
$ drush @sites vset site_offline 0

Set the page cache max-age for all sites to 1800 seconds#

# Drupal 8+ (Drush 9+) -- there is no cache_lifetime anymore
$ drush @sites config:set system.performance cache.page.max_age 1800

# Drupal 7 (Drush 7)
$ drush @sites vset cache_lifetime 600
$ drush @sites vset page_cache_maximum_age 1800

List all sites in a multi-site drupal setup#

$ drush @sites status
You are about to execute 'status' non-interactively (--yes forced) on all of the following targets:
  /var/www/html/site#multisite_A
  /var/www/html/site#multisite_B
Continue?  (y/n):
...

Flush all caches (varnish, memcached, …)#

# Drupal 8+ (Drush 9+)
$ drush @sites cache:rebuild   # or the short form: drush @sites cr

# Drupal 7 (Drush 7)
$ drush @sites cc all

Disable drupal’s cron#

# Drupal 8+ (Drush 9+) -- automated cron lives in the system.cron config
$ drush @sites config:set system.cron interval 0

# Drupal 7 (Drush 7)
$ drush @sites vset cron_safe_threshold 0

If you know any more life-saving drush commands (you know the kind, the ones you need when all hell breaks loose and everything’s offline), let me know!