Drush

Drush PHP Memory Limit

I was banging my head against the wall this morning because Drush kept telling me that I was exhausting PHP's memory at 128MB. I finally figured out the problem and thought I'd share for others searching the internet for a solution.

The first thing I did was check my php.ini file. Sometimes PHP on the command line will use a different php.ini file than the Apache version. In my case, the php.ini file is shared for both.

Drupal upgrade script

EDIT: The script below has been updated to work with Drush 3.x. Those using previous versions of Drush will need to edit the script appropriately. The nature of the change was to use the new Drush 3.x standard of no spaces with command names, so "drush sql dump" was changes to drush sql-dump."

Before using this script, make sure that all your contributed themes and modules are somewhere in the "sites/" directory. If they are in any other Drupal core directories, your modules and themes will be lost.

I run a handful of small Drupal sites that I can't afford to spend too much maintenance time on, but that still need to be updated with the occasional maintenance version of Drupal.

It can be quite time-consuming to manually update 4 or 5 sites each time a security release is published.

So, a couple months ago I spent an afternoon writing a shell script to automate the whole task. With a little help from Drush, it turns a 10 or 15 minute maintenance task into about 10 or 15 seconds.

Here's what it looks like.

Using drush to load a database file

Note: Updated Dec. 5, 2011 to reflect the latest changes in drush commands.

I backup databases, sometimes several times a week using drush.

$ drush sql-dump --result-file=backup.sql

(By the way, using the --result-file option instead of a redirect to prevent corrupting the charset in your data).

However, when reloading a backup I would always use the mysql command directly because drush doesn't have an import command.