I have a similar set up - multiple sites using the same codebase and different DBs. I use a shell script to run the same drush command through each site. The script is below - it's customised to my server set up. The relevant bits are:
My Drupal root directory is /var/www/drupal7
Each site (in drupal7/sites) contains ".d7." in the name.
The script below (called d7_all_sites) can run 3 drush commands on each of my sites: clear all caches, put sites in/out of maintenance mode, and update the database. The command is given by a parameter. So, when I update modules, I do this ...
$ d7_all_sites mm 1 ## puts all sites into maintenance mode
$ drush up ## updates the modules
$ d7_all_sites updb ## updates each site's DB schema
$ d7_all_sites mm 0 ## takes all sites out of maintenance mode
I'm a scripting novice, so any suggestions to improve the script are very welcome.
#!/bin/bash
# test that at least one parameter if given, else return error message & exit
if [ $# -eq 0 ]
then
echo -e "\n You must supply a valid parameter ...\n cc to clear caches.\n mm [0 or 1] for maintenance mode (0=online, 1=offline).\n updb to update databases.\n"
exit 2
fi
## clear all caches command
if [ $1 = "cc" ]
then
for SITE in `ls /var/www/drupal7/sites | grep ".d7."`;
do
echo
echo Clearing caches on $SITE ...
drush --uri=$SITE --root=/var/www/drupal7 cache-clear all
done
exit 0
fi
## maintenance mode
if [ $1 = "mm" ]
then
if [ $# -ne 2 ]
then
echo -e "\n You must supply a parameter ...\n 0 for online.\n 1 for offline.\n"
exit 2
else
if [ $2 -eq 0 ]
then
text="online ..."
else
if [ $2 -eq 1 ]
then
text="offline ..."
echo -e "\n You must supply a parameter ...\n 0 for online.\n 1 for offline.\n"
exit 2
fi
fi
fi
for SITE in `ls /var/www/drupal7/sites | grep ".d7."`;
do
echo
echo Putting $SITE $text
drush --uri=$SITE --root=/var/www/drupal7 vset --exact --yes maintenance_mode $2
done
exit 0
fi
# update databases
if [ $1 = "updb" ]
then
for SITE in `ls /var/www/drupal7/sites | grep ".d7."`;
do
echo
echo Checking $SITE for database updates ...
drush --uri=$SITE --root=/var/www/drupal7 --yes updatedb
done
exit 0
fi
# if no commands have been run, return an error message
echo -e "\n You must supply a valid parameter ...\n cc to clear caches.\n mm [0 or 1] for maintenance mode (0=online, 1=offline).\n updb to update databases.\n"
drush @sites <command>
, works for me on a couple of multisite installs. I don't have aliases set up for those so I guesssites
is a general alias