3

We have a WSS 3.0 solution.

We want to run a full backup of the SharePoint farm once per day.

What is the best way to do this? Is there a way to shedule backups from within SharePoint or do we need to create a powershell script and use a different tool to schedule it.

3 Answers 3

4

The most robust, free, plug-n-play solution I've found was this vbscript:

    Option Explicit

' Email source address
Const strFrom = "[email protected]"
'Email destination address
Const strTo = "[email protected]"
' Mail server address
Const strMailserver = "smtp.host.com"
'Mail Server Schema
Const strSchema = "http://schemas.microsoft.com/cdo/configuration/"

Dim varWeekDay, loopCounter, sharepointProcess, NodeList, Node
Dim objShell, objWMIService, objXMLDoc, objEmail, objFSO
Dim strRegKey, strMOSSPath, strBackupLocation, SharPointBackupRestoreTable, strComputer

Set objShell = CreateObject("WScript.Shell")

' Create variable used to contain the name of day
varWeekDay = (WeekdayName(Weekday(date)))

' Obtain the path where stsadm is located on the server
strRegKey = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Location")
'Sets stsadm folder string
strMOSSPath = strRegKey & "BIN\"

'sets backup folder string
strBackupLocation = "\\server\share$\" & varWeekDay

' Define the path to SharePoint Backup Restore Table file which contains
' crucial information regarding the outcome of the backup
SharPointBackupRestoreTable = strBackupLocation & "\spbrtoc.xml"

'*********************************************************
'Main Code Starts
'*********************************************************
'Deletes weekday folder only
Call deleteBackupFolder (strBackupLocation)

'Ensure the script runs in the SharePoint directory
objShell.CurrentDirectory = strMOSSPath

' Execute stsadm backup command
objShell.Run ("stsadm -o backup -directory " & strBackupLocation & " -backupmethod full")

' This Do loop checks the status of the backup process every minute.
' If the backup process hasn't completed within 60 minutes an email is sent to the
' Sharepoint administrator notifying him/her about this, otherwise an email is sent
' notifying the SharePoint Administrator of the outcome of the backup
Do
    loopCounter = loopCounter + 1

    If loopCounter > 60 Then
        Call SendEmail("SharePoint Backup Process exceeded 60 minutes", "SharePoint backup process has been running for over 60 minutes.  Please check progress of backup.")
    End If

    ' Wait for 1 minute
    WScript.Sleep 60000

    ' Check if the backup process (i.e. stsadm.exe) is currently running
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set sharepointProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'stsadm.exe'")

    If (sharepointProcess.count) = 0 Then
        ' Backup process has ended therefore check the SharePoint Backup Restore Table to analyse the outcome of the backup
        Set objXMLDoc = CreateObject("Microsoft.XMLDOM")

        objXMLDoc.async = False
        objXMLDoc.load(SharPointBackupRestoreTable)
        Set NodeList = objXMLDoc.documentElement.selectNodes("//SPErrorCount")

        For Each Node In NodeList
            If (Node.text) <> "0" Then
                ' Backup errors were generated
                Call SendEmail("SharePoint Backup Process Failed", "SharePoint backup failed with errors. Please investigate backup logs")
                Else
                ' No backup errors were generated
                Call SendEmail("SharePoint Backup Process successfully completed", "SharePoint backup completed without errors - " & strBackupLocation)
            End If
        Next

        Exit Do
    End If


Loop


'Sends email with status of backups
Sub SendEmail (subject, body)
    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = strFrom
    objEmail.To = strTo
    objEmail.Subject = subject
    objEmail.Textbody = body
    objEmail.Configuration.Fields.Item _
    (strSchema & "sendusing") = 2
    objEmail.Configuration.Fields.Item _
    (strSchema & "smtpserver") = strMailserver
    objEmail.Configuration.Fields.Item _
    (strSchema & "smtpserverport") = 25
    objEmail.Configuration.Fields.Update

    On Error Resume Next
    objEmail.Send
    On Error GOTO 0
    Call WriteEvent(subject,body)
End Sub

' Log the backup outcome to server application event log
Sub WriteEvent(subject,body)
    If subject = "SharePoint Backup Process successfully completed" Then
        objShell.LogEvent 0, body
    Else
        objShell.LogEvent 1, body
    end If
End Sub

Sub deleteBackupFolder (backupLocation)
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    If (objFSO.FolderExists(backupLocation)) Then
        ' Delete existing backup folder
        objFSO.DeleteFolder(backupLocation)
        ' Create new backup folder
        objFSO.createFolder(backupLocation)
    Else
        ' Folder not present therefore create new folder
        objFSO.createFolder(backupLocation)
    End If
End Sub

I'd love to say this is my handy work, but it isn't. I'm not sure where I've found it, but it sure is useful.

Cheers, Matt

1
2

You can use STSADM command line utility's backup method for full and differential backups. Once you write your batch file, you can schedule it using Windows Scheduler.

Also note that your batch file should be able to generate a new target file name on a daily basis (it may contain file name like ddMMYYYY_FullBackup.bak) so that it does not override the target file every day.

1

One thing you could consider is backing up the database once per day (or more often), this can be done by simply creating a backup task in SQL Server. You can restore those whenever you like. Also, I assume you've virtualized the server, so a full/incremental server backup would help a bit.

Off-course this is a bit much, so perhaps a backup via stsadm would suffice in your situation. I like the script of iOnline247 very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.