0

I've just taking over from a Sharepoint developer who has only worked in a single, live environment.

I want to set up a development environment (and subsequently also a UAT environment) and so to do this I need an exact (or near to exact as possible) clone of the live version, including all site collections, content and (ideally) permissions.

I have Googled and found that you can backup and restore single site collections using the Management Shell but to do each collection individually would be very time consuming.

Can anyone suggest a reliable way to do this?

Pandy Legend
  • 1,102
  • 3
  • 15
  • 29

1 Answers1

0

Why not just script it? Here is a small script I use:

[System.Console]::Clear()

write-host "remoting to live environment"

$siteCollectionUrl = "http://live.mysite.com";

if ($args.count -gt 0) {
   $siteCollectionUrl = $args[0]
   write-host "going to pullback content from $siteCollectionUrl"
}

$pwd = Get-Content c:\install\backups\crd-sharepoint.txt | ConvertTo-SecureString

$crd=new-object -typename System.Management.Automation.PSCredential -ArgumentList "dev\svc-sp-setup-dvt", $pwd

$s = New-PSSession -computername "liveServer" -Authentication CredSSP -Credential $crd

Invoke-Command -Session $s -Scriptblock {
param($siteCollectionUrl)
write-host "Connected, activating SharePoint snap-in..."
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction "SilentlyContinue"

write-host "Backing up $siteCollectionUrl remotely..."
backup-spsite -identity "$siteCollectionUrl" -path "c:\install\backups\scheduled_backup.bak" -force
} -args $siteCollectionUrl
#end session
Remove-PSSession $s

$path = "c:\install\backups\"
write-host "Copy backup locally..."
#copy
copy-item "\\liveServer\c$\install\backups\scheduled_backup.bak" $path -Force

write-host "restore...this may take a while if not already running in SharePoint PowerShell.  your patience is appreciated"
#restore
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"

restore-spsite -identity "$siteCollectionUrl" -path c:\install\backups\scheduled_backup.bak -force -confirm:$false

$username = [Environment]::UserName

write-host "have a great day, $username"

This does require PowerShell remoting to be enabled. If you have a list of sites, you can simply call this script repeatedly with the URLs of the site-collections you would like to copy, e.g.

$scriptPath = Join-Path (get-location) "backup_and_restore.ps1";
& $scriptPath "http://admin.accounting.mycompany.com"
& $scriptPath "http://admin.sales.mycompany.com"
& $scriptPath "http://admin.marketing.mycompany.com"
& $scriptPath "http://admin.engineering.mycompany.com"

Alternatively, you could create a backup per site collection in the script, and then restore them in kind. This would be dramatically more efficient since you wouldn't have to restart the SharePoint snap-in, but I'll leave that up to you to decide what's best in your situation.

Jaime Torres
  • 10,365
  • 1
  • 48
  • 56