various shenanigans.

Scheduling Sharepoint 2010 Farm Backups

1. Create a folder on a local or network drive “backups”. Share that folder as “backups” and give the account you used to install SharePoint as well as the farm and SQL database accounts full access (share permissions and NTFS).

2. Create these files in a Folder somewhere:

• backup-full.ps1 – This script will backup your entire farm to the share you created. This script will contain the following:

Add-PsSnapin Microsoft.SharePoint.Powershell
Backup-SPFarm -Directory \ServerNameBackups -BackupMethod Full

• backup-diff.ps1 – This script create a differential backup of your entire farm to the share you created. This script will contain the following:

Add-PsSnapin Microsoft.SharePoint.Powershell
Backup-SPFarm -Directory \ServerNameBackups -BackupMethod Differential

• cleanbackups.ps1 – This script will check the spbrtoc.xml file and delete backups older than 7 days so you don’t run out of disk space. You can change $days value. This script will contain the following:

# Location of spbrtoc.xml
$spbrtoc = “\ServernameBackupsspbrtoc.xml”
# Days of backup that will be remaining after backup cleanup.
$days = 7
# 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 harddisc.”

• Backup-Full.bat – This is a simple batch file to run the above backup-full.ps1 script. Create a scheduled task to run it every Sunday. The file contains the following:
powershell -command X:YourFolderBackup-Full.ps1

• Backup-Diff.bat – This is a simple batch file to run the above backup-diff.ps1 script. Create a scheduled task to run it every night except Sunday. The file contains the following:
powershell -command X:YourFolderBackup-Diff.ps1

• Clean.bat – This batch file will run the script to clean out older backup files (cleanbackup.ps1). The file contains the following:

powershell -command X:YourFoldercleanbackups.ps1

3. Create a scheduled task that will run the .bat files you created and set them to run at night when no one’s around. You have to make sure the scheduled tasks are set to run with the SharePoint farm account. After a full week you’ll have a directory with 7 days worth of backups.

Note: In order to run PowerShell commands on your server, you need to open powershell and execute the following command: Set-ExecutionPolicy Unrestricted

There are several factors involved in running a successful scripted backup which are covered by Todd Klindt in the following Microsoft SharePoint forum thread: http://social.technet.microsoft.com/Forums/en-US/sharepoint2010setup/thread/f755e7c1-bd0a-4c00-9be6-bbca83cf666b/.

1.Your Central Admin app pool account must have read/write access to the location of the backups.

2.Your SQL Service account must have read/write access to the location of the backups.

3.If you’re running a farm backup from STSADM or Windows PowerShell, the account you’re running it as must have read/write access to the location of the backups

4.The location must be accessible from the SharePoint machine the backup is running on.

5.The location must be accessible from the SQL instance that SharePoint is trying to back up.

6.This is why all the examples are UNCs, \servershare, and not local paths, C:backups

7. You might see “A Specified Logon Session Does Not Exist” when creating the scheduled task.
Check to make sure that your “Local Security Policy” (under Security Settings – Local Policies – Security Options), “Network access: Do not allow storage of credentials or .NET Passports for network authentication” is Disabled:

Close Bitnami banner
Bitnami