SharePoint 2013 Backup with PowerShell and Task Scheduler

You can do Everything with PowerShell – yes everything – and SharePoint is no exception. In this post for beginners, I will show you how to create tasks for the Task Scheduler to automate your SharePoint backups with PowerShell.

First, to backup your farm, you can use the PowerShell command Backup-SPFarm. For more details on this cmdlet, refer tohttp://technet.microsoft.com/en-us/library/ff607881.aspx. You can use the command to backup the farm a full backup as in the following example.

Backup-SPFarm -BackupMethod Full -Directory \\MyServer\SPBackups

And to backup the farm a differential backup, you can use the command as in the following example

Backup-SPFarm -BackupMethod Differential -Directory \\MyServer\SPBackups

To create a PowerShell script file, open a notepad file and save it as *.ps1. Let’s create two files – one for the full backup and another for the diff backup.

So create two files: SPFarmFullBackup.ps1 and SPFarmDiffBackup.ps1

In the first file for the full backup, type the following text.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”

Set-ExecutionPolicy -ExecutionPolicy “Unrestricted” -Force

Backup-SPFarm -BackupMethod Full -Directory \\MyServer\SPBackups

Save the file.

In the second file for the differential backup, type the following text.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”

Set-ExecutionPolicy -ExecutionPolicy “Unrestricted” -Force

Backup-SPFarm -BackupMethod Differential-Directory \\MyServer\SPBackups

Save the file.

Now, follow the steps below to create the tasks for Task Scheduler to automate the execution of backup files – let’s assume we will full-backup weekly and diff-backup daily.

1 – Open Tools > Tasks Scheduler

2 – In the center pane, right-click, and click Create Basic Task

3 – Assign the task a meaningful name – such as SharePoint-BackupFullWeekly

4 – Choose “Weekly ” on the When do you want the task to start screen

5 –  Specify the parameter for the weekly task schedule

6 –  Choose “Start a program” from the what action do you want the task to perform

7 –  On the start a program screen type in the command as the screenshot below. The Task scheduler is intelligent enough to recognize that you want to run PowerShell and that you supplied arguments.

Repeat the steps above to create a task for the diff backup.

Remarks:

 

One thought on “SharePoint 2013 Backup with PowerShell and Task Scheduler”

Leave a comment