I have a multisite installation with common modules code (all modules are in sites/all/modules). When I update the modules, after that I need to update the database of each site with drush updatedb -l site.com It is a time consuming task to do this for each site. Is there a way to batch update the database in multiple sites?

Thanks

up vote 4 down vote accepted

I believe drush v4.4 and above support drush @sites updb.

  • thanks. is this @sites a kind of variable? are more @...things exist? where exactly in drush.ws site is this documented? I had a look and did not find. thanks – john Oct 9 '11 at 15:09
  • @john Perhaps you can post this as a separate question because I don't have a comprehensive list of these features of drush myself. The @sites was something I stumbled upon. – nmc Oct 9 '11 at 15:18

Here is a script I wrote for different time consuming tasks to run on a multisite installation

The file has to be in your sites folder.

The script will loop through all folders (except all and default) to run the command choosen on every sites based on their settings.php file

#!/bin/bash

# Get all Drupal sites
sites=`find . -maxdepth 1 -type d -print | grep -v '/all$' | grep -v '/default$' | grep -v '\.$'`

echo "Choose the commande to execute : "
echo "1. update"
echo "2. put sites offline"
echo "3. put sites online"
echo "4. clear all cache"
echo "5. clear css+js cache"
echo "6. clear specific cache"
echo "7. install specific module"
echo "8. disable specific module"
echo -n "Input [1,2,3,4,5,6,7 or 8] ? "
read choice

if [ $choice -gt 6 ] ; then
  echo -n "Extension (module/theme) name ?"
  read ext
fi

# For each site, execute the command
for site in $sites
do
  echo ----------
  echo $site
  cd $site  
  if [ $choice -eq 1 ] ; then
    drush updatedb
  elif [ $choice -eq 2 ] ; then
    drush vset --always-set maintenance_mode 1
  elif [ $choice -eq 3 ] ; then
    drush vset --always-set maintenance_mode 0
  elif [ $choice -eq 4 ] ; then
    drush cc all
  elif [ $choice -eq 5 ] ; then
    drush cc css+js
  elif [ $choice -eq 6 ] ; then
    drush cc
  elif [ $choice -eq 7 ] ; then
    drush pm-enable -y $ext
  elif [ $choice -eq 8 ] ; then
    drush pm-disable -y $ext
  fi
  cd ../
done

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.