Site Collection BackupRestore and Managed Metadata

I recently saw an email on internal DL about things not working if you backup and restore site collection from one Farm to another. The team was using Managed Metadata in some list columns. These are scenarios where you want to move content from one environment to another and ensure your termsets are also available in target environment.In this post I will brief you about what needs to be done to make it work and reasons for same.

Wherever you restore the site collection, Managed Metadata Service should be available. Managed metadata columns consult the MMS service whenever we interact with data stored in these columns. If MMS is not there things can break and show unexpected behavior. The easiest option to make things work is to restore the termstore from source farm to target farm.

You can use Export-SPMetadataWebServicePartitionData to export term store from source application.http://technet.microsoft.com/en-us/library/ff607847.aspx. You can import  the same in target MMS using Import-SPMetadataWebServicePartitionData http://technet.microsoft.com/en-us/library/ff607667.aspx. By using this technique the term store is available on the target. The sspId used internally by the Termstore and referred by Managed metadata columns in list is retained.

Go ahead and test restored site collection in target Farm. You should find things working properly. In my random testing everything seems to be working fine. Please report issues, if you see any.

UPDATE

Hari requested me to put a sample as the API name is misleading. The service doesn't need to be partitioned for things to work. It works for un-partitioned  service application also. Service Application Proxy ID has to be passed for -Identity parameter. Example given below and hope it helps.

 #Export

$mmsApp = “4a867ce5-d9ee-4051-8e73-c5eca4158bcd”; #this sets the exporting MMS ID

$mmsproxy = Get-SPServiceApplicationProxy | ?{$_.TypeName -eq "ExportTaxonomyProxyName"};

Export-SPMetadataWebServicePartitionData -Identity $mmsApp -ServiceProxy $mmsproxy -Path \\location\exportfile.bak;



#Import 

$mms2 = "d045d3ce-e947-4465-b039-0dfbbe24fb22"   #this sets the importing MMS ID 

$mms2proxy = Get-SPServiceApplicationProxy | ?{$_.TypeName -eq "ImportTaxonomyProxyName"};

Import-SPMetadataWebServicePartitionData -Identity $mms2 -ServiceProxy $mms2proxy -path \\location\exportfile.bak -OverwriteExisting;