Home > Microsoft > SharePoint 2010 Backup

SharePoint 2010 Backup

June 20, 2012

First off you need to have a service account that is “sysadmin” on the SharePoint databases and is an SharePoint admin service account.
Second,  create two PowerShell script , two batch files and a scheduled task on the SharePoint Application server:

number 1:
Add-PsSnapin Microsoft.SharePoint.Powershell
Backup-SPFarm -Directory \\P1SPAPP01\Backup -BackupMethod full

Save it as backupsharepointfarm.ps1

number 2:
# Location of spbrtoc.xml
$spbrtoc = “D:\Backup\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
Write-host “Backup(s) entries older than $days days are removed from spbrtoc.xml and harddisc.”

Save it as: “cleanbackups.ps1”

then create two batch files thats executing the Powershell scripts:

number 1:
powershell -command D:\Backup\Script\BackupSharePointFarm.ps1

Save it as “backup.bat”

number 2:
powershell -command D:\Backup\Script\cleanbackups.ps1

Save it as “clean.bat”

Then create a “Sheduled task” on the application server that runs both the batch files and under the user that is your SharePoint service account.

Woila! you now get an backup evry day at 22:00 (10PM) and stores the backup for 14 days.

%d bloggers like this: