a drush primer - drupalcamp chattanooga 2013

31
A Drush Primer DrupalCamp Chattanooga 2013

Upload: chris-hales

Post on 10-May-2015

2.532 views

Category:

Technology


0 download

DESCRIPTION

Drush Primer session slides from my presentation at DrupalCamp Chattanooga which on November 9th, 2013.

TRANSCRIPT

Page 1: A Drush Primer - DrupalCamp Chattanooga 2013

A Drush PrimerDrupalCamp Chattanooga 2013

Page 2: A Drush Primer - DrupalCamp Chattanooga 2013

Chris HalesDevOps Manager

Twitter: @chris_halesIRC: chales

Page 3: A Drush Primer - DrupalCamp Chattanooga 2013

Not on the Agenda

● General Drupal administration

● How to use the terminal

● How to install Drush (RTFM)

● Really deep dive examples (well, just a few)

@Mediacurrent

Page 4: A Drush Primer - DrupalCamp Chattanooga 2013

● What is Drush?

● Some history

● Basic use

● Simple commands to make your life easier

● Drush aliases

● Advanced commands

● Custom combinations

● Drush Make

@Mediacurrent

Agenda

Page 5: A Drush Primer - DrupalCamp Chattanooga 2013

DrushWell over 889,000 downloads

Integration with 276+ modulesPackages available for most systems

Page 6: A Drush Primer - DrupalCamp Chattanooga 2013

What is

Drush?

Page 7: A Drush Primer - DrupalCamp Chattanooga 2013

“A command line shell and

scripting interface for

Drupal.”

www.drush.org

Page 8: A Drush Primer - DrupalCamp Chattanooga 2013

@Mediacurrent

What is it?

The main focus of Drush is to take complex commands that you could perform within the terminal and shorten them into simplified and easy to remember commands.

rsync -vldkogDtprz ssh [email protected]:/var/www/drupal/sites/default/files /local/www/drupal/sites/default/files

Or if you use Drush with an alias setup for your dev site you can use the following command.

$ drush rsync @mysite.dev:%files @mysite.local:%files

Page 9: A Drush Primer - DrupalCamp Chattanooga 2013

@Mediacurrent

History

Drush is a command line utility to assist in Drupal site building, maintenance and administration tasks.

It is a Drupal contrib project but it’s not a module. On *nix systems it’s run as a shell script or a bat on Windows. The guts are written in PHP so most Drupal developers should understand the inner workings.

The first commit to the project was made on Nov 12, 2006 by Arto Bendiken. He made the first few commits that started the 4.x release. Drupal legend Moshe Weitzman has been the primary maintainer for the past few years but he’s had a lot of help. At this time there are 165 contributors to the project.

Page 10: A Drush Primer - DrupalCamp Chattanooga 2013

The current version of Drush is version 7 which is compatible with Drupal 6, 7 and 8.

The Drush project moved to Github in August 2013 however you can still find general info on the original Drupal hosted project page.http://drupal.org/project/drush

Look for Drush at it’s new home on Githubhttps://github.com/drush-ops/drush

@Mediacurrent

History

Page 11: A Drush Primer - DrupalCamp Chattanooga 2013
Page 12: A Drush Primer - DrupalCamp Chattanooga 2013

The

Basics

Page 13: A Drush Primer - DrupalCamp Chattanooga 2013

Review the Drush documentation online

http://www.drush.org/help/docs

Resources on Drupal.org

https://drupal.org/node/477684

https://drupal.org/drush-faq

http://www.drush.org/resources

https://groups.drupal.org/node/28088

Drush itself has a very extensive help system

$ drush --help

$ drush help <command>

@Mediacurrent

Getting Help

And don’t forget Google is your friend!

Page 14: A Drush Primer - DrupalCamp Chattanooga 2013

@Mediacurrent

The BasicsTo use Drush with remote hosts you must use SSH keys!

Drush can perform some commands against remote sites without the need for Drush to be installed on the remote.

You must be within the context of a fully functional Drupal site to use most commands. For multisites drill into the site directory with the settings.php file of the site you wish to work with. If you see the following error you are not within a functional site.

Command <command> needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to run this command. [error]

A Drupal installation directory could not be found

Page 15: A Drush Primer - DrupalCamp Chattanooga 2013

The main command structure usually looks like this.

$ drush <cmd> [[arg1] [arg2]...] [[option1] [option2]...]

Drush commands are usually in the form of

$ drush <command> <from site> <to site>

Common options that remove interaction.-y(es) -n(o)

$ drush <command> <from site> <to site> -y

@Mediacurrent

Commands

Page 16: A Drush Primer - DrupalCamp Chattanooga 2013

Here are a few of the common admin tasks.

● Clear caches

● Install modules

● Update modules

● Run update.php

● Update configuration settings

● Manual cron runs

● Updating users

@Mediacurrent

Common Tasks

Page 17: A Drush Primer - DrupalCamp Chattanooga 2013

Check your site status.$ cd /path/to/drupal/docroot

$ drush st Drupal version : 6.28

Site URI : mysite.dev

Database driver : mysqli

Database username : user

Database password : pass

Database name : ag_www

Database : Connected

Drupal bootstrap : Successful

Drupal user : Anonymous

@Mediacurrent

Site Status

Page 18: A Drush Primer - DrupalCamp Chattanooga 2013

Default theme : mytheme

Administration theme : seven

Administration theme : seven

PHP executable : /path/to/php

PHP configuration : /path/to/conf/php.ini

PHP OS : Darwin

Drush version : 6.0

Drush configuration : "/path/to/drush/drushrc.php"

