Mehrere WordPress-Installationen automatisch aktualisieren (via shell)
Die folgende Anleitung stammt von Alex Günsche - vielen Dank!
Achtung! Bitte den Code lesen! Erst ausführen, wenn man verstanden hat, was hier passiert.
Backups sind Pflicht. Der Autor übernimmt keine Gewähr für etwaige Fehler.
Wenn man einen virtuellen oder dedizierten Root-Server hat, kann man ein kleines Bash-Script benutzen, um mehrere WordPress-Installationen automatisch zu aktualisieren. Das ganze passiert natürlich auf der Kommandozeile (bash).
#!/bin/bash # Copyright (c) 2007 Alex Guensche http://www.zirona.com # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, # copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following # conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # where are working data stored WORKDIR="/root/wpupgrade/" # a file with the absolute path to the WordPress installation and the URL # to the website, both separated only by an equation mark, no other characters # example lines in that file: # /var/www/example.org/htdocs/blog/=http://example.org/blog/ # /var/www/localhost/htdocs/=http://127.0.0.1/ WPDIRS_FILE="${WORKDIR}installations" # derive the affected WP installations from that file WPDIRS=$(cat ${WPDIRS_FILE}) # WordPress website and path to download package WORDPRESS="http://www.wordpress.org/" # download package file name LATEST="latest.tar.gz" # script to call in order to finish the upgrade UPGRADESCRIPT="wp-admin/upgrade.php?step=1" # get it on cd ${WORKDIR} # remove old versions [ -e "wordpress" ] && rm -r wordpress [ -e "latest.tar.gz" ] && rm latest.tar.gz # get latest version, unpack and prepare wget ${WORDPRESS}${LATEST} tar -xzf $LATEST rm -r wordpress/wp-content rm -r wordpress/wp-config-sample.php [ -d "languages" ] && cp -r languages wordpress/wp-includes # upgrade each webhost for i in ${WPDIRS}; do DIR=$(echo $i | cut -f 1 -d “=”) WEBSITE=$(echo $i | cut -f 2 -d “=”) USER=$(ls -l ${DIR}/wp-config.php | cut -f 3 -d ‘ ‘) GROUP=$(ls -l ${DIR}/wp-config.php | cut -f 4 -d ‘ ‘) echo “Upgrading WP installation in ${DIR} for host ${WEBSITE}…” echo -n “Do you have backups and want to continue? [y/N] ” read DOITBABY [ "${DOITBABY}" == "y" ] || exit cd $DIR; echo “Upgrading…” > index.html mv wp-content wordpress_content mv wp-config.php wordpress_config.php rm -r wp-* xmlrpc.php index.php cp -r ${WORKDIR}/wordpress/* . mv wordpress_content wp-content mv wordpress_config.php wp-config.php wget “${WEBSITE}${UPGRADESCRIPT}” -O - chown -R ${USER}:${GROUP} ${DIR} rm index.html echo “Upgrade for ${DIR} finished.” done
Benutzung:
- Als Root anmelden und nach /root/ wechseln
- Ein Verzeichnis namens wpupgrade anlegen
- In das Verzeichnis wpupgrade wechseln und das obige Script dort speichern
- Das Script mit chmod +x ausführbar machen
- Empfohlen: Ein Verzeichnis languages mit allen benötigten Sprachdateien anlegen
- Eine Datei installations anlegen, in das zeilenweise der absolute Verzeichnispfad sowie die Web-URL getrennt durch ein Gleichheitszeichen eingegeben werden (keine Leer- oder sonstige Zeichen!). Bspw.:
/var/www/example.org/htdocs/blog/=http://example.org/blog/
/var/www/localhost/htdocs/=http://127.0.0.1/
Wenn man dann das obige Script ausführt, werden alle in installations aufgeführten WordPress-Installationen automatisch aktualisiert.
Letzte Aktualisierung am 12. Januar 2007 um 16:28 von jottlieb. Zurück zur Übersicht.
