Full SharePoint Farm Backup with File Rotation

Performs scheduled full farm backups of SharePoint 2007 or SharePoint 2010 farms. It runs a Full backup on a weekly basis, and incremental backups on all other days. It should be configured as a daily scheduled task. It will also delete older backups to conserve space.

 
 
 
 
 
4.6 Star
(23)
Add to favorites
SharePoint
5/26/2011
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • SharePoint 2013 Farm Backup
    1 Posts | Last post September 11, 2015
    • Can you provide an updated script that has been fully tested in SharePoint 2013?
  • 2013
    2 Posts | Last post January 16, 2014
    • I'd love to use this for 2013.  What would I need to change?
    • Sorry, for some reason I missed the notification on this question. I don't think a whole lot changed with the Backup cmdlets and/or APIs going from SharePoint 2010 to SharePoint 2013, but I haven't at all gotten a chance to test that. My expectation is that there may be some modification necessary just because there always is something different but I'm not aware of anything specifically that will change it. 
  • Backup farm error
    1 Posts | Last post July 25, 2012
    • Ran the following script and got the error message
      
      http://gallery.technet.microsoft.com/9b99c435-8831-4c9e-a70b-1f13158ef22a.
      
      
      PS D:\Scripts> ./fullbackupwithfilerotation.ps1 -drive "D:" -backupDir "\\devwin
      app3\Backupfarm" -fullBackupDay "Sunday" -Backup-SPFarm -ConfigurationOnly -Forc
      e -nbrDaysRetained 14
      
      Backup-SPFarm : The backup job failed. For more information, see the error log
      that is located in the backup directory.
      At D:\Scripts\fullbackupwithfilerotation.ps1:211 char:20
      +       Backup-SPFarm <<<<  -directory $backupDir -backupmethod $backupMethod
          + CategoryInfo          : InvalidData: (Microsoft.Share...mdletBackupFarm:
         SPCmdletBackupFarm) [Backup-SPFarm], SPException
          + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletBackupFa
         rm
      
      How do I fix this error message?
  • Enhancements
    1 Posts | Last post July 20, 2012
    • Thanks for the script John!
      
      Here are a few enhancements suggestions:
      
      1. Use "Backup-SPFarm -ConfigurationOnly -Force -..." option for the configuration backup instead of Backup-SPConfigurationDatabase, because the latter asks for as much space on the share as the full backup, which may not be available. Backup-SPFarm has -Force option to make a backup, anyway.
      
      2. For cleanup logic, use weeks instead of days. Based on the Full backup day parameter, determine when the last full backup is taken, and make sure to keep at least the last full backup.
      
      3. For error reporting, make sure the new backup folder was actually created before reporting a successful backup. On some occasions (lack of space or permissions issues) this created some confusion - success was reported when there was an error.
      
      Hope these tips will help somebody.
      
  • Write to Application Log
    2 Posts | Last post July 11, 2012
    • First, Thank you John for very detailed script , it took me about 4 hours to read through it. 
      
      
      
      I noticed that you can't write to the application log with undeclared application log source 
      
      You have to declare the application log source as source first , then can use it in the function
      
      
      I modified the function (Record-Event)  as follows, that was the only way it worked.
      
      
      
      
      
      # This function standardizes the process to write entries to the event log
      # about the backups progress 
      function Record-Event ([string]$eventMsg, [string]$entryType) 
      { 
      #$entryType = "Information"
      #$entryType can be any of the following  "Information, Error, Warning, Information, SuccessAudit, FailureAudit"
      $spEventSourceType = "SharePoint 2010 Backup Script"
      $logName = "Application"
      [system.diagnostics.EventLog]::CreateEventSource($spEventSourceType,$logName)
         # Write the event to the servers Application log 
         
         Write-EventLog -LogName $logName  -Source $spEventSourceType -EventId 10990 -Message $eventMsg -EntryType $entryType   
      } 
      # end Record-Event 
      
    • Figured it out 
      Looks like you always call  Check-LogSource function first, which will check and create the source if needed.
      
      I wanted to make it more generic and write to any log .
      
      please disregard my first question.
      
      Thanks for sharing this script.
      
  • Why Get-LogLocation gives incorrect path?
    1 Posts | Last post February 03, 2012
    • John,
      Why would the Get-LogLocation cmdlet finds a path relative to the location of the script when running the script in a development installation of SP 2010?
      (e.g. C:\Users\SPFarmAdmin\Documents\PowerShell\%CommonProgramFiles%\Microsoft Shared\Web Server Extensions\14\LOGS)
      
      Suggestion: You might consider adding a function to the script to send an email if the backup fails.
      
      # SendAnEmail allows sending an email for success/failure
      function SendAnEmail ($bodyMessageDetail, $backupResult)
      {
        if($backupResult)
        {
            $subject = "The SharePoint Farm Backup was SUCCESSFUL for $today"
            $body = "The SharePoint Farm Backup was SUCCESSFUL for $today. " + "$bodyMessageDetail"
        }
        else
        {
            $subject = "The SharePoint Farm Backup FAILED for $today"
            $body = "The SharePoint Farm Backup FAILED for $today. " + "$bodyMessageDetail"
        }
        $emailFrom = "SPADMIN@mpifix.com" 
        $emailTo = "kelder@mpifix.com" 
        $smtpServer = "exchmn1.mpifix.com"
        $smtp = new-object Net.Mail.SmtpClient($smtpServer)  
        $smtp.Send($emailFrom, $emailTo, $subject, $body) 
      } #End SendAnEmail
      
      
      # ... and in the Backup-Farm function:
      
            try 
            {
                Backup-SPFarm -directory $backupDir -backupmethod $backupMethod
                # SendAnEmail("", $True)
            }
            catch
            {
              $ErrorMessage = $_.Exception.Message 
              SendAnEmail("$ErrorMessage", $False)
            }
      
  • Email Notification...
    1 Posts | Last post December 25, 2011
    • Dear John,
      
      Thanks for a great script very useful and helpful.
      Just i have a simple question and i wish if you can provide me with an answer and the code :)
      Is there anyway for this script to send an email notification for the Backup Job Status (Success or Failed Job), and if there is an error can be displayed on the mail.
      
      Best Regards,
      Khaled
  • Great to have :)
    1 Posts | Last post September 30, 2011
  • There does not appear to be sufficient disk space available...
    2 Posts | Last post July 06, 2011
    • Hey John,
      
      Thanks for this great script!
      
      One problem I'm having, though, is when the script checks for available disk space before backing up. I am using the script to back up to a network share, but the script doesn't seem to be able to determine the space available on the remote computer's F: drive.
      
      Is this due to the fact that the $computer variable is defined as the local computer name from which the script is run (sharepoint server) and not the remote computer name?
      
      Thanks!
      
      Matthew S.
    • Hello again,
      I got the script running by changing the line:
      # Determine the amount of free space in MB on the drive targeted for backup storage
      $space = Get-FreeDiskSpace -drive $env:systemdrive -computer $env:computername
      
      to:
      $space = Get-FreeDiskSpace -drive $drive -computer $computer