Themes, Modules, & Backups with Drupal Drush on Debian 7

Drush is a command line tool, which can be used for various Drupal projects. This tutorial uses Drush to install themes, modules, and a manual backup system, covering some basic administration tasks for Drupal websites.

This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, you can check our Users and Groups guide.

Installing Themes with Drush

Downloading, enabling, and setting the theme is extremely easy with Drupal Drush.

Find a theme to download. The Drush download name is usually in the release notes under the “Downloads” section on any drupal.org/project/project_theme theme page. Spaces are either removed or replaced with an underscore. Pictured below is an example. Here, “corporateclean” would be used in the Drush command:

At the time of this guide’s publication, this theme is not yet available for Drupal 8 beta. If you’re using this version of Drupal, select another theme to replace Corporate Clean for this example.

While logged in as the website owner, download and enable the theme:

1

drush en corporateclean -y

Notice the warning that “corporateclean was not found.” The drush en command looks for the theme or module locally before downloading.

Set Corporate Clean as the default, active theme:

1

drush vset theme_default corporateclean

Check the homepage of your site and the new theme should appear.

Installing Modules with Drush

Downloading and enabling a module is similar to working with a theme. However, modules can be used for almost any purpose. From enhancing public-facing functionality to providing a better administrative UI, there are thousands of Drupal modules. Try to find modules with clear documentation. Once installed, the browser interface can still be challenging.

To download a popular module called Commerce, first install the supporting modules. There are several:

1

drush en addressfield ctools entity rules token views views_ui -y

Now that the supporting modules have been installed, download and enable Commerce:

1

drush en commerce -y

Notice that Commerce includes 21 sub-modules. Each has its own functionality and most have a control switch within the admin’s browser interface.

Sign in to the Drupal browser interface and click on the “Modules” selection.

Next, scroll down to the “Commerce” module set, pictured below. Start checking or turning on the different Commerce sub-modules. Finally, select the “Save configuration” button at the very bottom of the page.

You have successfully installed and turned on a new module. The module is now running and ready to be used. In the case of the Commerce module set, notice the new “Store” menu on the Admin’s homepage.

Backup a Drupal Site with Drush

It’s always important to keep regular backups of a website. Backups protect you from losing data due to configuration changes, vulnerabilites, or system failures. Backups should be stored on a separate system whenever possible. Drush has built-in tools to help create backups of your site.

While in the /drupal directory, create a .tar.gz back-up file containing the site database and site files with:

1

drush archive-dump

The site has been backed up locally. Notice the backup has been created and placed in the the /home/user/drush-backups/archive-dump/ directory in a folder time stamped with its creation time. Drush saves your data into a .tar.gz archive file, containing the Drupal site folder and a copy of the MySql database.

To copy the file to a remote backup location, use the rsync command. Replace the date-time-stamp, examplesitename.date-time-stamp.tar.gz, user, ip-address, and /user/ with the appropriate inputs:

This will recreate the drupal folder, which you can then manually move into your web directory.

Automated Backups on Linode with Drush

The backup process above can be automated. You must create an SHH Pair Key, a Bash script, and use Cron automation.

Create SSH Key Pair Authentication without a password for the Linode hosting your Drupal site, and pass the public key to the backup server. This is a simple task. It’s covered in the Using SSH Key Pair Authentication section of the Securing Your Server guide.

On the Drupal hosting Linode, create a Bash script file. In the file excerpt below, replace example.com and the rsync command inputs from step 2 above:

This back up configuration creates a saved version once a week. The Cron timer is set for 12:01 a.m. every Sunday. There are many ways to configure a back up with additional options to consider. Check our Cron guide for more information.

This backup system leaves saved versions of the site and database on both the local and remote Linodes. Depending on the disk size of your Linode, you may want to occasionally delete older backup versions. The deletion task could be automated within the Bash script above. Since the Cron timer is only set for once a week, disk usage is probably not a large concern. There are many configuration options to consider.

Next Steps

This guide was part of a series that created a Drupal site from start to finish on Linode. Your server is complete. Now that everything is installed, master the Drupal interface, Drupal modules, and themes. Create a stunning site for the world to see.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.