Link to home
Start Free TrialLog in
Avatar of cktechnology
cktechnologyFlag for United States of America

asked on

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 = "10.10.10.10"
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
Do 
	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
Loop



	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
		Else
		  	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
	objXMLDoc.load(FileSpec)
	Set NodeList = objXMLDoc.documentElement.selectNodes("//SPErrorCount")
	For Each Node In NodeList
	   strStatus = (Node.text)
	   If strStatus <> "0" Then
	   	strMessage = "Sharepoint Backup Failed"
   		state = "Failed"
	   Else
	   	strMessage = "Sharepoint Backup Succeeded"
   		state = "Passed"
	   End If
	Next
  '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
	objEmail.Configuration.Fields.Update
	objEmail.Send
	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
   Else
	   objShell.LogEvent 1, strMessage
  end If
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of quihong
quihong
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial