Updating all of your Drupal Sites at Once - aka Lazy Person's Aegir

Aegir is an excellent way to manage multi site drupal instances, but sometimes it can be a bit too heavy. For example if you have a handful of sites, it can be overkill to deploy aegir. If there is an urgent security fix and you have a lot of sites (I am talking 100s if not 1000s) to patch, waiting for aegir to migrate and verify all of your sites can be a little too slow.

For these situations I have a little script which I use to do the heavy lifting. I keep in ~/bin/update-all-sites and it has a single purpose, to update all of my drupal instances with a single command. Just like aegir, my script leverages drush, but unlike aegir there is no parachute, so if something breaks during the upgrade you get to keep all of the pieces. If you use this script, I would recommend always backing up all of your databases first - just in case.

I keep my "platforms" in svn, so before running the script I run a svn switch or svn update depending on how major the update is. If you are using git or bzr, you would do something similar first. If you aren't using any form of version control - I feel sorry for your clients.

So here is the code, it should be pretty self explanatory - if not ask questions via the comments.

#!/bin/sh # Update all drupal sites at once using drush - aka lazy person's aegir # # Written by Dave Hall # Copyright (c) 2009 Dave Hall Consulting http://davehall.com.au # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # Alternatively you may use and/or distribute it under the terms # of the CC-BY-SA license http://creativecommons.org/licenses/by-sa/3.0/ # Change this to point to your instance of drush isn't in your path DRUSH_CMD="drush" if [ $# != 1 ]; then     SCRIPT="`basename $0`"     echo "Usage: $SCRIPT path-to-drupal-install"     exit 1; fi SITES_PATH="$1" PWD=$(pwd) cd "$SITES_PATH/sites"; for site in `find ./ -maxdepth 1 -type d | cut -d/ -f2 | egrep -v '(.git|.bzr|.svn|all|^$)'`; do     if [ -f "${site}/settings.php" ]; then         echo updating $site         $DRUSH_CMD updatedb -y -l $site     fi done # Lets go back to where we started cd "$PWD"

OK, so my script isn't any where as awesome as aegir, but if you are lazy (or in a hurry) it can come in handy. Most of the time you will probably still want to use aegir.


Make sure you make the script executable (hint run chmod +x /path/to/update-all-sites)

If you don't have drush in your path, I would recommend you add it, but if you can't then change DRUSH_CMD="drush" to point to your instance of drush - such as DRUSH_CMD="/opt/drush/drush".

Thanks to Peter Lieverdink (aka cafuego) for suggesting the improved regex.

Broken script

Rafael wrote:

Nice script,

But hey, the script is unreadable through the web, can you correct that.


Added Wed, 2009-12-09 02:42


greggles wrote:

I was working on this for a few hours the other day and got stuck on how to print out just the directory name. The answer: CUT! How could I forget about my old friend cut :(

Thanks for sharing this. I think you could simplify it a bit by using the "-exec drush -l {} updatedb -y" argument to find. That gets rid of the pretty message, but maybe a separate "-printf" could help add a pretty message.

Thanks again!

Added Wed, 2009-12-09 05:12


Dave wrote:

@Rafael - Fixed the formatting, sorry about that. I forgot to check it online after publishing it.

@greggles - I like to filter the rubbish, but I agree the message is optional. Happy for you to link to an improved version in the comments.

Added Wed, 2009-12-09 10:06

great script

Ted wrote:

I didn't even know that Aegir can make the site bit heavier.Thank you for sharing this code to us.I can already resume doing my program.


Added Thu, 2010-07-22 22:01

Link is offline?

watch megamind online wrote:

Thanks for sharing the link, but unfortunately it seems to be offline... Does anybody have a mirror or another source? Please reply to my post if you do!

I would appreciate if a staff member here at davehall.com.au could repost it.

Thanks, Peter

Added Sat, 2010-10-23 18:00

RE: Link is offline?

Dave wrote:

I am not sure which link you are referring to.

Added Thu, 2010-10-28 11:48