Archive for the ‘3.0’ Category

PowerShell SharePoint Site Collection Backup Script March 14th, 2010

Mike

I have been meaning to write a script in PowerShell to do SharePoint Site Collection backups for a while but not got round to it. I did do a quick and functional one at the tail end of last year, but it wasn't particularly elegant. This script I am much happier with: it will backup all Site Collections at the specified Web Application and place them at the given location in a folder constructed from the day's date. It also writes to a log file and can clean up folders containing backups that are older than a predetermined number of days.

Simply copy the script below and save it to a .ps1 file of your choice. Please retain my comments at the top and, as always, use at your own risk! The deletion portion is quite destructive :) . You may also have to set your Execution Policy to a less strict setting, such as RemoteSigned, e.g.:


Set-ExecutionPolicy RemoteSigned

I have tested the script with Microsoft Office SharePoint Server 2007 SP2 and Windows SharePoint Services 3.0 SP2 running on Windows Server 2003 R2 SP2 (PowerShell 1.0). It should work fine for MOSS and WSS running on different Windows Server operating systems.

Here is the script:

# SharePoint Site Collection Backup Script
# Author: Michael Cox
# Version: 1.0
# Date: March 2010
# Contact: http://www.betteritsolutions.co.uk/
# Use at own risk, please retain these comments

# Create alias for STSADM
Set-Alias -Name exeStsadm -Value ($Env:CommonProgramFiles + "\Microsoft Shared\Web Server Extensions\12\BIN\stsadm.exe") -Option Constant
# Specify maximum age in days for backup files
New-Variable -Name maxFileAge -Value 14 -Option Constant
# Get todays date, formatting as yyyyMMdd e.g. 20100224
New-Variable -Name todaysDate -Value (Get-Date -Format yyyyMMdd) -Option Constant
# Specify backup location and set log file location, folder must exist and be writable by account running script
New-Variable -Name backupLoc  -Value "S:\Backups" -Option Constant
New-Variable -Name logFileLoc -Value "$backupLoc\site_collection_backups.log" -Option Constant
# Specify Web Application
New-Variable -Name webApplication -Value "http://mossintranet/" -Option Constant

# Change to backup location and create folder, suppressing notification
Set-Location $backupLoc
New-Item $todaysDate -type directory | Out-Null
Set-Location $todaysDate

# Record backup start
Out-File -FilePath $logFileLoc -Append -InputObject $("Backup started at: " + (Get-Date -Format HH:mm` dd/MM/yyyy) + "`n")

# Enumerate Site Collections within chosen Web Application and store in a variable
[xml]$sitesXml = exeStsadm -o enumsites -url $webApplication

# Enumerates each site collection and performes an stsadm sitecollection backup against each site
$sitesXml.Sites.Site | ForEach-Object -Process {$backupFile = $_.Url.Replace('http://','').Replace('/','_') + ".bak"; exeStsadm -o backup -url $_.Url -filename $backupFile; Write-Host "Finished writing: $backupFile"; Out-File -FilePath $logFileLoc -Append -InputObject "Finished writing: $backupFile"}

# Remove folders that are older than the maxFileAge value
Set-Location $backupLoc
$tooOld = (Get-Date).addDays(-$maxFileAge)
Get-ChildItem | Where-Object {$_.PSIsContainer -and ($_.lastWriteTime -le $tooOld)} | ForEach-Object -Process {Remove-Item $_ -force -recurse; Write-Host "Folder $_ was deleted."; Out-File -FilePath $logFileLoc -Append -InputObject "Folder $_ was deleted."}

# Record backup end
Out-File -FilePath $logFileLoc -Append -InputObject $("`n" + "Backup ended at: " + (Get-Date -Format HH:mm` dd/MM/yyyy) + "`n")

Here is a screenshot of files created following a backup of a Web Application with two Site Collections and also the contents of the log file:

Screenshot after running script

Screenshot after running script

Please let me know if this is useful and also feel free to make suggestions for improvements or bug fixes, if you find any.

Continue reading...


 

Search Server Express 2008 Requires SP2 on Windows Server 2008 R2 November 30th, 2009

Mike

I recently installed Windows SharePoint Services (WSS) 3.0 with SP2 on Windows Server 2008 R2, with the intention of adding Search Server Express 2008 for enterprise search functionality. However, when I tried to run the Search Server install I was greeted with the following unfriendly message:

Program Compatibility Assistant

Program Compatibility Assistant

After some digging around and Googling, I discovered that Search Server wouldn’t install on Server 2008 R2 without Service Pack 2. Unfortunately, it doesn't appear possible (at this time) to download it with SP2 so what do you do? I did a little experimenting and found out that you can slipstream the The 2007 Microsoft Office Servers Service Pack 2 (SP2) into the install. Note that the download page actually specifies the service pack will update Search Server. Here's how to slipstream it:

  1. Open a command prompt, navigate to the location of the file SearchServerExpress.exe and run SearchServerExpress.exe /extract:SearchServer. This extracts (but doesn't install) Search Server Express to the folder SearchServer.
  2. Download the 2007 Microsoft Office Servers Service Pack 2 to the same location as the install file for Search Server Express.
  3. From the same command window, run officeserver2007sp2-kb953334-x64-fullfile-en-us.exe /extract:SearchServer\Updates (you will have downloaded the 64–bit version as Windows Server 2008 R2 is 64–bit only). This extracts the service pack files into the Updates folder of the Search Server install.
  4. Run setup.exe from within the SearchServer folder

 

You should find that the Search Server install now runs happily without complaining and pauses for a period of time to apply updates towards the end of the process.

Happy searching!

Continue reading...