Host Named Site Collection Restore from Production to DEV and 401 Unauthorized Error fix

Host Named Site Collection Restore from Production to DEV and 401 Unauthorized Error fix

I was attempting to do a Host named site collection restore from our Production environment (on SharePoint 2013 On-premise)  to our Dev environment (on SharePoint 2013 On-premise as well.)  I kept getting 401 unauthorized error for long. I tried at lot of things to fix this and nothing worked, eventually it clicked to me that the zones of both PROD and DEV are different and they needed to be fixed as well. Once I re-setup the zones correctly the newly restored Host named site collection just worked like breeze.

For helping out others in the similar situation I have put down the steps required:

General Steps are:
  1. Make note of the Zones of the target Site Collection
  2. Backup Source (Production) Site Collection
  3. Restore Site Collection to Target (DEV) Environment
  4. Remove Zones copied from Production and create new Zones for DEV
  5. Reset IIS
  6. Restore Term Store ( Managed Metadata Service)
  7. Update InfoPath Forms ( Republish to update Links)
  8. Fix Manual Links in the Sites
  9. Check all of the Result Sources.
  10. Restart Server
  11. Reset Crawl Index and Re-run the CRAWL
  1. Make note of the Zones of the target Site Collection

Run the following scripts on Windows Powershell ISE to get the names of the Site Collection zones

Add-PSSnapin Microsoft.SharePoint.PowerShell -ea 0

Get-SPSiteuRL http://portal-dev.abc.com:88

It returns 2 URLS:

SharePoint-zone1

Make note of it as after the restore we will need to reapply them to fix the 401 Unauthorized error with Host Named Site Collection restore

  1. Backup Source (Production) Site Collection

A site collection backup was completed on PROD Server (abc-az-sp-01)

Backup-SPSite “https://portal.abc.com” -Path “F:\Temp\Portal.bak”

  1. Restore site collection to Target (development) environment

The restore brought across all the site columns, content types, page layouts, site settings and permissions from the Production site.

A site collection restore was then completed onto DEV (abc-az-sp-03). The following powershell script was run to restore the site collection.

Restore-SPSite “http://portal-dev.abc.com:88” -Path “F:\Temp\Portal.bak” –force –HostHeaderWebApplication http://abc-az-sp-03:88

NOTE 1: It is very important to check the names of the HostHeaderWebApplication in Central Admin. Make sure you get the right name and also check the name of the site Collection from CA where you want restore it to, otherwise the restore will fail and cause more issues. Make special note of the Port numbers 

  1. Remove Zones copied from Production and create new Zones for DEV

Now after the restore of the Site Collection, if you try to browse the DEV SharePoint site you might get a 401 Unauthorized error. It’s because the extended zones of the Site Collection have been overwritten by the site collection restore and needs to be re-applied.

Run the following Powershell command to check the URLs after the restore:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ea 0

Get-SPSiteuRL http://portal-dev.abc.com:88

You will see the zones have changed

SharePoint-zone2

Run the following commands to fix this and get the old zones back:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ea 0

Remove-SPSiteUrl “https://portal.abc.com”

Set-SPSiteUrl -Identity “http://portal-dev.abc.com:88” -Zone Intranet -Url “https://portal-dev.abc.com” -Verbose

Get-SPSiteuRL http://portal-dev.abc.com:88

  1. Reset IIS and browse to the Target site

After performing an IIS reset you should be able to browse to the DEV site.

A server Restart may also be required.

  1. Restore Term Store ( Managed Metadata Service)

The term store also had to be restored from Source to Target. This was done with the following powershell commands on SharePoint.

Backup Source  Term Store (Production):

$mmsApplication = Get-SPServiceApplication | ? {$_.TypeName -eq “Managed Metadata Service”}

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

Export-SPMetadataWebServicePartitionData $mmsApplication.Id -ServiceProxy $mmsProxy -Path “c:\temp\mmsdata.cab” 

Restore to Target Term Store (Development):

$mmsApplication = Get-SPServiceApplication | ? {$_.TypeName -eq “Managed Metadata Service”}

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

Import-SPMetadataWebServicePartitionData $mmsApplication.Id -ServiceProxy $mmsProxy -Path “\\abc-az-sql-03\TermsE\mmsdata.cab” –OverwriteExisting 

NOTE 2: Make sure that the service account which is used to run the Managed Metadata Service has the “BulkAdmin” server role in SQL Server. This is role is only needed for the import. You can remove it afterwards. 

NOTE 3: If you get Permission Denied Error. The backup file needs to be located on SQL server as both SharePoint and SQL server need to work on this. Create a network Shared folder and provide exclusive access (read and write) to the Service account running Managed Metadata Service. Even if you set permissions to Everyone, it may not work, just give direct permissions to the service account. Also restart both SharePoint and SQL servers for the permissions to take effect. This took mw 2 hours to realize. 

  1. Republish InfoPath Forms

After restoring the site collection from the Live environment, the InfoPath forms need to be updated. Republish to the form library from InfoPath.

Need to do this as the URL for production is different to the dev site.

Update the submit data connection as well.

  1. Fix the hardcoded Links in the Restored SharePoint site if Any
  2. Fix Search and make sure all ResultSources exits in Target environment

Check if all Result sources exist in the Target Environment, if not manually create them

Also check the result types and create if anything is missing

  1. Restart The server
  2. Reset all Indexes and Restart the CRAWLs

The Search results should work now.

 

 

2,501 total views, 1 views today

About Author

Ricky Saini

Ricky Saini
Dynamics CRM, SharePoint, Office 365, Windows Azure and .Net Architect/Consultant/Freelancer in Australia ( Melbourne, Sydney and Canberra)

Leave a Comment