Search This Blog

Thursday 11 April 2013

Scheduling SharePoint Backups

Hi, To schedule SharePoint Central Admin backups you still to this day need to schedule it via a script.
This is so far up to SharePoint 2013.

Create the backup folder on your SQL Server, still playing with this but seems that backing up to your WFE sometimes can cause issues.
Share the folder with your farm users, sp_admin, sp_farm, sqluser.
i Have also started creating a Backup user with full rights everywhere(Full SQL, SP and server rights) and running the backup under it. Sorted out some issues i had.


Before you schedule it make sure you do a manual backup to the shared folder under Central Admin that it complete with no issues. Log in with your backup users for this.

If you get this error:  Operating system error 5(failed to retrieve text for this error. Reason: 15105).
BACKUP DATABASE is terminating abnormally.
Here is the solution(Backup user might also resolve this): http://daniecsp.blogspot.com/2013/04/sp2010-backups-failing-with-error.html

Now you can create the script file.
Here i changed my script to the following. Found this script at SharePoint Police and it work brilliantly
http://sharepointpolice.com/blog/2010/12/07/automated-powershell-script-to-backup-sharepoint-farm-or-site-collection-with-email-notification/

So, create a file with ps1 extension and with the following content:(Maybe copy it from the above link to make sure it is all 100% formatted)


****************************

# ==============================================================================================
# NAME: SP2010_Farm_Backup_With_Notification.ps1
# AUTHOR: Mukesh Parmar
# DATE: 07 December 2010
# COMMENT: A Powerful Script to take backup of the entire SharePoint 2010 Farm with email notification.
# Website: http://thecommunicator.co.cc
# ==============================================================================================
Add-PsSnapin Microsoft.SharePoint.Powershell –ErrorAction SilentlyContinue
try
 {
  $today = (Get-Date -Format dd-MM-yyyy)
 #Location of the Backup Folder
  [IO.Directory]::CreateDirectory("C:\Backups\Sharepoint\Scheduled\$today")
 # This will actually initiate the SPFarm backup.
  Backup-SPFarm -Directory C:\Backups\Sharepoint\Scheduled\$today -BackupMethod full
 # Edit the From Address as per your environment.
  $emailFrom = "SPBackupMcMethod@dac.co.za"
 # Edit the mail address to which the Notification should be sent.
  $emailTo = "daniec@dac.co.zam"
 # Subject for the notification email. The + “$today” part will add the date in the subject.
  $subject = "The SharePoint Farm Backup was Successful for "+"$today"
 # Body or the notification email. The + “$today” part will add the date in the subject.
  $body = "The SharePoint Farm Backup was Successful for "+"$today"
  # IP address of your SMTP server. Make sure relay Is enabled for the SharePoint server on your SMTP server
  $smtpServer = "10.10.10.2"
  $smtp = new-object Net.Mail.SmtpClient($smtpServer)
  $smtp.Send($emailFrom, $emailTo, $subject, $body)
 }
Catch
 {
  $ErrorMessage = $_.Exception.Message
  # Configure the below parameters as per the above.
  $emailFrom = "SPBackupMcMethod@dac.co.za"
  $emailTo = "daniec@dac.co.za"
  $subject = "The SharePoint Farm Backup Job failed on "+"$today"
  $body = "The SharePoint Farm Backup Job failed on "+"$today and the reason for failure was $ErrorMessage."
  $smtpServer = "10.10.10.2"
  $smtp = new-object Net.Mail.SmtpClient($smtpServer)
  $smtp.Send($emailFrom, $emailTo, $subject, $body)
 }


 ***************************


Edit the obvious parts as explained in the script.
Thanks Mukesh, this really helps allot.

Open PowerShell in Admin mode and run the ps1 file.(Stil logged on as backup user)
See if it completed without errors.

Now create a txt file, rename it to .bat and paste the line in there. Obviously change the path to your ps1 file path and name)
PowerShell -command C:\Backups\SharePoint\SPScheduledbackup.ps1

Ok, now you can double click on the bat file, let it run and check if there are errors.

If you get a error saying it is not digitally signed look here : http://daniecsp.blogspot.com/2013/02/powershell-script-not-digitally-signed.html

Now all that is left is to schedule it.

Open task scheduler.
Expand till below Microsoft and right click and choose "Create Basic Task"
Type name and click next


On the next 2 pages select the frequency you want to backup your SP.

Now click on the browse button and browse to your Bat file

You can also point to the PS1 directly with the following parameters:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
.\systemcheck.ps1
c:\script\

On this page check open properties and click next


Now  under General set your settings the same as screenshot. On configure for choose your o/s

After this you can click ok.
Right click on the task and make sure it completes successfully.

Hope this helps!




6 comments:

  1. Hey... You have nice Blog.. Keep follow this excellent work.
    Sharepoint Backup

    ReplyDelete
  2. Why create a batch file when you can call powershell directly and add your script path as an argument?

    ReplyDelete
  3. i Have actually started doing that...
    Must update this with that option. Thanks for pointing that out Paul

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Very nice post. This is awesome . Actually There is no longer an offline “Workspace” other than SkyDrive Pro, which only works for document access. SharePoint 2013 does not feature a search capability over documents, and the movement documents is not an easy task.
    sharepoint backup

    ReplyDelete