SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

PowerShell script to back-up site collections

 

This script enumerates the user web-applications and backups up all site collections on each of them in a separate folder.

 

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null
cls

$rootBackupStorage = "d:\backup\data"

write-host `n`n===================================================================================================
get-date

$oContentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService;

[Microsoft.SharePoint.Administration.SPWebApplicationCollection]$waColl = $oContentService.WebApplications;

$waColl1 = $waColl | where-object {$_.IsAdministrationWebApplication -eq $FALSE}

foreach ($wa in $waColl1)
{

    $waName = $wa.Name

    write-host "`nVirtual Server: " $waName

    $sites = $wa.Sites

    write-host "Sites: " $sites.Count

    foreach ($obj in $sites)
    {
      $siteurl = $obj.Url.Replace("
http://","").Replace(":","").split("/")

       write-host "Backing up: " $obj.Url
      $dir = $siteurl[0]
      $site = [String]::Join("-",$siteUrl)
      $siteurl = $obj.Url

      New-item "$rootBackupStorage\$dir" -type directory -force | out-null

      #write-host "stsadm -o backup -url $siteurl -filename ""$rootBackupStorage\$dir\$site.backup"" -overwrite"
      stsadm -o backup -url $siteurl -filename "$rootBackupStorage\$dir\$site.backup" -overwrite

    }

}


Posted 02-27-2008 3:20 PM by arjanp

Comments

Links (2/27/2008) « Steve Pietrek’s SharePoint Stuff wrote Links (2/27/2008) « Steve Pietrek’s SharePoint Stuff
on 02-27-2008 7:16 PM

Pingback from  Links (2/27/2008) « Steve Pietrek’s SharePoint Stuff

charles wrote re: PowerShell script to back-up site collections
on 12-05-2008 5:30 PM

Thanks for the script, however I am getting the following error when I run it.  Looks like some type casting is not working properly.

Cannot convert value "Microsoft.SharePoint.Administration.SPSiteCollection" to type "System.Xml.XmlDocument". Error: "Data at the root level is invalid. Line 1, position 1."

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.