When I first started working with Sharepoint 2007 I was frustrated having to use Central Administration to perform backups. I personally prefer the command line. I wanted a way to quickly perform farm backups and individual site backups without starting up Central Admin. Fortunately stsadm.exe and Powershell came to my rescue. Below are two functions that I first made to perform farm and site backups.
Steps to use the scripts
-
Add C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin added to your path .
-
Add these scripts to profile file in Powershell.
-
Create a shared directory for the backups. Make sure you have same permissions on the share as you would if backing up through Central Admin. This folder is basically a hot folder for instant backups.
$HotFolder = "E:\Backup\HotBackup\" + (Get-Date).dayofweek + "\"
function SpFarmBackup
{
if (Test-Path $HotFolder)
{
Remove-Item $HotFolder -recurse
New-Item $HotFolder -type directory
}
else
{
New-Item $HotFolder -type directory
}
$cmd = "stsadm -o backup -backupmethod full -directory " + $HotFolder + " -overwrite"
& cmd /c $cmd
}
function SpWebBackup ( $SiteName, $FileName)
{
$Backup = $HotFolder + $FileName + ".bak"
$cmd = "stsadm -o export -url " + """$SiteName""" + " -includeusersecurity -filename " + """$Backup""" + " -overwrite"
cmd /c $cmd
}
In my next post I will show you a more robust backup solution for Sharepoint with Powershell.