The one hour Sitecore upgrade (or downgrade) with Unicorn

* Note - This is out of date now - use Sitecores express upgrade tool! It is still an interesting read though :-) *

I was recently asked to update a solution from version 7.5 to version 8 Update 3 (the latest version at the time of writing). I did this in less than an hour.

Next week if we wanted to, in theory we could upgrade (or even downgrade) to a different version very quickly.

The standard way of upgrading is to download an update package, install it and manually make the config changes.

However you need to do this a number of times, first 7.5 to 8 Initial, then 8 Initial to 8 Update 1, Update 1 to Update 2 and then Update 2 to update 3.. phew!

Instead I decided to try something different.

The plan

First caveat time, I must say this may not be the best solution for you depending on your version you might find some added difficulties. Hopefully my experience may give you some ideas to plan your next upgrade.

So the plan:

  1. Branch the source code (which is based on Sitecore 7.5)
  2. Serialize the 7.5 Sitecore content using Unicorn.
  3. Update the Sitecore runtimes (sitecore folder, sitecore modules folder, data folder, sitecore assemblies).
  4. Update the configs quickly (more about this below).
  5. Attach the blank Sitecore 8 dbs.
  6. Update the connectionstrings to point to the new dbs.
  7. Sync the serialized content to the new databases.
  8. Copy across data we need from Core.

This can be done very quickly if your solution is set up correctly.

How our solution is set up

I purposely set up our solution at the start so that upgrades are easier.

Firstly we don't touch the OOTB Web.Config except to remove the Sitecore and AppSettings sections to move them to their own files.

In our configuration folder we have the OOTB Web.Config and a Web.Base.Transform.Config. On build we generate the root web.config by running the transform against the OOTB config.

All Sitecore transforms are handled by sitecore config patching.

This makes part 4, updating the configs really easy. I just replace the OOTB Web and Sitecore.config with those from the newer version.

Serializing the database

The very first thing I did was to serialize all the content I wanted to port across to the new version using Unicorn.

Setting up Unicorn is really easy (read more here) and in Serialization.config you simply define all the content you want to serialize.

Clicking the "Reserialize now" button form /Unicorn.aspx will serialize all your content ready for later.

Update the Sitecore runtimes

This is as simple as replacing the Sitecore, Sitecoremodules, AppConfig and the Sitecore assemblies (which we keep in nuget) with the latest versions. note: Sitecore / Sitecore_modules are not kept in source control. You may need to reference new assemblies from your website project.

Attach the blank databases

After attaching the new databases and updating the connectionstrings.config we can build the solution and test the CMS via /sitecore.

If everything has gone to plan you should be able to login with admin b.

Synchronize the content

Now we synchronize the content we serialized earlier. Again from /Unicorn.aspx simply click the 'Sync Now' button.

Check in Sitecore and if by magic all your content in the upgraded version.

What about all my users..

So obviously all your roles and users are stored in Core. I copied them across using the following scripts on all the aspnet_* tables.

 INSERT INTO [xxx.DEV.Core8].dbo.aspnet_Profile 
SELECT * FROM [xxx.DEV.Core75].dbo.aspnet_Profile
WHERE NOT EXISTS 
(SELECT * 
 FROM [xxx.DEV.Core8].dbo.aspnet_Profile  
 WHERE [xxx.DEV.Core8].dbo.aspnet_Profile.UserId 
 = [xxx.DEV.Core75].dbo.aspnet_Profile.UserId)

The Live environment?

I would suggest creating a new website alongside the old one and switching IIS across when it is ready. You can then follow the same process above (serialize the live sitecore content with unicorn, push up the code and then sync to new dbs). Make sure you disable the Unicorn on the live environment before you allow live traffic in!

One hour?

So our solution is small at the moment, however the theory should hold true for mature sites too. It might take a bit longer but should still save a bunch of time and working from a fresh sitecore database is always a win.

Dave Leigh

Web, and long time Sitecore developer based in Bristol, UK, working at Valtech - valtech.co.uk - @valtech.
I occasionally do other things too.