Home / content migration / SharePoint Content databases move from one farm to another – data refresh process across farms

SharePoint Content databases move from one farm to another – data refresh process across farms

            Today we will see how we can get all the content (including Site Collections and Content Databases) from one SharePoint Farm to another farm. This also including content from Project Server Databases.

          While we are planning to upgrade SharePoint 2010 to 2013, we need to replicate the upgrade process in staging farm  to be as close to production farm. The main goal here is to move all the current content and from production farm to a staging farm where both the SharePoint farms share a similar architecture in terms of servers, service applications and web applications.

Note: project server db refresh process will follow in next post 🙂

The High level Plan:

  1. Gather all the web applications and their content databases.
  2. Get all the content databases from TST/Stagning env. where you want to detach all the databaess.
  3. Detach all the databases from the farm using a simple command or script (check below)
  4. Once verified all the databases have been detatched and remove them from DB servers.
  5. Backup and restore databases from PROD db server to this staging farm.(make sure the db owner is changed to farm service account)
  6. Mount the databases restored from prod and set the necessary max and warning site count.
  7. Restore any custom databases which are being used for any third party tools or custom solutions from PRD to Stage farm
  8. Clear all the SharePoint Timer cache.
  9. Reset all the search index data for all the search applications and once attached all the databases fire a full search.
  10. If you have blog cache implemented then you need to refresh the cache (delete and let it rebuild again)
  11. Restore “emailenabledlists” table from sharepoint_config database (what ever is the config db in prod ) to stage (optional: this isonly required if you need the email enabled lists and email details of the lists/doc. libraries/discussion forums you want to restore)
The remaining challenges for the staging farm to be identical was to migrate the managed metadata database from prd farm and 
Now lets see the basic PowerShell cmdlets to be executed for the above steps:
Web application – site collections and content databases can be gathered: (execute for each web application)
PowerShell shell:\>Get-spcontentdatabase  -webapplication http://webapplication | select name  > c:\webapplicationname-contentdatabase.txt
Note: In case if we use more than one SQL DB instances, we need to make sure content databases are restored in respective DB instances as per the farm architecture.
UnMount Databases – Simple PowerShell script – copy all your databases we captured in the above step to one file:
$dblist = get-content c:\stg-detatchdb.txt
foreach($db in $dblist)
      dismount-spcontentdatabase -identity $db -Confirm:$FALSE
Attached databases in Stg farm:
$dblist = get-content c:\stg-attachdb.txt
foreach($db in $dblist)
Mount-SPContentDatabase -WebApplication http://webappname -Name $db -Confirm:$FALSE -DatabaseServer “dbsrever\instance” -MaxSiteCount -WarningSiteCount
# your can use the below command to again set the max and warning site count
#Set-SPContentDatabase -identity $db -Confirm:$FALSE -MaxSiteCount 1 -WarningSiteCount 0
You can clear the timer cache either manually on each server in the following way 
Either you can clear the cache using a simple script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$servers = getspserver | ? { $_.Role eq “Application” }
$configDb = Get-SPDatabase | ? {$_.TypeName -eq “Configuration Database”}
$guid = $configDb.Id
foreach($spserv in $servers)
set-service -computername $spserv -Name sptimerv4 -status stopped
sleep 5
Remove-Item “\\$spserv\c$\ProgramData\Microsoft\SharePoint\Config\$guid\*.xml”
Set-Content “\\$spserv\c$\ProgramData\Microsoft\SharePoint\Config\$guid\cache.ini” “1”
sleep 5
set-service -computername $spserv -Name sptimerv4 -status Running
sleep 300

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
foreach($webApp in $WebAppServices)
     Write-Host $webApp
Remove-PsSnapin Microsoft.SharePoint.PowerShell
This completes the content db restore from one farm to another, I will write how to restore project server db refresh in next post.
Do write me back on your opinions and if we can improve on this process and include any missing pieces.

About Venu Madhav

Check Also

PowerShell Script – list all SharePoint group members

A quick script to query  site collections in a web application for SharePoint group and ...

Leave a Reply