SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need a PowerShell script which could perform the following:

  • How to Back up and Content Database of a Web Application
  • Restore a Content Database on a newly created Web Application
share|improve this question
and what is your question ? – Steve B Jun 26 '12 at 14:42
I need a PowerShell script which could handle both of above things :) – Geek Jun 26 '12 at 14:55
this is still not a question. Anyways, Why don't you simply detach DB from the source app, then reattach the DB to the target APP (backup the ocntent database in SQL server first) – Steve B Jun 26 '12 at 14:57
Because Steve B's comment bears repeating: – Robert Kaucher Jun 26 '12 at 15:17
Don't be afraid to bing or browse TechNet for the standard powershell commands. – Mike Oryszak Jun 26 '12 at 16:35
up vote 2 down vote accepted

If both web apps are in the same farm, the fastest and easiest way is to detach DB from app A and reattach DB from B.

$srcApp = Get-SPWebApplication http://app1
$targetApp = Get-SPWebApplication http://app2

$dbs = Get-SPContentDatabase -WebApplication $srcApp  | % { $_.Name }

Get-SPContentDataBase -WebApplication $srcApp | Dismount-SPContentDataBase


$dbs | % { Mount-SPContentData -Name $_ -WebApplication $targetApp }

This script should do the job (can't test by now, don't fire it blindly).

[Edit] and of course, backup the whole content database before

share|improve this answer

Using the SharePoint PowerShell console

Backup-SPFarm -Directory <BackupFolder> -BackupMethod {Full | Differential} -Item <WebApplicationName> [-Verbose]

See this MSDN article: Use Windows PowerShell to back up a Web application in SharePoint Server.

Use this command to restore a content DB:

Restore-SPFarm -Directory <Backup folder name> -RestoreMethod Overwrite -Item <Content database name> [-BackupId <GUID>] [-Verbose]

See this TechNet article: Use Windows PowerShell to restore a SharePoint content database.

Please ensure that you understand these commands and run tests to know what is going to happen. Other links:



share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.