Home
/
Drupal Tutorials
/
Drush Tutorial

Drush Tutorial

Drush is a command line interface that allows managing your Drupal web sites fast and easy. This scripting shell should be additionally installed on your hosting server in order to benefit from its features. It is pre-installed on the SiteGround servers and you can use it with your Web Hosting package.

First, you need to have a Drupal installation under your hosting account. It can be completed in several mouse clicks through Site Tools > Dev > App Installer.

Second, you need SSH access to your account to run Drush commands.

This tutorial explains how to use Drush in order to back up and update your script, install and activate Drupal extensions, remove them and clear the script’s cache.

Backup Website with Drush

To create a backup of your Drupal web site using Drush, log in to your account via SSH. Detailed instructions on how to use SSH can be found in our SSH tutorial. After you log in to your account via SSH, navigate to the Drupal installation’s home folder.

Then run the following command:

drush archive-dump --destination=/home/customer/service/www/domain.com/backup/site.tar.gz

Replace domain.com with your actual domain name. You can pick a different location for the backup and different backup file name. Executing the command above will create an archive with all the website files and a copy of your Drupal database. The output would be similar to the following one:

Database dump saved to /tmp/drush_tmp_1510221289_5a0425e916e33/USER_drup.sql [success]
Archive saved to /home/customer/service/www/domain.com/backup/site.tar.gz [ok]

After the process is successfully completed, you will be able to find the backup in the specified location – /home/USER/backup/site.tar.gz.

Restore Website with Drush

If you need to restore a backup of your website, use the following command:

drush archive-restore /home/customer/service/www/domain.com/backup/site.tar.gz

The output will be similar to:

Archive restored to /home/customer/service/www/domain.com/newdrupal [ok]
/home/USER/public_html/newdrupal

Upgrade Website with Drush

To upgrade the Drupal core, use the command below:

drush ups

After the application’s core is upgraded, you should make sure to update the database as well:

drush updb

Update entity, if any required entity updates are needed:

drush entup

Install, Enable and Uninstall Plugin with Drush

To install a chosen plugin you should download and enable it. Check the example listed below:

drush dl addtoany

The output would be similar to:

Project addtoany (8.x-1.8) downloaded to /home/customer/service/www/domain.com/public_html/drupal/modules/addtoany. [success]

To enable the installed module, you should run the command below:

drush en addtoany
The following extensions will be enabled: addtoany
Do you really want to continue? (y/n): y
addtoany was enabled successfully. [ok]
addtoany defines the following permissions: administer addtoany

Instead of AddToAny, you can pick a different Drupal plugin or module. To skip the Do you really want to continue? prompt modify the command in the following way:

drush en -y addtoany

A chosen extension can be disabled and removed with the command below:

drush pm-uninstall addtoany
The following extensions will be uninstalled: addtoany
Do you really want to continue? (y/n): y
addtoany was successfully uninstalled.

Clear Cache with Drush

Often you would need to clear the script’s cache. It can be easily completed with the following command:

drush cache-clear
Enter a number to choose which cache to clear.
[0] : Cancel
[1] : drush
[2] : theme-registry
[3] : menu
[4] : css-js
[5] : module-list
[6] : theme-list
[7] : render
[8] : views

If you prefer to clear all types of cache at once, the following command is available:

drush cache-rebuild
Cache rebuild complete. [ok]

Drush Help

To get help on the Drush commands run the following command:

drush help

If you want to learn how to use a specific command enter the following line in the shell:

drush help command

Replace the command string with the chosen one. For example:

drush help archive-backup

More about Drush may be found in the official documentation of the project: https://www.drush.org/

Share This Article