Monday, January 30, 2012

SharePoint 2010 - How to Backup/Restore Managed Metadata from one farm to another?

What?

SharePoint 2010 - How to Backup/Restore Managed Metadata from one farm/environment to another?

Why?

You will be amazed by the lack of proper import/export functionality.

It is quite a general requirement to migrate Managed Metadata Service / Termsets from one environment to the other.

There are a few approaches to backup/restore managed metadata between environments.

OOB, SharePoint 2010 allows for ONLY importing managed metadata in CSV format. You are required to use Powershell / Object Model to build the csv file. Here is a script that can do it. Managed metadata terms and termsets each have a unique guid. If you take a backup of a site that is using managed metadata in some columns and restore this site into another environment, the guids don't match up. You will have to go through and re click each term and "wire it back up" so it's okay and doesn't show in red text. Paul Culmsee did a good job of explaining the same with nice screenshots here. This is quite hectic especially if there is a lot of data.


How?

The easiest and the effective approach is to LIFT the managed metadata service application from one environment to the other. That way you can ensure that the guids of terms and termsets match.

This process is done in PowerShell and involves exporting managed metadata service application first, then importing it in the target environment/farm.

Powershell Configuration:

Open PowerShell. You might get an error. “The local farm is not accessible”
If the farm admin account is used, this error won’t show up.
Make sure that the account that is used for deploying solutions / executing Powershell scripts has the following role memberships for SharePoint Config Database:
  • public
  • SharePoint_Shell_Access
  • db_owner
Follow this article to fix the error: http://www.sharepointassist.com/2010/01/29/the-local-farm-is-not-accessible-cmdlets-with-featuredependencyid-are-not-registered/



Powershell for Export:

$mmsAppId= "App ID Guid Placeholder"

$mmsproxy = Get-SPServiceApplicationProxy -Identity "Proxy ID Guid Placeholder"

Export-SPMetadataWebServicePartitionData -Identity $mmsAppId -ServiceProxy $mmsproxy -Path "Path to save Exported file placeholder"

App ID Guid Placeholder:

Navigate to CA > Application Management > Manage Service Applications > Managed Metadata Service Application

The App ID Guid Placeholder is the Guid that is highlighted in the below picture:


Proxy ID Guid Placeholder:

Navigate to CA > Application Management > Manage Service Applications > Managed Metadata Service Application Proxy (Managed Metadata Service Connection)

Do not click on the Managed Metadata Service link and highlight it by clicking anywhere else in the row.

Click “Properties” in the ribbon.


Right click in the dialog and capture the appid as highlighted below:

The App ID Guid Placeholder is the appid that is highlighted in the below picture



If you get an error “Export / Import failed due to insufficient rights”, you will have to open SQL Server Management Studio in the SQL Server machine and make sure that the service account used by managed metadata service application has bulkadmin rights in SQL Server.

Give BulkAdmin rights to the managed metadata service account account as it is required for managed metadata service application import.


Execute the PowerShell script again and the script should run fine.


The Import Process:

Make sure that the exported backup file is copied physically into the server that hosts SQL Server and make sure that it is accessible from the WFE where the PowerShell script is executed.

Create a folder in the DB server. Create a share for the folder and grant full control rights to Farm Account and App Pool Account. Copy the managed metadata service backup file into the shared folder. It is a requirement to access the backup file from DB server. If the backup file is not read from the shared folder in DB server, the import process fails.

Execute the below PowerShell commands.

$mmsAppId= "App ID Guid Placeholder"
$mmsproxy = Get-SPServiceApplicationProxy -Identity "Proxy ID Guid Placeholder"
Import-SPMetadataWebServicePartitionData -Identity $mmsAppId -ServiceProxy $mmsproxy -Path "Exported file’s path placeholder" -OverwriteExisting;

The "App ID Guid Placeholder" & "Proxy ID Guid Placeholder" will need to be identified using the same process above in the destination farm.

Make sure to remove the bulkadmin permissions to the managed metadata service account as soon as you are done with the import/export process.

2 comments:

  1. Great help man!, keep going sharing your knowledge THANKS A LOT!

    ReplyDelete
  2. Thanks Sir! Worked great!

    ReplyDelete