Monday, November 18, 2013

How to restore site collection from higher Sharepoint version

Sometimes you may face with situation that bug is only reproducibly on production, but not e.g. on QA or on your local development environment. Such problems are much harder to troubleshoot. Often they are caused by the content which exist only on production. And if troubleshooting directly on production is problematic (e.g. if you don’t have remote desktop access to it), you should get backup of site collection or whole content database, restore it on local dev env and try to reproduce bug here. But what to do if you have lower Sharepoint version on you local environment, than on production? Of course it is better to have the same versions, but world is not ideal and sometimes we may face with such situation. In this post I will show the trick of how to restore site collection from the higher Sharepoint version. Before to start I need to warn that this is actually a hack and you should not rely on it. There is no guarantee that it will work in your particular case, because new Sharepoint version may have different schema, incompatible with previous one (that’s why standard way is not allowed).

Ok, suppose that we have site collection backup, which is created with Backup-SPSite cmdlet:

Backup-SPSite http://example1.com -Path C:\Backup\example1.bak

We copied it on local environment and want to restore it with Restore-SPSite:

Restore-SPSite http://example2.com -Path C:\Backup\example1.bak –Confirm:$false

(Here I intentionally used different urls for source and target sites in order to show that it is possible to restore site collection to the different url). If we have lower Sharepoint version on the local environment we will get unclear nativehr exception, which won’t say anything. But if we will make our logging verbose and check Sharepoint logs, we will find the following error:

Could not deserialize site from C:\Backup\example1.bak. Microsoft.SharePoint.SPException: Schema version of backup 15.0.4505.1005 does not match current schema version 15.0.4420.1017.

(Exact version number is not important. For this post it is only important that source version 15.0.4505.1005 is higher than target version 15.0.4420.1017).

What to do in this case? Mount-SPContentDatabase also won’t work because of the same reason, i.e. content database backup also won’t work. In this case we can either update our environment (and you should consider this option as basic) or go by non-standard way.

For non-standard way we will need hex editor. At first I thought that site collection backup is regular .cab file, so it will be possible to uncompress it, edit text files inside it and compress back (I described this trick in this post: Retain object identity during export and import of subsites in Sharepoint into different site collection hierarchy location), but this is not the case with site collection backups made with mentioned cmdlets. They look like regular binary files. So we will need some hex editor for modifying it. I used HxD hexeditor, but you can use any other as well.

If we will open backup file in it and will try to find the version, which we got from error message from the log, we will find that it is located in the beginning of the file:

image

The good thing is that version is stored only once. So we will change source version to the target in the hex editor now:

image

Now save it and run Restore-SPSite again. This time restore should work. Hope that this trick will help someone. But remember that it is hack and use it carefully.

11 comments:

  1. I want to restore sharepoint 2013 site collection backup on sharepoint 2010, and did the same as you have mentioned above, but not working

    Sharepoint 2013: 15.0.4505.1005
    Sharepoint 2010: 14.0.4762.1000

    Regards

    ReplyDelete
  2. hello Muhammad,
    this method works only within the same major SP version. I.e. you may use it for restoring site collections on different minor versions of SP2010 or SP2013, but not across different major SP versions. In order to restore SP2010 site collections on SP2013 you need to follow upgrade instructions provided by MS. But your scenario with converting SP2013 to SP2010 is downgrade which is not supported in SP at all.

    ReplyDelete
  3. i opend the backupfile i.e. "sitebackup.bak" in the HxD Editior tool but i didn't find the version. how/where i can see the version?

    ReplyDelete
  4. Aaaaaaaaaaaaaaand here comes a helluva bump from Oct 2020 to say thank you for being a genius way back in 2014 already... lol... Brilliant, solved my current dilemma. You sir, are a champ..

    ReplyDelete