Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
2  
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: quickmeme.com/meme/3pvcw2 –  Robert Kaucher Jun 26 '12 at 15:17
2  
Don't be afraid to bing or browse TechNet for the standard powershell commands. –  Mike Oryszak Jun 26 '12 at 16:35
add comment

2 Answers 2

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

Remove-SPWebApplication

$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
add comment

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:

Restore-SPFarm

Backup-SPFarm

http://technet.microsoft.com/en-us/library/ee890117

share|improve this answer
add comment

Your Answer

 
discard

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.