Friday, November 22, 2013

Backup and Restore of one Site Collection using columns in Managed Metadata

Wherever you restore one site collection from one Farm to another that uses site columns linked with some termstore some errors can be showed like this:

image

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 MMS from source farm to target farm.

You can use :

1. Export-SPMetadataWebServicePartitionData (http://technet.microsoft.com/en-us/library/ff607847.aspx) to export the MMS from source farm;

2. After that, the second steps is import  the same MMS exported in the step 1 using Import-SPMetadataWebServicePartitionData (http://technet.microsoft.com/en-us/library/ff607667.aspx ).

By using this technique the term store is available on the target as the same in the source. The sspId used internally by the Term Store and referred by Managed Metadata columns in list is retained.

Below the scripts to apply:

#Step 1 – Export MMS

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

#this sets the exporting MMS ID
$mmsApp = $mmsApplication = Get-SPServiceApplication | ? {$_.TypeName -eq “Managed Metadata Service”}

$mmsproxy = Get-SPServiceApplicationProxy | ?{$_.TypeName -eq “Managed Metadata Service Connection”}

Export-SPMetadataWebServicePartitionData $mmsApp.Id -ServiceProxy $mmsproxy -Path \\ebsgerh04\Backup\exportfile.bak

#Step 2 – #Import MMS

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

#this sets the exporting MMS ID
$mmsApplication = Get-SPServiceApplication | ? {$_.TypeName -eq “Managed Metadata Service”}
$mmsProxy = Get-SPServiceApplicationProxy | ? {$_.TypeName -eq “Managed Metadata Service Connection”}
Import-SPMetadataWebServicePartitionData $mmsApplication.Id -ServiceProxy $mmsProxy -Path “\\Sharepoint_Server\Backup\exportfile.bak” -OverwriteExisting

No comments:

Post a Comment