How to Update Your Drupal Install Using Subversion

It's a pretty day outside

Note: Today's article is an unfortunate but necessary lift from an article someone else wrote. Matt Cheney at Chapter Three wrote a great article called "HOWTO: Upgrade an SVN Managed Drupal Installation (without CVS)". Unfortunately, their blog is on Google's warning list for malware. So, I figured I'd write my own version (of pretty much the same advice).

If you use Subversion to manage code updates to your Drupal-based site, then chances are that whenever an update to the Drupal core comes out, it's really annoying to use. You don't want to go copying your sites/ directory from the old version to the new, since all your .svn directories are in the old version. It's just a big headache. Luckily, there's basically one command you have to run to painlessly update Drupal (with just a little bit of set up). Here's how:

Download the latest Drupal, extract it to a directory, and cd into it

You can put the directory wherever you want. We're just going to be using it to copy from. It's quickest to just do all of this from the command line. A note: I'm on a Mac (and using Terminal). If you're on Linux, I think these commands will still work fine. If you're on Windows, well, this article might not help. Also, I'm writing this with Drupal 6.19 being the latest update. For future releases, just replace "6.19" below with whatever the version number is. Ok, so here's how:

curl -O
tar -xzf drupal-6.19.tar.gz
cd drupal-6.19

At this point, you should be inside the directory you just downloaded and extracted.

Use find to copy the files from the new Drupal into your existing install

Here's where the magic happens. To be safe, you should first run a command that lists what's going to happen. Once that looks good, you do the real thing. You're going to run all of these following commands from inside the directory you extracted. And, "/path/to/www/" in the commands below should be replaced with the path to the directory for the website you're updating. To see what's going to happen, run:

find * -type f -exec echo cp {} /path/to/www/{} \;

You should see a long list of all the copy commands that will be run in the update. If that looks right, then you run the real thing, which basically just removes the "echo" from the previous command:

find * -type f -exec cp {} /path/to/www/{} \;

You won't see any output from this, but it will copy all the Drupal code files over to your site. The last thing you can do is run a diff to see that the copy worked, and also see what the code updates are in this new version of Drupal. Not necessary, but still a good check to run:

find * -type f -exec diff {} /path/to/www/{} \;

... and that should be it. Of course, make sure you run update.php afterwards! If you have any questions or suggestions, leave me a comment below.


Lars Nielsen's picture

Looks very nice. Does this approach still work with D7?

Chadwick Wood's picture

I believe this approach should work with Drupal 7, yes. But these days I'm usually using Drush to update Drupal core, since it has that ability now!