Skip to main content

Thinking out aloud - Dave Hunter's SharePoint Blog

Go Search
Home
Blog
  

Locations of visitors to this page


 Useful Links

  Microsoft UK events
  SharePoint 2007 on CodePlex
  SharePoint Community Portal
  SharePoint User Group
  SharePoint Community Portal
  SharePoint Pedia
  SharePoint MSDN Forums
  SharePoint University
Home > Thinking out aloud - Dave Hunter's SharePoint Blog > Posts > Powershell SharePoint 2007 Backup Script
My thoughts and findings on Microsoft Information worker technologies, including MCMS and SharePoint 2007 (MOSS).
Powershell SharePoint 2007 Backup Script
I’m still not bought on the whole Powershell and SharePoint idea but I’m getting there.  I found this example script that cleans up the old backup files and then performs a full farm backup of MOSS.

When performing backups of SharePoint using Central Administration or STSADM, backup files are created in a specified UNC path.  If you don’t keep an eye on this location and delete/archive old backups this can grow out of control.  Cleaning up backup files isn’t straightforward either, it involes manually editing the spbrtoc.xml file in the backup location and then deleting the backup folders that relate to the backups you removed from the XML file. 
 
This is where Powershell adds value.

# Clean-up (old) backup files created by WSS v3 (STSADM.EXE)
# Created by Marco
# Tested with PowerShell RTM v1.0

# Location of spbrtoc.xml
$spbrtoc = "\\server\backup\Sharepoint\spbrtoc.xml"

# Days of backup that will be remaining after backup cleanup.
$days = 14

# Import the Sharepoint backup report xml file
[xml]$sp = gc $spbrtoc

# Find the old backups in spbrtoc.xml
$old = $sp.SPBackupRestoreHistory.SPHistoryObject | ? { $_.SPStartTime -lt ((get-date).adddays(-$days)) }
if ($old -eq $Null) { write-host "No reports of backups older than $days days found in spbrtoc.xml.`nspbrtoc.xml isn't changed and no files are removed.`n" ; break}

# Delete the old backups from the Sharepoint backup report xml file
$old | % { $sp.SPBackupRestoreHistory.RemoveChild($_) }

# Delete the physical folders in which the old backups were located
$old | % { Remove-Item $_.SPBackupDirectory -Recurse }

# Save the new Sharepoint backup report xml file
$sp.Save($spbrtoc)
Write-host "Backup(s) entries older than $days days are removed from spbrtoc.xml and harddisk."

  • Create a batch file on the SharePoint 2007 server with the following commands:

STSADM –o backup –directory \\server\backup -backupmethod full -quiet
powershell.exe c:\scripts\SPFullFarmBackup.ps1

  • Save the file and add a scheduled job for the batch file.
This script:
  • Queries the spbrtoc.xml file and finds all the backups.
  • Deletes older backups (by the value of days specified in the script – in this case 14 days).
  • Deletes the associated backup files from the UNC path and save the updated spbrtoc.xml.

Thanks for Marco for the backup script http://blog.wauwwie.nl/Lists/Categories/Category.aspx?Name=MOSS%202007%20%2F%20WSS%20v.3

  Copyright
This work is licenced under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.0 UK: England & Wales License
  Site Map

Comments

There are no comments yet for this post.

 Dave Hunter

I'm currently a Senior Consultant at Netstore 2e2. I specialise in Microsoft Information Worker technologies (especially MOSS, MCMS and .NET), with over 8 years of experience within this area of specialism. 

I have gained two certifications for MOSS and WSS and look to complete the full certification track soon.

View Dave Hunter's profile on LinkedIn

  Subscribe in a reader


 Latest Posts

I’m attending the first ever SharePoint Saturday in the UK31/08/2010 19:43
I’ve re-joined CIBER UK31/08/2010 19:26
I’ve been Awarded a MVP for SharePoint01/04/2010 19:49
SharePoint 2010 Training on Microsoft E-Learning15/03/2010 17:56
SharePoint UK User Group - Thursday 27th August London Meeting25/08/2009 17:56
CAML Query that filters on the current user23/07/2009 17:50
Microsoft Ramp Up Free SharePoint Developer Training22/07/2009 20:59
How To: Change a SharePoint Application Pool Programmatically07/07/2009 18:08
SharePoint Forums Topping 100 Answers06/07/2009 12:29
Find out the SharePoint Internal Name for a Column or Site Column28/05/2009 09:56
1 - 10 Next