Got a new web project? Request a quote

drush

Do you have a backup strategy? 3 tools to save your day

For drupal we have a number of different methods to backup the database. Having a backup strategy is one of the easiest things to do but is often overlooked. Perform regular backups to keep your sanity when disaster hits. Implement a backup strategy for daily weekly and monthly backups and look cool to the client. I am going to discuss about 3 different tools to backup your database. Read on so you have no excuse.

Use drush to add a component to a feature like a drupal pro

Features is one of those modules we can not do without. One annoying issue with features is that it is slow. The bigger the drupal site, the slower the features UI pages load. And waiting for the page to load is one of the most disturbing things during drupal development.

Adding a new component to a feature is a multistep process: Go the features page, add the component to the feature, download the feature, remove the old feature and extract the new one. And repeat many times during the day.

Fortunately, we can speed this process quite a bit. Drush to the rescue again! This post is going to explain how to use drush to add new components to a feature.

How to write drush commands and hooks

I clearly remember the moment of excitement and joy couple of years ago when I discovered drush. Interacting with drupal from the command line? Wow! This was definitely something new to me, never seen it before in any cms.
Digging more, I discovered the wp-cli for the wordpress, but it seems that this in no way as mature as drush.

I use drush on a daily basis. For simple tasks such as clearing the caches or updating a feature to more complex stuff like in a deployment process or as an interactive php shell.

As with drupal, drush can also be extended. It is just a matter of writing the proper hook in the proper file. It is really simple and everyone can write their own drush commands.

As an example, I am going to show you how you to trigger a node save.

Find and export variables with drush or features

Features is a must have tool for deploying drupal sites. Features can be used for storing the website configuration in files, instead of the database. It can for example allow you to store a view in a file. You can then commit this code to your repo as usual.
Must of the site's configuration is stored in variables. Features, when used with strongarm, can be used to also export those variables from your staging env to your production. You can always find the name of the variable, by inspecting the html code. I use another trick to easily locate the variable name:

You can use

drush vget

to get the value of variable. For example,

drush vget cache

will return 1 or 0, depending on the value of the caching parameter set in admin/config/development/performance. If you dont know exactly the name of the variable, you can for example do a

Copy a remote database or backup with drush

I use drush a lot during development. A common task is to restore the database or copy the database from the stg server to my local machine.
A lot of people use Backup and migrate to do this which works fine but is just too many steps for me. With drush, this can be as long as a single command:

drush sql-sync @site-dev @self --sanitize

This command will copy the db from the dev server to the local machine.
The --sanitize switch will sanitize the email addresses and the passwords of the users. This way, you will be sure that there will no email accidentally sent from the devel machine.
Be carefull, not to switch the order of @site-dev and @self or you will copy the local db to the dev server.
It is usually good to do a:

drush sql-drop

before running the sql-sync command. This will drop the local db and it will likely save you some time troubleshooting.