After years wasting time on drupal/sql backups, drupal restores, drupal updates etc, I started using the powerful drush command.
If you don’t know it “drush” is simply a (dru)pal (sh)ell written in PHP. It has been developed by core drupal developers to assist sysadmin and developers in everyday site management.
First, to install drush in a typical Debian/Ubuntu server, you need to install the PHP Extension and Application Repository (PEAR) which hosts drush. Simply type:
apt-get install php-pear
Then to install drush, use the following two commands:
pear channel-discover pear.drush.org
pear install drush/drush
Now you should be okay. Just check with
You should see something like
Now, you can start using drush.
The drush command needs some “Drupal root” directory to work with. That is the directory on a Drupal installation. If you don’t specify it, it assumes your Drupal root directory is the current one. For instance, if you have a site installed at /var/www/supersyntages.gr you can check its status with the command:
drush -r /var/www/supersyntages.gr status
or with the combination
In both cases, you’ll get something like
Drupal version : 6.29 Site URI : http://default Database driver : mysql Database hostname : localhost Database username : cthulu Database name : bloodyrecipes Database : Connected Drupal bootstrap : Successful Drupal user : Ανώνυμος Default theme : myawesomethme Administration theme : 0 PHP configuration : /etc/php5/cli/php.ini Drush version : 5.9 Drush configuration : Drupal root : /var/www/supersyntages.gr Site path : sites/default File directory path : sites/default/files Temporary file directory path : /tmp
From now on, I assume we are using the current directory as our Drupal root dir.
So, to backup all your Drupal files plus the MySQL database to a single file, you only need
You will get a single backup tarball in /root/drush-backups/archive-dump/currentdate
If you have already backed up a drupal installation, you can restore it with:
To see if anything’s wrong with your installation — essentially show what you would normally see in the status admin page:
or more essentially, make it show only the red lines from the status admin page:
drush rq --severity=2
You will get a list with all things you would normally see in /admin/settings/status plus a list with all modules which need update.
To update drupal core and modules (and apply dateabase update) in the current installation, you just type:
First, drush will tell you what exactly it will do, and you will be prompted to continue. If you press Y, you will have an updated Drupal installation in less than 5 minutes.
Then check your Drupal installation status again:
or you can have a birds-eye view of the current Drupal installation, using
To clear all caches, without a single click:
drush cc all
Of course there are dozens of more interesting drush commands.
For instance, to download and install some a PDF library, i.e. tcpdf
drush pdfdl tcpdf
To see all installed modules and thems:
or just modules
drush pm-list --type=module
or just non-core modules
drush pm-list --type=module --no-core
To refresh the module update status:
To uninstall a module/theme, i.e. Scheduler, you use:
drush pm-uninstall scheduler
To print release information for a given module/theme:
drush rl scheduler
To download some other module/theme from drupal.org, i.e. mytinytodo and zen theme:
drush dl mytinytodo zen
or make it prompt you for the version you want to download:
drush dl zen --select
If you have a Drupal installation you want to use as a template for future projects, just generate a “makefile” from it:
drush make-generate supersyntages.make
When you need to setup a new Drupal installation from your supersyntages.make makefile, use the following command to set up the new site inside the “newsitedir” folder:
drush make supersyntages.make newsitedir
With drush creating and deleting a user could not be simpler:
drush ucrt dimitris
drush ucan dimitris
To change the password for a user, you use:
drush upwd dimitris
If you have search index issues, you can see how many search items remain unindexed, with:
To force Drupal to index any remaining search items:
To see a list of site variables:
To run cron in all active modules:
To disable all non-core modules (you’ ll need it when you upgrade to a major version of Drupal):
drush pm-disable `drush pm-list --no-core --type=module --pipe`
And, finally, to see the last 20 watchdog messages:
drush ws 20
or you can search for cron messages only:
drush watchdog-show "cron"
For drush commands or info about each one of them, just use the drush command alone or drush help topic where “topic” is some command, i.e. drush help ws