Pages

Saturday, April 5, 2014

Drush - Drupal Command Line interface

Drush is a command line interface that allows to manage 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. 
First, you need to have a Drupal installation under your hosting account. It can be completed in several mouse clicks through cPanel -> Softaculous.
Second, you need SSH access to your account in order to run Drush commands.
In this part of the Drupal tutorial we will show how to use Drush in order to backup and update your script, install and activate Drupal extensions, remove them and clear the script’s cache.
In order to create a backup of your Drupal web site with Drush follow the steps listed below:
  1. Log in your account via SSH. 
  2. Navigate to the Drupal installation’s home folder.
  3. Run the following command:
drush archive-backup –destination=/home/cPuser/backup/site.tar.gz
Replace the cPuser variable with your actual cPanel user. You can pick a different location for the backup and different backup file name.
Executing the command listed above will create an archive with all the web site files and a dump of your Drupal database.
The output will be similar to the following one:
Drupal version                  :  7.22
Site URI                        :  http://default
Database driver                 :  mysql
Database username               :  cPuser_drup709
Database name                   :  cPuser_drup709
Database                        :  Connected
Drupal bootstrap                :  Successful
Drupal user                     :  Anonymous
Default theme                   :  bartik
Administration theme            :  seven
PHP configuration               :  /usr/local/php54/lib/php.ini
Drush version                   :  6.0-dev
Drush configuration             :
Drush alias files               :
Drupal root                     :  /home/cPuser/public_html/drupal
Site path                       :  sites/default
File directory path             :  sites/default/files
Temporary file directory path:/tmp
Archive saved to /home/cPuser/backupD/site.tar.gz
If you need to restore a backup of your web site use the following command:
drush archive-restore /home/cPuser/backup/site.tgz
The output will be similar to:
Archive restored to /home/cPuser/public_html/drupal                         [ok]
To update the Drupal application execute the following command:
drush pm-update
Checking available update data …                                          [ok]
Checked available update data for Block.                                    [ok]
Checked available update data for one project.                          [status]
Name    Installed Version  Proposed version  Message
Drupal  7.20               7.22              Update available
Update information last refreshed: Thu, 06/06/2013 – 11:18
Update status information on all installed and enabled Drupal projects:
Code updates will be made to drupal core.
WARNING:  Updating core will discard any modifications made to Drupal core files, most noteworthy among these are .htaccess and robots.txt.  If you have made any modifications to these files, please back them up before updating so that you can re-create your modifications in the updated version of the file.
Note: Updating core can potentially break your site. It is NOT recommended to update production sites without prior testing.
Do you really want to continue? (y/n): y
Project drupal was updated successfully. Installed version is now 7.22.
Backups were saved into the directory                                       [ok]
/home/cPuser/drush-backups/cPuser_drup709/20130606113109/drupal.
‘all’ cache was cleared in self                                        [success]
No database updates required                                           [success]
‘all’ cache was cleared in self                                        [success]
Finished performing updates.                                                [ok]
The above command will also update the plugins.
To install a chosen plugin you should download and enable it. Check the example listed below:
drush dl addtoany
Project addtoany (7.x-4.0) downloaded to sites/all/modules/addtoany.   [success]
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
Your AddToAny settings are available under Configuration > System    [status] > AddToAny
Instead of AddToAny you can pick a different Drupal plugin or module. The 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 two simple commands. Check the example:
drush dis -y addtoany
The following extensions will be disabled: addtoany
Do you really want to continue? (y/n): y
addtoany was disabled successfully.    
drush pm-uninstall -y addtoany
The following modules will be uninstalled: addtoany
Do you really want to continue? (y/n): y
addtoany was successfully uninstalled.
Often the Drupal web site administrators need to clear the script’s cache. It can be easily completed with the following command:
drush cache-clear all
‘all’ cache was cleared in self                                        [success]
If the webmaster prefers to clear different types of cache the options can be listed:
drush cache-clear
Enter 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
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 can be found in the official documentation of the project: http://drush.ws/

No comments:

Post a Comment

Thanks for your comment.