Sharepont Backup Script suddenly failing

Posted on 2009-12-23
Last Modified: 2012-05-08
We had this great sharepoint script that used to run and backup our WSS daily. Recently it's been failing with this windows script host error: C:\\backupwss.vbs Line 53 Char 2; Error: Object required 'objXMLDoc.documentElement'
Code: 800A01A8
Source: Microsoft VBScript runtime error.

The script we are using is in the snippet below:

Any help would be much appreciated as now, instead of creating Folders with the day names full of wss backup info, it's just creating Empty folders and deleting the previous backups!!
Const strFrom = ""

Const strTo = ""

Const strMailserver = ""

strWeekDay = (WeekdayName(Weekday(date))) 'Day of week used to place backup in a particular folder

Set objShell = CreateObject("WScript.Shell")

'Find path of SharePoint installation and where stsadm is located

strRegKey =  objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Location") 

strWSSPath = strRegKey & "BIN\"

strBuPath = "\\server\sp_backup\" & strWeekDay

FileSpec = strBuPath &  "\spbrtoc.xml" 'Check XML in file to check on success or failure of Backup

Call DeleteAFolder (strBuPath)

objShell.CurrentDirectory = strWSSPath 'change script to run is sps bin directory

objShell.Exec ("stsadm -o backup -directory " & strBuPath & " -backupmethod full") 'Excute Backup Command

'This loop waits for the backup job to complete


	count = count + 1

	'This counter gives the script 20 minutes to complete.  If it does not complete in that time the script with notify the admin.

	If count > 240 Then

		Call SendEmail("Failed","The script took to long to run. Please Check")

	End If

	WScript.Sleep 5000

	strComputer = "."

	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

	Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'stsadm.exe'")

	numProcess = colProcesses.count

	If numProcess = 0 Then

	Exit Do

	End If


	Sub	DeleteAFolder (strBuPath)

		Set fso = CreateObject("Scripting.FileSystemObject")

		If (fso.FolderExists(strBuPath)) Then

   		 	fso.DeleteFolder(strBuPath) 'delete previous backup

 		  	fso.createFolder(strBuPath) ' Create folder for new backup


		  	fso.createFolder(strBuPath) 'If folder not present it will create folder

        End If

  	End Sub

'This sub routine inspects the XML file of the backup to ensure it was successful

Call BackupStat(FileSpec)

Sub BackupStat(FileSpec)

	Set objXMLDoc = CreateObject("Microsoft.XMLDOM")

	objXMLDoc.async = False


	Set NodeList = objXMLDoc.documentElement.selectNodes("//SPErrorCount")

	For Each Node In NodeList

	   strStatus = (Node.text)

	   If strStatus <> "0" Then

	   	strMessage = "Sharepoint Backup Failed"

   		state = "Failed"


	   	strMessage = "Sharepoint Backup Succeeded"

   		state = "Passed"

	   End If


  'If state = "Passed" Then

  Call SendEmail (state,strMessage)

  'end if

End Sub

'Sends email with status of backups

Sub SendEmail (state,strMessage)

	Set objEmail = CreateObject("CDO.Message")

	objEmail.From = strFrom

	objEmail.To = strTo

	objEmail.Subject = "SharerPoint ServerName" & state 

	objEmail.Textbody = strMessage

	objEmail.Configuration.Fields.Item _

	    ("") = 2

	objEmail.Configuration.Fields.Item _

	    ("") = strMailserver

	objEmail.Configuration.Fields.Item _

	    ("") = 25



	Call WriteEvent(state,strMessage)

End Sub

'writes to event log status of backup

Sub WriteEvent(State,StrMessage)

   If state = "Passed" Then

	   objShell.LogEvent 0, strMessage


	   objShell.LogEvent 1, strMessage

  end If

End Sub

Open in new window

Question by:cktechnology
    1 Comment
    LVL 16

    Accepted Solution

    Looks like your backup job is failing. That is obviously, but your script is not handling it correct. The previous backups are deleted because it is called before the actual backup is performed. Typically, you would want to delete the previous backup after a confirmation of a successful backup unless you don't have the space to hold two backups on disk. However, since you are only giving it 20 minutes to backup, I have to assume the databases isn't that big.

    My recommendation would be to echo out the exact command used in this line:

    objShell.Exec ("stsadm -o backup -directory " & strBuPath & " -backupmethod full")

    and run it locally from your SharePoint Server to see if any errors are generated.

    However, I would bet that your problem is that you have a hung backup job so the stsadm -o backup command will give you a error that a backup job is already running and hence no XML file to parse. You can verify this by trying to run the backup command locally on the SP Server. If this is the case, you will need to go into Central Admin->Operations->Back up and Restore. Somewhere in there you can kill the backup job.


    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    There is one common problem that all we SharePoint developers share: custom solution deployment. This topic can't be covered fully in this short article, so all I want to do in this one is to review it from a development-to-operations perspectiv…
    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now