Thursday, October 7, 2010

Moving a Sitefinity site into another database

I’ve come across a couple of occasions where I needed to copy the structure and layout of one Sitefinity site into an existing Sitefinity database. For example when moving from a development or staging environment to production.

I did some research and found no point-and-click solution for this so far. The Sitefinity API does support duplicating pages but that does not seem to work well for moving pages from one database to another.

Then I came across the handy site export feature in Sitefinity. This allows you to export an entire site into a zip. The zip can be used to create a new site. Under the hood there’s and ExportModule that’s doing all the work. The zip contains both the site’s files and a set of XML files that hold the site structure and any content you may have entered. So, to duplicate a site into an existing database here’s what to do:

1. Export the site and collect the zip file


The zip will be in the App_Data\Sitefinity_Exports folder of the exported site.

2. Extract the XML data files
Go into the zip. There’s a second zip inside called Extract that zip and copy the App_Data/Sitefinity_DataImport folder inside it into your existing site.

3. Configure the CMS provider to use a new application
Go into your web.config and search for the cms section and add (or modify) the applicationName attribute.

<cms defaultProvider="Sitefinity" pageExtension=".aspx" projectName="MyProject" disabled="false" pageEditorUIMode="Overlay">
    <add connectionStringName="DefaultConnection" 
          allowPageHistory="true" allowPageWorkflow="false" 
          type="Telerik.Cms.Data.DefaultProvider, Telerik.Cms.Data"

4. Import the XML data
Copy the attached Import.aspx into the root of your site and navigate to it. It will allow you to select a data set to import. The code that does the real work:

var tool = new SiteExporter();
tool.Import( "Your-data-set" );


5. Login and set the home page
Right now there is no home page for the new site yet. Login an set the home page to activate the new layout.

And finally…
Don’t forget to remove the Import.aspx file from your site.

Note that you can switch back to the old layout at any time by reverting the applicationName setting in web.config.

Source code:


Corby said...

I'm looking for a way to get a site migrated from version 3.7 sp2 to 3.7 sp4 and perhaps up to version 4 once the RC becomes official. I've not had very much luck installing the patch to get me to 3.7 sp4. Will this export method you speak of work between different versions of Sitefinity? Thanks in advance. -Corby-

Marnix said...

Hi Corby,

I really can't answer that with any certainty. I'm pretty sure it's safe to export from sp2 and import in sp4, but I haven't tried that.
The impression I get from the Upgrade instructions for SP4 is that the database hasn't changed, so it should be ok.

If you need a definitive answer or help upgrading your installation you should post to the Sitefinity forums.

Anonymous said...

I get an http time out message when I try to run this tool.
[HttpException (0x80004005): Request timed out.]

Marnix said...

@Anonymous : That could happen if importing takes a long time, for example on a slow (or busy) machine or when importing large amounts of data. When a request takes too long it will be aborted. The time a request is allowed to run is configured in web.config through the executionTimeout attribute on the httpRuntime element. Set it to the number of seconds you want the request to run, default is 110 seconds.

Neil Gauld said...

Hi Marnix

We are looking for a way to translate a complete website in Site Finity and this export method looks like it could work. Translating within Site Finity is not an option for translators as it is slow and they cannot use their translation tools.
We can translate XML files so would it be possible to translate this bundle of files and then set it up again as a duplicate asite in another language? Or is there a better exporting an XLIFF file?

Marnix said...

Hi Neil,

Interesting idea.

Since the exported data is XML you may be able to transform it to XLIFF and back. In my experience there's few things that you can't get Sitefinity to do, though it may take a bit of coding.

You may also consider writing some custom pages that directly access the Sitefinity APIs to extract the data and import it after translation.

ADT said...

Hi Marnix,

I wonder if the epxorted site also contains user information? Can I use this method to migrate user profile as well? Thanks!

Marnix said...


I'm pretty sure it doesn't contain user information. This feature was intended to make templates which typically wouldn't contain user information. The method I'm describing here is what I used to migrate the layout and content from a staging site to a production site.