EasyWPUpdate ver 2.0 RC 1 - Just in time for WordPress 2.0.7

Ξ January 12th, 2007 | → | ∇ Bash, WordPress, install, installation, putty, ssh, update, upgrade |

Well I can’t call it the 5 second upgrade script any more… Since adding full file backups, and compressed database backups, from Windows desktop, through manual log in and launch of the update script, it took me ~15 seconds to update an active blog with a couple dozen posts and log all of the results to a html log. I’m fairly certain I could type my password faster and shave off a few seconds. The script itself, which now shows start and stop times, only took 2 seconds to do its work. The rest was connect and login time. Sometimes it took a whole 30 seconds for the process to complete, web and server usage being what it is, but either way, wow. I should say that I used this last night with all of the options turned on, creating file backups AND gzipped backups AND database backups AND an HTML log file AND adding extra verbosity AND updating my 6 WordPress blogs and it took a full 8.5 minutes. I had to actually minimize the window to get it out of my way…. Between that and typing in the script name at the shell prompt, I was exhausted!

When I think of how long it used to take me to update just my wife’s blog, I just have to shake my head. Each release was a many-night, if not many-week process till I had the spare time to concentrate on doing the whole thing right. And I had to look up the instructions on the database backup every time… I’m just so glad this script is done.

The basic functionality is now complete and I am calling this a RC 1 release. It still needs further testing (especially the MySQLDump stuff. Does everyone HAVE MySQLDump? Should I disable this feature by default?), but it is fairly stable now.

Here’s the basic functionality

#  You can use this program in several ways:  
#    * In the default mode to download the latest and greatest update,
#      make an uncompressed copy of your files, makes a compressed backup
#      of your database(s), distributes the file to any number of 
#      directories, and performs the web steps
#    * Configure it to make a online copy of your files you use for easy 
#      recovery AND a compressed copy that you can download.
#    * Add custom directories and backup MORE than just WP. 
#    * Configure it update from a local file each night and start with
#      a clean blog every morning.  
#    * Use it as a nightly backup script by disabling all other steps

I’ve made about a gazzilion improvements and took the advice of a dozen or more reviewers out there. I think the new script is much improved. I’m really pleased with how well the database backup stuff works. I change into each blog directory, read all of the connection information from the wp-config.php file and use that to connect to the database. (I’m fairly certain this will work well for most servers, but I’m a little worried that *nix gurus will not be using TCP to connect to their databases and I have that hard coded. You gurus should let me know if this is an issue in the comments for this post!) I also then query the tables names from the specified database using the prefix specified for the blog. This means that this process will work for ALL versions of WP and will not grab non-WP stuff like vBulletin tables. It also means that it works just as well if you have 1 blog per DB or ALL blogs in 1 DB. It doesn’t matter. The DB backup for Blog1 has ONLY the data for Blog1. That is better for security, size, time and opens a neat avenue for testers who want to restore their blog to a different database/databasename and then test a major upgrade running their full blog out of a different directory. I’ve structured the tarball backups to make this easy too. *SORRY* There I go into tech speak again, but it is neat stuff, that is normally totally hidden from view.

You can peruse the text version, EasyWPUpdate.txt, here: link

Like the new name? I think it is better. I put TCC in front of all of my plugins, but really there is no need here. And yes, the sample version has grown to 851 lines. That’s not ALL code of course. It is heavily documented and includes some HTML that will give you a nice webpage log for you to peruse after the process is done. You can see a sample log here: link.

Now, I had deliberately made that last post very intimidating. I wanted people to be wary of the script. Now, I have much more confidence in its ability and quality. I’ve learned a lot in the last week. From using procedures, to the trap function, to sed and MySQLDump, to basic shell coding practices. It was all fun and you get the benifit. Especially because there are three versions of WP in the pipeline: 2.0.7 (Very, Very Soon), 2.0.8 (in the works), 2.1 (Very Soon).

So, I’ve made this post easier to read and the script easier to configure. I’ll do a full document later, but here are the basic steps to install this script:
1. Use Telnet or Putty to connect to your website and log into the shell
2. Type the following line:
wget http://www.thecodecave.com/downloads/EasyWPUpdate
3. Type the following line:
chmod +x EasyWPUpdate
4. Use an editor to change the values in Step 1 and save it again.
5. Run the script by typing:
EasyWPUpdate

That’s it. You will have just made backups of the files and database and updated all of your blogs. When 2.0.8 comes out, the process will be:
1. Log in
2. Type
EasyWPUpdate

And you are done.

Now, step 1 looks like this:

