[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 639
  • Last Modified:

Sharepont Backup Script suddenly failing

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 = "sharepoint@domain.com"
Const strTo = "user@domain.com"
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 _
	    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
	objEmail.Configuration.Fields.Item _
	    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strMailserver
	objEmail.Configuration.Fields.Item _
	    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 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

1 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now