This morning I saw a critical update to Wordpress version 3.0.4 ... and after I checked what had actually changed, I was ready to move all my sites and blogs over to it. As the webmaster for SaltRiver Computer Systems in Phoenix, I manage dozens of Wordpress installations, so this can get quite tedious. So let's automate the process.
OK, let's upgrade
I use the excellent
wptool script [see note 1] to maintain my
Wordpress installations, so we will automate with that tool as a base.
I put a copy in
Before we get started, the first domain I wanted to upgrade used the "old" repository; here is how to change it to the "new" one:
svn sw --relocate http://svn.automattic.com/wordpress/ http://core.svn.wordpress.org/ .
Now... Using the
bash shell on a system whose domains are created
following the pattern of
virtualmin, the following one-liner could
come in handy to change all Wordpress subdomain installations for that
for wp in ~/public_html ~/domains/*/public_html ; do pushd $wp ; svn sw --relocate http://svn.automattic.com/wordpress/ http://core.svn.wordpress.org/ . ; popd ; done
Preparing for multiple upgrades
Let's get a little fancier and create a script in
#!/bin/bash # # Upgrades all this user's Wordpress sites. # To use: (as root) # sudo -u the_username -i /opt/wordpress/upgradeall.sh # logfile=/tmp/`whoami`-`date +%Y%m%d`.log for subdomain in ~/public_html ~/domains/*/public_html do echo Upgrading $subdomain pushd $subdomain svn cleanup wpversion=`svn info` if [[ "$wpversion" =~ "svn.automattic.com" ]] then svn sw --relocate http://svn.automattic.com/wordpress/ http://core.svn.wordpress.org/ . fi echo Upgrading $subdomain >>$logfile /opt/wordpress/wptool upgrade >> $logfile popd done
That includes a "cleanup" (in case a previous subversion process stalled), an automatic switch to the new repository when required, and an upgrade to the latest version of Wordpress.
Mass Upgrading: Dozens or hundreds of sites and blogs at once
Are you ready for sparks to fly from your fingertips? Let's do this as root:
for uu in user1 user2 user3 ; do sudo -u $uu -i /opt/wordpress/upgradeall.sh ; done
Voila! All the Wordpress sites for all the users we listed get upgraded.
Be prepared to go back and check your work by reading the logfiles, and verifying that all the websites actually still function.
- wptool available here. Note, text is in German. Description is: "An easier and compatible script, usable as a cron job, for WordPress administrators, installations and (automated) updates. Requires SSH access to your web server."