Sunday, September 30, 2012

SharePoint Backup Method for Every Day of the Week


# Standard Load of the SharePoint plugin for PowerShell, nothing special here
$snapin = (Get-PSSnapin -name Microsoft.SharePoint.PowerShell -EA SilentlyContinue)

IF ($snapin -ne $null){write-host "SharePoint Snap-in is loaded"}
ELSE { write-host "SharePoint Snap-in not found... Loading now"
Add-PSSnapin Microsoft.SharePoint.PowerShell
write-host "SharePoint Snap-in is loaded"
}
# END Loading SharePoint Snapin

# Lets get the day of the week using the DateTime object
([system.datetime]$date = $([system.datetime]::now))
$dayofweek = $date.DayOfWeek

#set the location where you want to backup the farm
$backupDirectory = "\\server\folder\subfolder"

#If its Sunday let's do a full backup instead of a differental
if($dayofweek -eq "Sunday")
{
write-host "$dayofweek - Full Backup being Executed"
Backup-SPFarm -Directory $backupDirectory -BackupMethod Full
}
else
{
#Its not Sunday, so let's just do a differential backup
Write-Host "$dayofweek - Differential Backup Being Executed"
Backup-SPFarm -Directory $backupDirectory -BackupMethod Differential
}

No comments:

Post a Comment