WordPress Upgrade Script

If you have shell access to your webserver, upgrading to the latest WordPress build can be a matter of painless seconds. As usual there is more than one way to do it, and here is one of these ways — the script I am using.

  1. #!/bin/bash
  2. CURDIR=$(pwd)
  3. SITE="http://yoursite.com/blog"
  4. echo Updating Wordpress in $CURDIR
  5. echo 1.  downloading latest build
  6. wget -q http://wordpress.org/latest.tar.gz
  7. echo 2.  unpacking latest build
  8. tar zxf latest.tar.gz
  9. cd wordpress/
  10. echo 3.  replacing old files with fresh ones
  11. tar cf - . | (cd $CURDIR; tar xf -)
  12. echo 4.  updating your blog
  13. wget -q -O - ${SITE}/wp-admin/upgrade.php?step=1 > /dev/null
  14. echo 5.  removing unneeded files and directory
  15. rm -f ../latest.tar.gz
  16. echo 6.  all done !

Modify line 3 to reflect your blog URL and here you go. The script downloads the latest build, unpacks it, overwrite your files and keeps file attributes, update your blog with the often forgotten /wp-admin/upgrade.php step, and removes temporary files. Literally takes seconds to upgrade.

Newbie how-to:

  1. Go to the wordpress root, where wp-config.php sits
  2. Using your favorite editor (pico ?) create a new file named updatewp
  3. Paste the code in the newly created file, save, exit
  4. chmod +x updatewp
  5. To upgrade WordPress: just type ./updatewp in the root dir

Note: this is based on a script I found a couple of years ago, which introduced me to the wicked tar piped line (step 3). I completely forgot where I found this originally, so if you have the feeling you might be the original coder, feel free to raise your hand in the comments :)

13 comments

  1. WordPress 自动升级脚本 at catch the digital flow

    […] Microsoft 系统的批处理脚本,但相比之下功能要强大得多。感谢 Ozh 提供下面的代码: PLAIN TEXT […]

  2. iKArus

    I would add two lines after line 15 to delete the unpacked wordpress folder:


    16. cd ..
    17. rm -f -r wordpress
    18. echo 6. all done !

  3. iKA’s Blog » WP-Updates vereinfacht

    […] nervige Updaten von WordPress kann man, wie ich heute bei Ozh gesehen habe, extrem vereinfachen! Alles was dafür benötigt wird, ist das folgende, […]

  4.   最便捷升级 WordPress 2.3.1 的方法 by BloggingPro China

    […] 今天在这里找到了一个好东西 – WordPress Bash 升级脚本。对于有 SSH 权限的朋友来说,这可能是最简单的升级 WordPress 的方式(SVN update 除外)。花儿已经在 BPCN 和花儿开了用这种方法成功完成了升级,所以请大家放心使用 […]

  5. Wordpress自动升级脚本 | Ge Xiaofei

    […] 在整理插件的过程中,发现了一个很好用的wordpress自动升级脚本,非常好用。不过要使用这个wordpress脚本的前提是你需要有服务器的shell权限。 #!/bin/bash […]

  6. WordPress Wednesday News: WordCamp Melbourne Sold Out Success, WordPress 2.4 Delayed, Security News, Rumors and Scams, and More : The Blog Herald

    […] Peter Westwood's description of the changes in WordPress 2.3.1. Also see PlanetOzh's WordPress Upgrade Script for those with shell access to their web server, making upgrading WordPress "a matter of […]

  7. WordPress Wednesday News: Will You Turn Off Akismet? WordPress 2.4 Delayed, and More WordPress News : The Blog Herald

    […] Peter Westwood's description of the changes in WordPress 2.3.1. Also see PlanetOzh's WordPress Upgrade Script for those with shell access to their web server, making upgrading WordPress "a matter of […]

  8. Tyler Menezes

    Will this preserve custom themes?

  9. Ozh

    Tyler Menezes » It has nothing to do with themes.

  10. Wordpress?????? | ??

    […] ???????????????????wordpress???????????????????wordpress??????????????shell??? […]

  11. Upgrading Wordpress Script | Nate’s Brain Dump
  12. WordPress Wednesday: Upgrade Script | Tom Altman’s Wedia Conversation

    […] WordPress Upgrade Script « planetOzh. […]

  13. Hackers Highlight 8 March 2009 | WPLover

    […] multiple WordPress installations. Stephen Rider offered up Virtual Multiblog. Ozh linked to his WordPress Upgrade Script. Eric Marden listed some of the more general build process tools: Phing, Capistrano, Ant, Maven, […]

Comments are closed.