# ##################################################################
# Step 1. Tell the script where to find the blogs
# ##################################################################
# List all of your WordPress directories and urls here.
#
# Each Blog should have a BlogDir and a BlugURL.
# Each Blog should have its own number [1],[2],[3] etc
# Delete the ones you don’t need.
#
BlogDir[1]=’site1dir’
BlogURL[1]=’www.example.com’

BlogDir[2]=’site2/news’
BlogURL[2]=’www.site2.com/news’

BlogDir[3]=’wordpress’
BlogURL[3]=’blog.site3.com’

That isn’t that hard to change is it? Even in VI.

Some quick tips on editing the script
1. type
vi EasyWPUpdate
2. Hit i
3. Make your changes
4. Hit ESCAPE COLON W to save your changes (or skip this step to lose changes)
5. Hit ESCAPE COLON !Q to immediately quit

Also, if your root directory is accessible from the web, you might want to change the name of the script
mv EasyWPUpdate SomeSneakyName
to prevent unauthorized access.

If you ran the alpha 3 version of the script, you can copy and paste configuration over BUT!!!! you have to make the following changes:
The BlogDirs[] array has been renamed to BlogDir[]. Drop the “s” from all of those variables.

You should not need to copy the Common*Prefix variables over, but if you do, make sure to remove the trailing slash from the CommonRootPrefix variable.

I think that’s all you need to be aware of.

If you are a guru, please read through all 6 setup steps (and the rest too) there may be things you want to change.

I’ve also updated my Did That Help page and added a forum specficly for this script.

That might make discussions a little bit easier.

Well that’s about it. Let me know how it works. I’d like to get some good testing in before 2.0.7 comes out. I’ll also do some testing with updating to 2.1 so I am certain that will work well. I also need write instructions for the database recovery steps. The script has built in instructions if it blows up in the middle of updating the files. So, that is handled.

I’ll leave you with the change history and credits section from the script. Enjoy!

# History:
#    01/AUG/2006 - BL - Created
#    21/DEC/2006 - BL - Added multiple blog arrays 
#                       Added options at the top of the script
#    04/JAN/2007 - BL - Added File Backup routines
#                       Added web update
#                       Added tmp directory usage
#                       Added local source ”freshen” option
#    11/JAN/2007 - BL - Added ”steps” and further comments
#                       Added quotes around many vars to protect against spaces
#                       Changed TMPDIR-/tmp to TMPDIR:-/tmp
#                       Changed `pwd` != ”$tmp” to `$pwd` != ”$tmp”
#                       Added further error trapping around cd and cp routines
#                       Fixed file backup procedure, was adding extra layers
#                       Added ability to backup to tarball
#                       Added SQL backup procedure
#                       Fixed local file backup procedure
#                       Removed “Verbose” from cp to make messages clearer
#                       Added log to webpage for Joe.
#                       Fixed inconsistent use of trailing / in path variables
#                       Added status messages throughout
#                       Added recovery instructions in case of failure mid backup
#                       Added a list of directories to backup
#                       Added Credits section
#
# Credits - I want to thank all of the readers of TheCodeCave.com, for
#   their testing of this script. I especially appreciated Michael, Maciek, 
#   Aaron and Joe for all of the helpful suggestions.  
#   A very special thanks goes out to goldfish on the FreeNode #sed channel                     
#   who will be PayPaled a Cafe Voltaire tomorrow.  I would have spent days
#   figuring out the RegEx for the SED commands.  Prec, also from #sed gave 
#   provided me with a working cr/lf stripper.  For bash, lhunath, jp-_ and the                     
#   whole crew at #bash on FreeNode gave great line by line suggestions.
#   They basically gave it a full code review!  None of this would have been 
#   possible without Advanced Bash-Scripting Guide. 20 days ago I didn’t know
#   what bash was.  Now I’ve written a powerful script with features I’ve not
#   seen anywhere else.  If you have any questions about the code in this 
#   script, you’ll find the answers here:&nbsphttp://www.tldp.org/LDP/abs/html/
#

 

20 Responses to ' EasyWPUpdate ver 2.0 RC 1 - Just in time for WordPress 2.0.7 '

