Tuesday 9 December 2014

Copy site collection from source farm to target farm



Copying content allows the replication of production data in another environment. The result will be identical environments, which provides the ideal testing environment.

Prerequisites

In order to successfully restore your data, make sure you fulfil the following requirements:
  1. Your account is in the local admin group of the production environment
  2. Your account is in the local admin group of the target environment
  3. The production environment should have the same or a lesser patch version than the target environment.
  4. Both environments should have the same solutions deployed for the source and target web applications.
  5. Your target site collection should not exist to avoid conflicts.

Database restore

Ask the SQL team nicely to restore a copy of the production content database of your source web application where the site collection resides, to the target SQL instance.

Note: Make sure the dbo of the target database is the web application service account of your target farm.
When the target database is restored, it’s time to bring it into SharePoint. Here a first decision has to be made:

Scenario 1: Different managed paths

In the case of different source and target managed paths, it’s impossible to directly attach the content database to the target web application.
  1. In order to successfully attach the content database, create a new –empty- web application. Empty means that there are no site collections created in the attached content databases of the web application.
  2. Attach the restored contentdatabase using the following command:
    1
    Mount-SPContentDatabase -Name "RestoredDatabase" –WebApplication http://emptywebapp/
    When the command is finished you get info about your new database:
  3. If your source farm has a different version than the target farm, you have to run an extra command to upgrade your contentdatabase to the right version:
    1
    2
    $db = Get-SPContentDatabase | ?{$_.Name –eq "RestoredDatabase"}
    Upgrade-SPContentDatabase $db
    The upgrade process might generate errors. The most common cause is that the source web application’s solutions aren’t deployed on the empty web application. You may safely ignore this error.
  4. Now that your content database is attached it’s time to move the site to the correct web application and managed path.
    1
    Backup-SPSite http://emptywebapp/ -Path C:\TEMP\backup.bak
    1
    Restore-SPSite http://sharepoint/site -Path C:\TEMP\backup.bak
    Make sure that when you restore your site, you target the right contentdatabase. You can use the –DatabaseName switch to specify where to restore the site collection on the target web application’s content databases.
  5. Make sure that you clean up after your restore was successful.
    • Delete the temporary bak file
    • Delete the restored content database
    • Delete the temporary web application
    • Delete the temporary web application’s content database
backuprestoremanagedpath

Scenario 2: Same managed paths

When the source and target web application’s site collection have the same managed path, it’s possible to directly attach the restored database to the target web application. You do this with the following steps:
  1. Attach the restored contentdatabase using the following command:
    1
    Mount-SPContentDatabase -Name "RestoredDatabase" –WebApplication http://emptywebapp/
  2. If your source farm has a different version than the target farm, you have to run an extra command to upgrade your contentdatabase to the right version:
    1
    2
    $db = Get-SPContentDatabase | ?{$_.Name –eq "RestoredDatabase"}
    Upgrade-SPContentDatabase $db

Result

When a site is moved from production to another environment, all it’s content is moved. Take into account that data might also reside in other places like the managed metadata term store.


 Reference:

http://bramnuyts.be/2012/01/12/copy-site-collection-from-source-farm-to-target-farm/

2 comments: