Task Scheduler To Automate The Execution Of Backup For SharePoint (by Prashant Kumar)

Task scheduler is required to automate the execution of backup files. In my last article, I have written about SharePoint full and differential backup, using central admin and PowerShell. Today, I am going to show you how to automate the execution of the backup file, using backup files script in task scheduler. Task scheduler is a constituent of Microsoft Windows that provides the ability to schedule the launch of the programs or the scripts at pre-defined times or after specified time intervals for task scheduling. With the help of task scheduling, we can reduce work for administrative department as well. We will get output efficiently without any extra resource utilized for the same.

Task scheduler was announced with Microsoft Windows 95 as a system agent, which was changed in successive operating systems by Microsoft. A task is clearly defined by associating or relating a set of actions, which can include launching an Application or taking some custom-defined action, to a set of triggers, which can either be time-based or an event-based. The function is available for task scheduler with those defined task states and configured accordingly.

Thus, let’s continue with how to configure Task Scheduler to automate the execution of backup files.

As we know, SharePoint 2013 backup structure and recovery processes includes farm backup and recovery. We can complete backup and recovery operations by using SharePoint central administration Website or Windows PowerShell cmdlets.

Refer to the URL given below for more details about backup in SharePoint 2013

The step by step configuration with the screenshots is given below.

  • Start PowerShell ISE with administrator rights and copy the command given below with modification, as per your environment.

  • One folder should be created on the local system or network and should be shared with full permission to copy the backup on the destination folder.

  • The command syntax which is given below for the same also shows you how to run it and what will be the result at the end.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”

Set-ExecutionPolicy -ExecutionPolicy “Unrestricted” -Force.

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

Add-PSSnapin “Microsoft.SharePoint.PowerShell”.

Set-ExecutionPolicy -ExecutionPolicy “Unrestricted” –Force.

Backup-SPFarm -BackupMethod Differential -Directory \\MyServer\SPBackups -Item <ContentDatabaseName> [-Verbose].

  • Required changes are highlighted with RED: Please input your entry here for directory and content DB Name, if you are going for differential

  • Once modification is done, save those above script file on the local system drive with ending .PS1 file

  • Let’s create two files – one for the full backup and another for the diff backup.

  • Now, save those script files above with an appropriate name and one by one, you can save those file as fullbackup.PS1 and DiffBackup.PS1

Now, follow the steps given below to create the task for task scheduler to automate the execution of the script backup file.

  • Open Tools called tasks scheduler, using Windows button or command taskschd.msc.

  • In the center pane, right-click and click Create Basic Task or just click on the task, if we are going for full backup, we need to schedule this task weekly or monthly.

Now, we will go ahead and schedule differential backup with an advanced option available on task scheduler

  • Follow the same steps listed above for opening task scheduler and creating path for copying the backup file, if we wish to copy the backup file in the network file should be shared with full permission.

  • Now, select task scheduler and select Create task instead of basic task.

  • Now, on the prompt screen, assign the name, description and select security option  for when this task should be triggered. Here, we can change the user or group also. We can see on the screenshot given below, once everything is done, move to next tab called Triggers.

  • On the triggers page, we need to add New trigger and select the schedule time from the settings page and select other more advanced tasks from advanced settings like how frequently it should be run and expiration. Once done, click OK and move to the next tab. See the screenshot given below.

On the Action Page, we need to select an action from the drop down of the page, add program or script by browsing the file located on the system, add argument (optional).

  • In the next tab settings, select available option from the screen, if we wish or we can complete this process by selecting OK. Once we will select OK, so just start first time by clicking on task and RUN. See the screenshot given below for more details.

  • Once we have started task, we can see the history from history tab to track the issue, and the same log will be created to an event log, which can be referred to.

Now, this is done. From here, we will keep getting new backup copy for each time interval, which we have mentioned above.

A few important points are there to execute the above task

  • Don’t forget to assign SQL Server agent Service account; a write permission on the backup folder

  • Add-PSSnapin in the script file loads the Microsoft.SharePoint.PowerShell snap-in in the PowerShell sessionhttp://technet.microsoft.com/en-us/library/hh849705.aspx

  • Set-ExecutionPolicy -ExecutionPolicy Unrestricted allows you to run PowerShell script http://technet.microsoft.com/en-us/library/ee176961.aspx

  • Backup-SPFarm -Directory <Assign the local system path for better performance> -BackupMethod {Full | Differential} -Item <ContentDatabaseName> [-Verbose]

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

TOP