Some time it is necessary to copy all content of Sharepoint site from one environment to another. For example, in order to make testing more relevant it may be needed to copy production content to test environment, so it will be possible to test functionality with real content without risk to break something. In general such scenarios are done by copying content database and mounting it on test env. But if you configured cross-site publishing on production site, the process will be more complicated. In this post I will describe steps which are needed for successful copy of such sites across environments.
Step 1. Copy content databases
This step is still needed. If you use 2 web applications (authoring and public), you need to copy both of them. Also if you use managed metadata, you should also copy managed metadata database.
On test env create new managed metadata service application and use copied database for it (it can be done by New-SPMetadataServiceApplication cmdlet). After that restore and mount copied content databases using Mount-SPContentDatabase cmdlet. Try to edit some page or document with managed metadata and check that it is editable, i.e. that it is possible to change value in managed metadata fields.
Step 2. Set standard result source as default
If you have custom result source which is set as default, then you need to set OTB “Local Sharepoint Results” source temporary as default. Sharepoint doesn’t show catalog connections when custom result source is set as default (I wrote about it here: Problem with missing catalog connections when use customized search result source in Sharepoint 2013). Later we will return it back.
Alternatively you may completely delete custom result sources from your site collections. It can be done with the following code:
1: public static void DeleteResultSource(SPSite site, string name)
3: var searchAppProxy = getSearchServiceApplicationProxy(site);
4: var federationManager = new FederationManager(searchAppProxy);
5: var searchOwner = new SearchObjectOwner(SearchObjectLevel.SPSite, site.RootWeb);
6: var source = federationManager.GetSourceByName(name, searchOwner);
11: private static SearchServiceApplicationProxy getSearchServiceApplicationProxy(
12: SPSite site)
14: var serviceContext = SPServiceContext.GetContext(site);
16: var searchAppProxy =
18: as SearchServiceApplicationProxy;
19: return searchAppProxy;
Step 3. Remove old catalog connections
Old catalog connections should be removed and recreated on test env. You can remove catalog connections with the following code:
1: public static void DeleteCatalogConnection(SPWeb web)
3: string catalogUrl = ...;
4: var catalogSubscriber = new CatalogSubscriber(catalogUrl, web.Url);
Here we used CatalogSubscriber helper class from this msdn example.
Step 4. Reset search index and make full crawl
Go to Central administration > Manage service applications > Search service application and reset search index. After that make full crawl of the authoring and public sites.
Step 5. Reconnect to catalog
After full crawl new catalog connection should appear in Site settings > Manage catalog connections. We need to reconnect to it in order to use cross-site publishing on test environment. Example of connecting to new catalog programmatically can be found in the same msdn example which was mentioned above.
Step 6. Set custom result source as default
On step 1 we set OTB “Local Sharepoint Results” result source as default. Now we can set custom result source back to default. If you deleted custom result sources on step 1, you need to recreate it here.
That’s basically all. There may be additional steps, specific for your particular case, but general process should be done with steps described above and after that you should have working cross-site publishing on copied site on test environment.