Wednesday, September 12, 2012

How to Correctly Backup and Restore Term Store DB, Content Type Hub and Content Database

I have run across this scenario a few times so I thought I would write a guide for others to follow. The need for this comes up when companies have multiple environments such as Prod, Staging, Test, Dev etc. Almost invariably, I have seen that the Prod environments are the most up to date, not only in terms of content but also in terms of configuration of the SharePoint farm.

So lets assume that your organization is using the Content Type Hub to syndicate and push content types to the different subscribing site collections. This involves the use of the Managed Metadata Service which directs the publishing of the content types and also allows for the term sets to be used in the various SharePoint web sites. Lets also assume that your sites use Managed Metadata columns that are mapped to the term sets in the term store. Every once in a while, you want to pull data back to your other environments for periodic refreshes and testing. I have been asked how to do this by a few clients so I will lay it out here.

To do this correctly, you will need to back up at least 3 databases from your production farm, depends on how many databases your hub and content sites are using. I am assuming 1 per web application here. So, backup the Hub database, the content database or databases which you want to bring back, and the managed metadata database that contains all the term sets and terms. What is the managed metadata database, you ask. To find that out, you have to go to Service Applications, highlight the Managed Metadata Service application and then click properties. You will see the name of the database on this screen.


Bring those backed up databases to the target environment SQL Server, ready to be restored. As a best practice first I make backups of all three or more databases in the target environment that I am about to replace. Then I turn of the SP Timer service to make sure the timer jobs don't try to push stuff while I am restoring term sets and the Hub. Then I override the MMS destination database with the MMS database I just backup from Prod. This brings back all the term sets and terms. I also disconnect the Hub and the target web application content databases using CA or stsadm or powershell.

Note: To view this go back to the properties screen we were just on for the Managed Metadata Service Application. This brings back the connection to the content type hub in production, which is what we don't want. We want this URL to point to our target environment (Staging, Test etc). It is not possible to change this URL from the UI, we have to change it using powershell.


The Powershell command is as follows:

Set-SPMetadataServiceApplication -Identity "<ServiceApplication>" -HubURI "<HubURI>"

Once the managed metadata service looks good and all the term sets and terms have come through, then we can move on to the hub and content databases. Restore the hub and content databases as different names on the target farm so they dont override. Make sure that the permissions match on the newly restored database and the old database that we just disconnected. This is just a practice I follow. Then attach the hub web application to the newly restored hub database from prod. You might have to redo permissions on the newly restored site collections through CA so you can access them.

Finally, restore and attach all the content databases that you need to. After all this is done, do an IISReset and start the timer service. This will start the two timer jobs that push and subscribe to the content types from the new hub.

There you go, all done! Verify to make sure that your MMS columns work correctly in your web applications and that your content types are being pushed down correctly from your local hub.

12 comments:

Anonymous said...

Am exactly in the same situation nw. Will try this out and let you know. Thanks for sharing your experience.

Faraz said...

Sure thing, let me know how it goes.

NasserO said...

Nice work, Faraz. However, different farms have different contents not just by accident. The QA farm is configured heavily for QA activities. Once you swap the content database of the QA farm by that of the production, QA team will hate your guts. Same applies to a shared dev environment that is used by more than one dev team.

Your solution has merits though. With the inexpensive virtualized environments, you can always back up any production site collection and restore it on a new virtualized environment for testing. A good and disciplined QA team can write scripts to create their ideal configuration in minutes. So you put some times on setup and configuration, but you don't throw away other people's sites, lists, metadata etc.

However, a better solution could be configuring a single content hub for all of your environments. But I am not sure if SharePoint allows that.

Thanks
Nasser.

mithra said...


Hey... You have nice Blog.. Keep follow this excellent work.
Sharepoint Backup

Matthew Jones said...

We backup site collection via stsadm\powershell and restore it in other farm. But the term store service values are missing after the restore. How can we backup & restore the site collection with the service data as well? This site helps me to write my essay on this theme.

special essays said...

Thank you for information!
professional essay writers

essay writing said...

I always like your blog post because you always come with different ideas and information.
Writings-centre.com

Anonymous said...

Hi,
Thank you for this information. Please take my suggestion to also re-publish the content types located in the hub. Do this before running the timer jobs to propagate them. If you do not republish them, they may end up as editable on the consumer sites, or not propagate at all.

Barbara said...

I like this post! This information is really interesting! By the way, skilled writers can always meet your request write my essay.

Amy Pearson said...

Thanks for the tips! They can help me to write my essay.

alexxlexx said...

Thank you for very nice advices, I wish I could write my essay like you!

Anonymous said...

should i run the powershell if i am only restoring the MMS database?.