Create a Scheduled Task for SharePoint Farm Backups using PowerShell
PowerShell makes it easy to backup your SharePoint farm. And combined with the Task Scheduler, it makes you even more productive!
In today’s blog post, we’ll use PowerShell to create the SharePoint Farm backup scripts, and automate them with the Task Scheduler.
We’ll create 2x backup scripts:
- Full backup > will run weekly
- Differential backup > will run daily
The process & results are applicable to SharePoint 2013 as well as SharePoint 2016.
Minimum requirements:
- Access to the SharePoint farm
- Permissions to create/run PowerShell scripts
Create a folder to store the backups
First step is to have a place to store the backups. We’ll create a folder called “SPBackups“.
Following Microsoft best practices, we want our backup folder to be as close as possible to the SQL Server (when possible).
We also need to grant the appropriate permissions to the service accounts performing the backup, and to the backups folder.
For more info about permissions regarding which backup/restore you wish to perform (farm, service applications, etc..) please refer to the official documentation.
Create the scripts for the backups
As said previously, we’ll create 2x PowerShell scripts using the Backup-SPFarm cmdlet:
- Full
- Differential
Those scripts are very basic for the purpose of this blog, but you get the idea 🙂
#FULL Farm Backup
#================
#Add SharePoint snappin if not running from SharePoint Management Shell
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction Stop
#Creation of the FULL backup
Write-Host "Backing up the Farm... Go grab a coffee and put your feet up!" -f Yellow
Backup-SPFarm -Directory \\SP1\SPBackups -BackupMethod Full -Percentage 5 -Verbose -Force -ErrorAction Stop
Write-Host "Congratulations! The FULL backup completed successfully!" -f Green
IMPORTANT:
Before you can run the first differential backup, a FULL backup needs to be performed.
After saving the file into .ps1, run PowerShell as Administrator, and run the script.
For the second script, amend the script by replacing the -BackupMethod parameter from “full” to “differential“.
Backup-SPFarm -Directory \\SP1\SPBackups -BackupMethod Differential -Percentage 5 -Verbose -Force -ErrorAction Stop
Create a task in the Task Scheduler
Now is the time to create an automated task because running the scripts manually every day/week is simply not an option!
On your Windows Server:
- Open Server Manager
- Tools
- Task Scheduler
- Right-click on “Task Schedule Library“
- Click on “Create a basic Task“
- Give the task a “Name“
- Give a “Description“
- Click “Next“
- Choose “Weekly“
- Click “Next“
- Specify the parameters that you need for the weekly task (backup)
- Click “Next“
NOTE:
Make sure that backups (full & diff) are performed out-of-hours for performance.
- Choose “Start a program“
- Click “Next“
- Enter PowerShell.exe in program
- Add Arguments => Where is the PS script for backup located
- Start in => Path of the backup folder
- Click “Next“
- Tick the box “Open properties dialog[….]“
- Click “Finish“
- Select the necessary options
- Click “OK“
- Enter the password
- Click “OK“
The task is now ready to run on a scheduled time! 🙂
Create a new task for the differential backup script, and don’t forget…. test, test, test!