Drush alias files : ~/.drush/my.drushrc.php

Drupal root : /path/to/docroot

Site path : sites/mysite.dev

File directory path : sites/default/files

Temporary file directory path : /tmp

@Mediacurrent

Site Status

Page 19: A Drush Primer - DrupalCamp Chattanooga 2013

Clearing caches.$ cd /path/to/drupal/docroot$ drush ccEnter a number to choose which cache to clear. [0] : Cancel [1] : all [2] : drush [3] : theme-registry [4] : menu [5] : css-js [6] : block [7] : module-list [8] : theme-list [9] : registry [10] : views

@Mediacurrent

Clearing Cache

Page 20: A Drush Primer - DrupalCamp Chattanooga 2013

Clear all caches.$ cd /path/to/drupal/docroot

$ drush cc all

'all' cache was cleared in mysite.local [success]

Clear just a specific cache such as the CSS/JS cache$ cd /path/to/drupal/docroot

$ drush cc css-js

'css-js' cache was cleared in mysite.local [success]

@Mediacurrent

Clearing Cache

Page 21: A Drush Primer - DrupalCamp Chattanooga 2013

Download the module.$ cd /path/to/drupal/docroot

$ drush dl schema

Project schema (6.x-1.7) downloaded to

sites/all/modules/contrib/schema. [success]

Then enable the module.$ drush en schema

schema was enabled successfully. [ok]

You can also combine the commands.$ drush dl scheme && drush en schema -y

@Mediacurrent

Install Modules

Page 22: A Drush Primer - DrupalCamp Chattanooga 2013

View a list of available module updates.(output abbreviated)

$ cd /path/to/drupal/docroot

$ drush upName Installed Version Proposed version Message

context 6.x-3.1 6.x-3.3 SECURITY UPDATE available

ctools 6.x-1.10+2-dev 6.x-1.0 Update available

features 6.x-1.x-dev 6.x-1.2 Update available

filefield 6.x-3.10 6.x-3.11 Update available

Do you really want to continue with the update process? (y/n):

@Mediacurrent

Update Modules

Page 23: A Drush Primer - DrupalCamp Chattanooga 2013

Update one or more modules by specifying them. The new version will be downloaded, any database updates executed and caches cleared.(output abbreviated)

$ cd /path/to/drupal/docroot

$ drush up context features Do you really want to continue with the update process? (y/n): y

Project context was updated successfully. Installed version is

now 6.x-3.3.

Backups were saved into the directory /backups/context. [ok]

'all' cache was cleared in mysite.local [success]

No database updates required [success]

'all' cache was cleared in mysite.local [success]

Finished performing updates. [ok]

@Mediacurrent

Update Modules

Page 24: A Drush Primer - DrupalCamp Chattanooga 2013

Advanced

Page 25: A Drush Primer - DrupalCamp Chattanooga 2013

Drush aliases allow your to target the context of a site much easier.

$ cd /path/to/drupal/docroot$ drush sa --full --with-optional @self$aliases["self"] = array ( 'root' => '/path/to/site/docroot', 'uri' => 'http://default', '#name' => 'self', 'path-aliases' => array ( '%drush' => '/path/to/php/drush', '%site' => 'sites/default/', ),);

@Mediacurrent

Drush Aliases

Page 26: A Drush Primer - DrupalCamp Chattanooga 2013

Once you create an alias file and name the sites you wish to interact with you can target the sites’ context and run any command against it.For a full featured alais template you can use mine as a starting point, https://gist.github.com/chales/2635760

Download a module to the local site.$ drush @mysite.local dl admin_menu

Check production status.$ drush @mysite.prod st

Clear caches on the staging site.$ drush @mysite.stage cc all

@Mediacurrent

Drush Aliases

Page 27: A Drush Primer - DrupalCamp Chattanooga 2013

Now you can use alias shortcuts to perform commands such as syncing your local site to the production site.

Sync the files in sites/default/files using the files path alias.$ drush rsync @mysite.prod:%files @mysite.local:%files

Sync the database using sql-sync.$ drush sql-sync @mysite.prod @mysite.local

@Mediacurrent

Drush Aliases

Page 28: A Drush Primer - DrupalCamp Chattanooga 2013

Backup a database.$ drush sql-dump --result-file=dump.sql

Backup a database using gzip compression.$ drush sql-dump --gzip --result-file=dump.sql.gz

Similar but you can just use the command output and write it to a file.$ drush sql-dump > /path/to/dump/file.sql

To restore this dump file you can use the Drush sql-query command.$ drush sqlq < /path/to/dump/file.sql

@Mediacurrent

Database Dumps

Page 29: A Drush Primer - DrupalCamp Chattanooga 2013

You can install a full Drupal site.$ cd /path/to/drupal/docroot

$ drush si --db-url=mysql://root:[email protected]/test_d7

--account-pass=abc123

(assumes you have a database setup already)

If you need to add the database you can also use the superuser options which will then create the database as well.--db-su=name --db-su-pw=password --account-

pass=myadminpass

@Mediacurrent

Site Install

Page 30: A Drush Primer - DrupalCamp Chattanooga 2013

List all available variables.$ drush variable-get

Set maintenance mode.$ drush variable-set maintenance_mode 1

maintenance_mode was set to "1". [success]

Disable maintenance mode.$ drush variable-set maintenance_mode 0

maintenance_mode was set to "0". [success]

@Mediacurrent

Variables

Page 31: A Drush Primer - DrupalCamp Chattanooga 2013

Thank You!

Questions?@chris_hales Mediacurrent.com

slideshare.net/chris_hales