Subscribe to comments with RSS or TrackBack to ' EasyWPUpdate ver 2.0 RC 1 - Just in time for WordPress 2.0.7 '.

  1. Kevin said,

    on January 12th, 2007 at 4:47 pm

    Wow - anxious to give the new script a run. MANY thanks - the last one has already saved me lots of time.

  2. Kevin said,

    on January 12th, 2007 at 5:01 pm

    OK - what’s happening? I tried to wget per the instructions above and it actually retrieved a file called “article323″–the html of this article. Maybe there’s something going on with permalinks?

    And the one eye’d gravatar - not sure where that cam from.

  3. Brian said,

    on January 12th, 2007 at 5:01 pm

    My Pleasure Kevin. Hey I should give people an upgrade guide.

    You can copy and paste configuration over BUT!!!! you have to make the following changes:
    The BlogDirs[] array has been renamed to BlogDir[]. Drop the “s” from all of those variables.

    You should not need to copy the Common*Prefix variables over, but if you do, make sure to remove the trailing slash from the CommonRootPrefix variable.

    I think that’s all you need to be aware of. I’ll add that to the article.

    BTW what control are you using for your pod casts. That’s pretty slick. I’ve started to record my lessons on 1 Corinthians and want to archive them here. That control would be useful. Though I’m not quite sure how you could preach on Acts, Philipians Galations and Timothy and some how skip 1 Corinthians! It’s quite a book!

  4. Kevin said,

    on January 12th, 2007 at 5:06 pm

    Brian - I’m using the Audio Player WordPress Plugin — very handy.

    And I’m glad you mentioned the “BlogDir” change.

  5. Brian said,

    on January 12th, 2007 at 5:07 pm

    Oh my! that would explain why there were no wget downloads yet… I left ou the downloads directory in the url. Here is the correct url:

    http://www.thecodecave.com/downloads/EasyWPUpdate

    I’ve changed the line in the article to read:
    wget http://www.thecodecave.com/downloads/EasyWPUpdate

    That should do it!

  6. Kevin said,

    on January 12th, 2007 at 5:10 pm

    Great - that did it - thanks. And preaching through Acts has really stretched me. It’s been good.

  7. Kevin said,

    on January 12th, 2007 at 5:28 pm

    Brian - just noticed you use “EasyWPUpgrade” in the tips for editing the script but you use “EasyWPUpdate” elsewhere.

  8. Brian said,

    on January 12th, 2007 at 5:37 pm

    Dagnabbit. That’s a hard habbit to kick! FIXED.

  9. Joe said,

    on January 12th, 2007 at 7:53 pm

    Wow… Wow about my php script? Do you want the new version?

  10. Joe said,

    on January 12th, 2007 at 11:02 pm

    Oops, again…

    Wow about my php scirpt?

    LOL :-D Should be what about.

  11. Brian said,

    on January 12th, 2007 at 11:30 pm

    Ah!
    Yeah toss it into the forum and we can chat about it….
    http://www.thecodecave.com/forum/viewforum.php?f=11&sid=464e41b0f9a329897382ba285be8eef9

  12. Mark said,

    on January 16th, 2007 at 4:30 am

    Is it possible for this script su to different users for each site? I was hoping to run this as root and update 3 installs in different user directories, but I don’t want to take root ownership of all those files :-/

    Any ideas?

  13. Brian said,

    on January 16th, 2007 at 11:05 am

    Sure, you should be able to add another array to the top of the script that has the user ID in it for the blog. Then you can add the appropriate su command for that directory. I never have to use SU. What are the parameters that you would be using?


  14. on January 28th, 2007 at 12:52 pm

    [...] those of you that manage your own wordpress blogs, I started using EasyWPUpdate, a script written by Brian Layman that auto-upgrades wordpress blogs. From my initial experience, I [...]

  15. IT Damager said,

    on February 25th, 2007 at 1:19 pm

    The script works great (just upgraded 8 sites to 2.1.1), but it leaves trash files in the root directory of each site. For example:

    upgrade.php
    upgrade.php?step=1&backto=
    upgrade.php?step=3&backto=
    upgrade.php.1
    upgrade.php?step=2&backto=

    These files contain the html output from running the upgrade.php script. Perhaps the output of upgrade.php should be redirected to null?

  16. IT Damager said,

    on February 25th, 2007 at 1:24 pm

    wget -O /dev/null -q $CurBlogURL$CurUpgradeURL


  17. on March 2nd, 2007 at 11:12 pm

    [...] WordPress を簡単にアップグレードする方法を調査してみました。 すると、EasyWPUpdate [...]


  18. on March 15th, 2007 at 2:20 pm

    [...] elixir that has eluded me all this time. I’d taken a look at TheCodeCave’s approach - a script that automates the process, but I chickened out once more, mainly due to the fact that I [...]

  19. Joe said,

    on March 30th, 2007 at 6:32 pm

    I’m going to be setting up the WebRunner site, it will be soon found at http://mostlynothing.info/code/webrunner/ . :-)


  20. on April 3rd, 2007 at 2:12 pm

    [...] upgraded using Brian Layman’s quite marvellous Easy WordPress Upgrade Script, which is recommended to anyone who has shell (command line) access to their host. Backs up your [...]

Leave a reply