Windows 2003 Backup Query

  • Thread starter Thread starter Glenn Clark
  • Start date Start date
G

Glenn Clark

Hi All

I have found the script below for backing up and emailing a contact once
complete. My problem is that even though the backup was sucessfull I get a
email saying its failed. Can anyone shed any light on this as I am not too
good with these scripts

Many thanks Glenn

// ==========================[ File
Header ]===================================
// File: bn-backup.js
// Version: 3.5
// Date: 15th February 2008
// Author: David Hewison
// Licence: GNU General Public License V2
//
//
// This program is free software you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
//
//
//
// Note: Set the number of ntbackup log files in the overwrite cycle to 1.
// Setting in HKCU\Software\Microsoft\NTbackup\Log Files\Log File Count
// Set the script operating parameters in xData()
// Separate backups are done for each set to overcome problems with VSS/2003
// - see Microsoft's Tech note ID: 820852
// Backup name on command line has maximum length of 28 characters
// ===========================[
Variables ]====================================

var fso = new ActiveXObject("Scripting.FileSystemObject")
var FileHandle, ExitStatus=0, BackupStatus=0
var ForReading = 1, ForWriting = 2, ForAppending = 8
var EmailBody = "Supplementary information:\n\n"
var NewLabel, Tapedevice

// ===========================[ Main
Program ]=================================

EmailBody += OutlookWarning()

FileHandle = fso.OpenTextFile(IoLogFile(), ForWriting, true)
IoXMLHeader("", true, FileHandle)
IoLog("open", FileHandle)

BackupStatus = BackupStatus | Flag("firstset")
if (!((WScript.Arguments.length>0) && (WScript.Arguments(0).length<29)))
{
NewLabel = BackupLabel("")
BackupStatus += Flag("label")
}
else NewLabel = BackupLabel(WScript.Arguments(0))
if (BackupToDisk() && (xData(4040) == "")) BackupStatus +=
Flag("disk_path")
IoLogCustomerInfo(FileHandle)
IoXMLDataRaw("open", "System", FileHandle, GetData_TagAttributes("System"))
IoLogHostInfo(FileHandle)
if (BackupToTape() && ContinueBackup(BackupStatus,FileHandle)) Tapedevice =
TapeInitialisation(FileHandle)
if ((xData(3121)=="yes") && ContinueBackup(BackupStatus,FileHandle))
{
if (SharePointBackup(FileHandle))
{
EmailBody += GetData_SharepointSize(FileHandle)
}
}
if ((BackupToTape()) && (Tapedevice=="") &&
ContinueBackup(BackupStatus,FileHandle))
{
if (xData(4034) !="")
{
Tapedevice = TapeInitialisation(FileHandle)
if (Tapedevice=="")
{
EmailBody += "\nError: No tape media found.\n"
BackupStatus += Flag("no_tape")
}
}
else
{
EmailBody += "\nError: No tape device GUID found.\n"
BackupStatus += Flag("no_guid")
}
}
for (i=1i<5i++)
{
if (ContinueBackup(BackupStatus,FileHandle))
BackupStatus = BackupRun(Tapedevice, NewLabel, i, BackupStatus, FileHandle)
}
if ((xData(4031) == "yes") && (xData(4030)=="tape"))
{
if (ContinueBackup(BackupStatus,FileHandle) && ((BackupStatus &
Flag("firstset"))==0))
Tape_Eject(TapeLabel(Tapedevice, FileHandle), FileHandle)
}
GetData_LogicalDisk(FileHandle)
if (xData(3111) == "yes")
{
EmailBody += "\nExchange mailbox store size: " +
GetData_ExchStoreSize("mbx",FileHandle) + " GB\n"
EmailBody += "\nExchange public store size: " +
GetData_ExchStoreSize("pub",FileHandle) + " GB\n"
}
IoXMLDataRaw("close", "System", FileHandle, "")


IoLog("close", FileHandle)
FileHandle.Close()
Sleep(5)


if (xData(4024) != "yes") WScript.Quit(ExitStatus)

if (BackupStatus ==0)
{
Email(MyAddr(), xData(4023), xData(3001) + " " + NewLabel + " log",
EmailBody, IoLogFile(), ConCatenateFile())
WScript.Quit(BackupStatus)
}
else
{
Email(MyAddr(), xData(4023), xData(3001) + " " + NewLabel + " Failed",
EmailBody, IoLogFile(), "")
WScript.Quit(BackupStatus)
}

// ===========================[
functions ]====================================


function GetData_CompName()
{
var strComputer = ".", CompName=""
var objWMIService = GetObject("winmgmts:\\\\" + strComputer +
"\\root\\cimv2")
var e = new Enumerator(objWMIService.ExecQuery("Select * from
Win32_OperatingSystem","WQL",48))

for (!e.atEnd()e.moveNext())
{ objItem = e.item()

CompName = objItem.CSName
}
return(CompName)
}



function GetData_ExchStoreSize( store, LogHandle)
{
var Txt="", Units = "GB", LogF=0x00040000, size=0

if ((xData(3111) == "yes") && ((store=="mbx") || (store=="pub")))
{
if (store == "mbx")
{
size = FsFileSize(xData(3112), LogHandle) + FsFileSize(xData(3113),
LogHandle)
size = NumberConversion(size, "", Units,2)
if (FsLogFlag(LogF))
{
IoXMLDataRaw("open", "MSExchangeIS", LogHandle,
GetData_TagAttributes("GetData_MSExchangeIS"))
IoXMLData("Store", "mailbox", LogHandle)
IoXMLData("dBFile", xData(3112), LogHandle)
IoXMLData("StmFile", xData(3113), LogHandle)
IoXMLData("Size", size, LogHandle)
IoXMLData("Units", Units, LogHandle)
IoXMLDataRaw("close", "MSExchangeIS", LogHandle, "")
}
}
if (store == "pub")
{
size = FsFileSize(xData(3114), LogHandle) + FsFileSize(xData(3115),
LogHandle)
size = NumberConversion(size, "", Units,2)
if (FsLogFlag(LogF))
{
IoXMLDataRaw("open", "MSExchangeIS", LogHandle,
GetData_TagAttributes("GetData_MSExchangeIS"))
IoXMLData("Store", "public", LogHandle)
IoXMLData("dBFile", xData(3114), LogHandle)
IoXMLData("StmFile", xData(3115), LogHandle)
IoXMLData("Size", size, LogHandle)
IoXMLData("Units", Units, LogHandle)
IoXMLDataRaw("close", "MSExchangeIS", LogHandle, "")
}
}
}
return(size)
}



function GetData_LogicalDisk(LogHandle)
{
var strComputer = ".", Units = "GB",LogF=0x00040000
var objWMIService = GetObject("winmgmts:\\\\" + strComputer +
"\\root\\cimv2")
var e = new Enumerator(objWMIService.ExecQuery("Select * from
Win32_LogicalDisk","WQL",48))
if (FsLogFlag(LogF))
{
for (!e.atEnd()e.moveNext())
{ objItem = e.item()
if (objItem.DriveType == 3)
{
IoXMLDataRaw("open", "LogicalDisk", LogHandle,
GetData_TagAttributes("LogicalDisk"))
IoXMLData("DiskDrive", objItem.DeviceID, LogHandle)
IoXMLData("Description", objItem.Description, LogHandle)
IoXMLData("FileSystem", objItem.FileSystem, LogHandle)
IoXMLData("FreeSpace", NumberConversion(objItem.FreeSpace, "", Units,2),
LogHandle)
IoXMLData("TotalSize", NumberConversion(objItem.Size, "", Units,2),
LogHandle)
IoXMLData("Units", Units, LogHandle)
IoXMLData("VolumeName", objItem.VolumeName, LogHandle)
IoXMLDataRaw("close", "LogicalDisk", LogHandle, "")
}
}
}
return(0)
}



function GetData_OS(LogHandle)
{
var strComputer = ".",LogF=0x20000
var objWMIService = GetObject("winmgmts:\\\\" + strComputer +
"\\root\\cimv2")
var e = new Enumerator(objWMIService.ExecQuery("Select * from
Win32_OperatingSystem","WQL",48))
if (FsLogFlag(LogF))
{
for (!e.atEnd()e.moveNext())
{ objItem = e.item()
IoXMLDataRaw("open", "SystemSummary", LogHandle,
GetData_TagAttributes("OS_Data"))
IoXMLData("Organisation", objItem.Organization, LogHandle)
IoXMLData("HostName", objItem.CSName, LogHandle)
IoXMLData("OS", objItem.Caption, LogHandle)
IoXMLData("Version", objItem.Version, LogHandle)
IoXMLData("ServicePack", objItem.CSDVersion, LogHandle)
//IoXMLData("SerialNumber", objItem.SerialNumber, LogHandle)
//IoXMLData("MaxPageFile", objItem.TotalVirtualMemorySize, LogHandle)
//IoXMLData("MemorySize", objItem.TotalVisibleMemorySize, LogHandle)
//IoXMLData("FreeMemory", objItem.FreePhysicalMemory, LogHandle)
//IoXMLData("LastBootUpTime", objItem.LastBootUpTime, LogHandle)
//IoXMLData("DateTime", objItem.LocalDateTime, LogHandle)
IoXMLDataRaw("close", "SystemSummary", LogHandle, "")
}
}
return(0)
}



function GetData_SharepointSize(LogHandle)
{
var Txt, Units="MB"
if (xData(3121) == "yes")
{
IoLogEvent("open", LogHandle, "")
Txt = "Size of sharepoint backup file is "
Txt += NumberConversion( FsFileSize(xData(3123), LogHandle), "", Units, 2)
Txt += " " + Units + ".\n"
IoLogEvent("content", FileHandle, Txt)
IoLogEvent("close", LogHandle, "")
}
return(Txt)
}



function GetData_TagAttributes(SrcTxt)
{
var oTxt=""
oTxt += "date=\""+DateInfo()+"\""
oTxt += " time=\""+TimeInfo()+"\""
oTxt += " type=\"information\" source=\"GetData_"+SrcTxt+"\""
oTxt += " category=\"none\" id=\"0\""
return(oTxt)
}



function GetData_TapeDrive(LogHandle)
{
var objWMIService = GetObject("winmgmts:\\\\.\\root\\cimv2")
var tape0=""
var e = new Enumerator(objWMIService.ExecQuery("Select * from
Win32_TapeDrive","WQL",48))
for (!e.atEnd()e.moveNext())
{
objItem = e.item()
IoXMLDataRaw("open", "Tape_Drives", LogHandle,
GetData_TagAttributes("Tape_Drives"))
IoXMLData("Name", objItem.Name, LogHandle)
if (tape0=="") tape0=objItem.Name
IoXMLData("Description", objItem.Description, LogHandle)
IoXMLData("Manufacturer", objItem.Manufacturer, LogHandle)
IoXMLData("Status", objItem.Status, LogHandle)
if (objItem.NeedsCleaning) IoXMLData("Cleaning", "Drive needs cleaning",
LogHandle)
switch (objItem.Availability)
{
case 0x3: IoXMLData("Availability", "Running/Full Power", LogHandle)
break
case 0x4: IoXMLData("Availability", "Warning", LogHandle)
break
case 0x5: IoXMLData("Availability", "In Test", LogHandle)
break
case 0x7: IoXMLData("Availability", "Power Off", LogHandle)
break
case 0x8: IoXMLData("Availability", "Offline", LogHandle)
break
case 0x9: IoXMLData("Availability", "Off duty", LogHandle)
break
case 0xA: IoXMLData("Availability", "Degraded", LogHandle)
break
default: IoXMLData("Availability", "Unknown", LogHandle)
break
}
switch (objItem.Capabilities[0])
{
case 0x1: IoXMLData("Capabilities", "Other", LogHandle)
break
case 0x2: IoXMLData("Capabilities", "Sequential Access", LogHandle)
break
case 0x3: IoXMLData("Capabilities", "Random Access", LogHandle)
break
case 0x4: IoXMLData("Capabilities", "Supports Writing", LogHandle)
break
default: IoXMLData("Capabilities","Unknown", LogHandle)
break
}
if (objItem.Compression) IoXMLData("Compression", "Hardware compression is
enabled", LogHandle)
IoXMLDataRaw("close", "Tape_Drives", LogHandle, "")
}
return(tape0)
}



function GetTempPath(os)
{
var wsh
wsh = WScript.CreateObject("WScript.Shell").environment
return(wsh("TEMP"))
}



//
============================================================================
// JScript Library module: email functions
// Author: David Hewison
// Version: 2007.02.07.01
//
// ===========================[
functions ]====================================


// [Email Library]

function Email(From, To, Subject, BodyText, AttachFile1, AttachFile2)
{
var objEmail = new ActiveXObject("CDO.Message")
objEmail.From = From
objEmail.To = To
objEmail.Subject = Subject
objEmail.TextBody = BodyText
if (AttachFile1 != "") objEmail.AddAttachment(AttachFile1)
if (AttachFile2 != "") objEmail.AddAttachment(AttachFile2)
objEmail.Send()
return(0)
}



function MyAddr()
{
return(xData(4021))
}



function OutlookWarning()
{
var msg=""
msg += "The attached log file bn-backup.xml will not open correctly inside
Microsoft Outlook "
msg += "(see Microsoft Q303487)."
msg += "If you are using Microsoft Outlook you must save the attached
logfile to disk first "
msg += "and open it from there.\n\n"
return(msg)
}



//
============================================================================
// JScript Library module: filesystem functions
// Author: David Hewison
// Version: 2007.02.07.01
// ===========================[
functions ]====================================


// [ FileSystem Library]

function FsCheckFileExists(FileName, LogHandle)
{
var ExitCode, LogF=0x2
if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, "FsCheckFileExists")
var fso = new ActiveXObject("Scripting.FileSystemObject")
ExitCode = fso.FileExists(FileName)
if (FsLogFlag(LogF))
{
if (ExitCode) IoLogEvent("content", LogHandle, FileName +" does exist\n")
else IoLogEvent("content", LogHandle, FileName +" was not found\n")
IoLogEvent("close",LogHandle,"")
}
return(ExitCode)
}



function FsCheckFolderExists(FolderName, LogHandle)
{
var ExitCode, LogF=0x200
if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, "")
var fso = new ActiveXObject("Scripting.FileSystemObject")
ExitCode = fso.FolderExists(FolderName)
if (FsLogFlag(LogF))
{
if (ExitCode) IoLogEvent("content", LogHandle, "FsCheckFolderExists success:
" + FolderName +"\n")
else IoLogEvent("content", LogHandle, "FsCheckFolderExists fail: " +
FolderName +"\n")
IoLogEvent("close",LogHandle,"")
}
return(ExitCode)
}



function FsFileCreate(FileName, LogHandle, Overwrite, Unicode)
{
var f, fso, LogF=0x1

if ((FsCheckFileExists(FileName, LogHandle) && Overwrite) ||
(!FsCheckFileExists(FileName, LogHandle)))
{
if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, "")
fso = new ActiveXObject("Scripting.FileSystemObject")
f = fso.CreateTextFile(FileName, Overwrite, Unicode)
f.Close()
if (FsLogFlag(LogF))
{
IoLogEvent("content", LogHandle, "FsFileCreate: " + FileName +"\n")
IoLogEvent("close",LogHandle,"")
}
return(0)
}
else return(1)
}



function FsFileDelete(FileName, LogHandle)
{
var f, fso, LogF=0x8

if (FsCheckFileExists(FileName, LogHandle))
{
if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, "")
fso = new ActiveXObject("Scripting.FileSystemObject")
f = fso.Getfile(FileName)
f.Delete()
if (FsLogFlag(LogF))
{
IoLogEvent("content", LogHandle, "FsFileDelete: " + FileName +"\n")
IoLogEvent("close",LogHandle,"")
}
return(0)
}
else return(1)
}


function FsFileSize(FileName, LogHandle)
{
var fso, s, o
fso = new ActiveXObject("Scripting.FileSystemObject")
o = fso.GetFile(FileName)
if (FsCheckFileExists(o, LogHandle))
s = o.size
else
s = -1
return(s)
}



function FsFileWrite(FileName, LogHandle, Unicode, text)
{
var f, fso, LogF=0x10

if (FsCheckFileExists(FileName, LogHandle))
{
if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, "")
fso = new ActiveXObject("Scripting.FileSystemObject")
f = fso.OpenTextFile(FileName, 2, false, Unicode)
f.Write(text)
f.Close()
if (FsLogFlag(LogF))
{
IoLogEvent("content", LogHandle, "FsFileWrite: " + FileName +"\n")
IoLogEvent("close",LogHandle,"")
}
return(0)
}
else return(1)
}



function FsFolderCopy(SrcPath, DestPath, LogHandle)
{
var LogF=0x400
if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, "")
fso = new ActiveXObject("Scripting.FileSystemObject")
fso.CopyFolder(SrcPath, DestPath)
if (FsLogFlag(LogF))
{
IoLogEvent("content", LogHandle, "FsFolderCopy: " + SrcPath + " to " +
DestPath + "\n")
IoLogEvent("close",LogHandle,"")
}
return(0)
}


function FsFolderCreate(Path, LogHandle)
{
var fso, a, LogF=0x100
if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, "")
fso = new ActiveXObject("Scripting.FileSystemObject")
if (fso.FolderExists(Path)) return(0)
a = fso.CreateFolder(Path)
if (FsLogFlag(LogF))
{
IoLogEvent("content", LogHandle, "FsFolderCreate: " + Path +"\n")
IoLogEvent("close",LogHandle,"")
}
return(0)
}




function FsFolderListing(Path)
{

var fso, f, f1, fc, s
fso = new ActiveXObject("Scripting.FileSystemObject")
f = fso.GetFolder(Path)
fc = new Enumerator(f.files)
s = ""
for ( !fc.atEnd() fc.moveNext())
{
s += fc.item() + "\n"
}
return(s)
}





function FsGetTempPath(LogHandle)
{
var wsh, LogF=0x1000,v=""
wsh = WScript.CreateObject("WScript.Shell").environment
v = wsh("TEMP")
if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, "")
if (FsLogFlag(LogF))
{
IoLogEvent("content", LogHandle, "Var TEMP: " + v +"\n")
IoLogEvent("close",LogHandle,"")
}
return(v)
}



function FsGetScriptPath(LogHandle)
{
var p, LogF=0x2000
if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, "")
p = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.length -
WScript.ScriptName.length)
if (FsLogFlag(LogF))
{
IoLogEvent("content", LogHandle, "Script Path: " + p +"\n")
IoLogEvent("close",LogHandle,"")
}
return(p)
}



function FsLogFlag(flag)
{
if ((xData(1001) & flag) == flag)
{
return(true)
}
else
{
return(false)
}
}



function FsObjectSize(Obj, LogHandle)
{
var fso, s
fso = new ActiveXObject("Scripting.FileSystemObject")
if ((FsCheckFileExists(Obj, LogHandle)) || (FsCheckFolderExists(Obj,
LogHandle)))
s = fso.size
else
s = -1
return(s)
}



function FsRegistryWriteKey(Key, LogHandle)
{
var WshShell = WScript.CreateObject("WScript.Shell")
IoLogEvent("open", LogHandle, "")
IoLogEvent("content", LogHandle, "Adding registry key: " + Key + "\n")
WshShell.RegWrite( Key, 1, "REG_BINARY")
IoLogEvent("close", LogHandle, "")
return(0)
}



function FsRegistryWriteValue(Value, Type, Content, LogHandle)
{
// Permissible Types are: REG_SZ, REG_DWORD, REG_BINARY

var WshShell = WScript.CreateObject("WScript.Shell")
IoLogEvent("open", LogHandle, "")
IoLogEvent("content", LogHandle, "Adding registry value: " + Value + "\n")
IoLogEvent("content", LogHandle, " - value type: " + Type + "\n")
IoLogEvent("content", LogHandle, " - value content: " + Content + "\n")
WshShell.RegWrite(Value, Content, Type)
IoLogEvent("close", LogHandle, "")
return(0)
}



function FsRunExtProg(Prog, Synchronously, LogHandle)
{
var LogF=0x4000, Result
var WshShell = new ActiveXObject("WScript.Shell")
var Process = WshShell.Exec(Prog)
if (FsLogFlag(LogF))
{
IoLogEvent("open", LogHandle, "Process_spawing")
if (!Synchronously)
IoLogEvent("content", LogHandle, "Spawning asynchronously: " + Prog +"\n")
else
IoLogEvent("content", LogHandle, "Spawning synchronously: " + Prog +"\n")
IoLogEvent("close",LogHandle,"")

}
if (!Synchronously)
{
return(0)
}
while (!Process.Status)
{
WScript.Sleep(10)
}
Result = Process.ExitCode
if (FsLogFlag(LogF))
{
IoLogEvent("open", LogHandle, "Process_Result")
IoLogEvent("content",LogHandle,Result)
IoLogEvent("close",LogHandle,"")
}
return(Result)
}



function FsScheduleCreate(Name, Command, Arguments, Type, Modifier, Start,
LogHandle)
{
var ComStr = "schtasks /create"
ComStr += " /TN \"" + Name + "\""
ComStr += " /TR \"" + Command + " " + Arguments + "\""
ComStr += " /SC " + Type + " /MO " + Modifier
if (Start != "") ComStr += " /ST " + Start
ComStr += " /S " + xData(5) + " /RU " + xData(8) + " /RP " + xData(9)
IoLogEvent("open", LogHandle, "")
IoLogEvent("content", LogHandle, "Creating scheduler task: " + Name + "\n")
IoLogEvent("content", LogHandle, "Data: " + ComStr + "\n")
RunExtProg("cmd.exe /c " + ComStr, false)
IoLogEvent("close", LogHandle, "")
return(0)
}


function FsReadTempFile()
{
var fs0, fo, fh, Line, tXt=""
var fso = new ActiveXObject("Scripting.FileSystemObject")

fo = fso.GetFile(FsTempFile())
fh = fo.OpenAsTextStream( 1, -2)
while (!fh.AtEndOfStream)
{
Line = fh.ReadLine()
if (Line != "") tXt += " \"" + Line + "\" "
}
fh.Close()
return(tXt)
}


function FsTempFile()
{
return(xData(1011) + "\\" + xData(4003))
}



//
============================================================================
// JScript Library module
// Author: David Hewison
// Version: 2006.08.26.01
//
// ===========================[ I/O
Library ]====================================


function IoAsk(Question)
{
var answer=""
IoConsoleOut(Question)
return(IoConsoleIn())
}



function IoConsoleIn()
{
var fso, h1, TextIn
fso = WScript.CreateObject("Scripting.FileSystemObject")

h1 = fso.OpenTextFile("con",1, false)
TextIn = h1.ReadLine()
h1.Close()
return(TextIn)
}



function IoConsoleOut(text)
{
var fso, h1
fso = WScript.CreateObject("Scripting.FileSystemObject")

h2 = fso.OpenTextFile("con",2, true)
h2.Write(text)
h2.Close()
return
}






function IoLog(mode, LogHandle)
{
if (mode=="open")
{
LogHandle.Write("<bnlog " + IoXMLSchema("bnlog") + ">\n")
}
if (mode=="close")
{
LogHandle.Write("</bnlog>\n")
}
return(0)
}



function IoLogCustomerInfo(LogHandle)
{
IoXMLDataRaw("open", "Customer", LogHandle, "")
IoXMLDataRaw("open", "Name", LogHandle, "")
IoXMLDataRaw("content", "", LogHandle, xData(3001))
IoXMLDataRaw("close", "Name", LogHandle, "")
IoXMLDataRaw("close", "Customer", LogHandle, "")
return(0)
}



function IoLogEvent(mode, LogHandle, Text)
{
if (mode=="open")
{
var Src = xData(1014), oTxt=""
if (Text != "") Src = Text
oTxt = "<Logevent date=\""+DateInfo()+"\""
oTxt += " time=\""+TimeInfo()+"\""
oTxt += " type=\"information\""
oTxt += " source=\"" + Src + "\""
oTxt += " category=\"none\" id=\"0\">\n"
LogHandle.Write(oTxt)
}
if (mode=="close")
{
var oTxt = "</Logevent>\n"
LogHandle.Write(oTxt)
}
if (mode=="content")
{
var oTxt = Text
LogHandle.Write(oTxt)
}
return(0)
}




function IoLogFile()
{
return(xData(1011) + "\\" + xData(1012))
}



function IoLogHostInfo(LogHandle)
{
GetData_OS(LogHandle)
return(0)
}



function IoXMLComment(Text)
{
var comment=""
comment += "<!--"
comment += Text
comment += "-->\n"
return(comment)
}



function IoXMLData( TagName, Content, LogHandle)
{
IoXMLDataRaw( "open", TagName, LogHandle, "")
IoXMLDataRaw( "content", "", LogHandle, Content)
IoXMLDataRaw( "close", TagName, LogHandle, "")
return(0)
}



function IoXMLDataRaw(mode, TagName, LogHandle, Text)
{
if (mode=="open")
{
var oTxt = "\n<" + TagName + " " + Text + ">"
LogHandle.Write(oTxt)
}
if (mode=="close")
{
var oTxt = "\n</" + TagName + ">"
LogHandle.Write(oTxt)
}
if (mode=="content")
{
var oTxt = Text
LogHandle.Write(oTxt)
}
return(0)
}




function IoXMLHeader(DocType, Standalone, LogHandle)
{
var XMLHeader
var InlineHeader="<?xml version=\"1.0\" standalone=\"yes\"?>"
var ExtHeader="<?xml version=\"1.0\" standalone=\"no\"?>"
var Style="bnlog"
var DocName = "Logging: " + xData(1) + " " + xData(2) + " \n Code libraries
by David Hewison, Infoshop 2000-2008"
var BN="Busted Networks Ltd"
var BNDetails=""
BNDetails += "PO Box 103\nBognor Regis\nWest Sussex\nPO22 0WB\nUK"
BNDetails += "\nWeb: http://www.bustednetworks.com"
BNDetails += "\nEmail: sales@bustednetworks.com"

if (Standalone) XMLHeader = InlineHeader
else XMLHeader = ExtHeader
LogHandle.Write(XMLHeader + "\n")
LogHandle.Write( IoXMLStylesheet(Style) )
LogHandle.Write(IoXMLComment(DocName))
LogHandle.Write(IoXMLComment(BN))
LogHandle.Write(IoXMLComment(BNDetails))
return(0)
}



function IoXMLSchema(schema)
{
var xsd=""
switch (schema)
{
case "bnlog": //Schema for Busted Networks Log Files
xsd += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
xsd +=
"xsi:noNamespaceSchemaLocation=\"http://www.infoshop.co.uk/xsd/bnlog-schema.xsd\"\n"
break
default:
break
}
return(xsd)

}


function IoXMLStylesheet(style)
{
var xsl=""
switch (style)
{
case "bnlog": //Style sheet for Busted Networks Log Files
xsl += "<?xml-stylesheet TYPE='text/xsl'
href='http://www.infoshop.co.uk/xsl/bnlogstyle.xsl'?>\n"
break
default:
break
}
return(xsl)
}



//
============================================================================
// JScript Library module: Number functions
// Author: David Hewison
// Version: 2007.02.07.01
//
// ===========================[ Num
Library ]====================================


function NumberConversion(x,srcUnits,targetUnits, Digits)
{
var y = 1, z = 1
switch (srcUnits)
{
case "KB": y = 1024
break

case "MB": y = 1048576
break

case "GB": y = 1073741824
break
}
switch (targetUnits)
{
case "KB": z = 1024
break

case "MB": z = 1048576
break

case "GB": z = 1073741824
break
}

return( parseInt(x * (y / z) * Math.pow(10,Digits))/Math.pow(10,Digits) )
}



//
============================================================================
// JScript Library module: rsm interface
// Author: David Hewison
// Version: 2007.02.01.01
//
// ===========================[ rsm
library ]====================================


function rsm(Arguments, FileHandle, LoopMax)
{
var i, ExitCode, cmdLine, fh, fo, fso, info
if (LoopMax>3) LoopMax = 3
if (LoopMax<1) LoopMax = 1
for (i=0 i<LoopMax i++)
{
info = " --result:"
cmdLine = "cmd.exe /C rsm.exe " + Arguments
TapeLog("append", "\nrsm command: " + cmdLine + "\n Command Output:\n")
IoLogEvent("open", FileHandle, "RSM_Command")
IoLogEvent("content", FileHandle, "\""+ Arguments + "\" \n")
IoLogEvent("close", FileHandle, "")
ExitCode = FsRunExtProg(cmdLine + " > \"" + FsTempFile() + "\"\"", true,
FileHandle)
FsRunExtProg("cmd.exe /c type \"" + FsTempFile() + "\" >> \"" +
TapeLogFile() + "\"\"", true, FileHandle)
IoLogEvent("open", FileHandle, "RSM_Result")
IoLogEvent("content", FileHandle, FsReadTempFile())
IoLogEvent("close", FileHandle, "")
if (ExitCode==0) i=LoopMax
else
{
IoLogEvent("open", FileHandle, "RSM_Result")
IoLogEvent("content", FileHandle, "Tape drive not ready, waiting" +
xData(4033) + " minutes\n")
IoLogEvent("close", FileHandle, "")
Sleep(xData(4033)*60)
}
}
return(FsReadTempFile())
}



//
============================================================================
// JScript Library module: sharepoint interface
// Author: David Hewison
// Version: 2007.02.01.01
//
// ===========================[ sharepoint
library ]============================


function SharePointBackup(LogHandle)
{
var ExitStatus, UtilCmd
var UtilCmd1 = "-o backup -url " + xData(3124) + " -filename "
var UtilCmd2 = " -overwrite"
UtilCmd = UtilCmd1 + xData(3123) + UtilCmd2

if (xData(3121)=="yes")
{
ExitStatus = FsRunExtProg("cmd.exe. /c " + xData(3122) + " " + UtilCmd,
true, LogHandle)
IoLogEvent("open", LogHandle, "")
if (ExitStatus==0) IoLogEvent("content", LogHandle, "Sharepoint backed up to
disk successfully\n")
else IoLogEvent("content", LogHandle, "Sharepoint backup returned error code
" + ExitStatus + "\n")
IoLogEvent("close", LogHandle, "")
}
return((ExitStatus==0))
}



//
============================================================================
// JScript Library module: string handling functions
// Author: David Hewison
// Version: 2006.04.26.01
//
// ===========================[
functions ]====================================


// [String Library]

function StrNumToStr(Number, Length)
{
var Index = ""
Index = Number.toString()
while (Index.length<Length) Index = "0"+Index
return(Index)
}


function StrIdxStr(Number, Length)
{
var Index = ""
Index = Number.toString()
while (Index.length<Length) Index = "0"+Index
return(Index)
}


//
============================================================================
// JScript Library module: tape and backup functions
// Author: David Hewison
// Version: 2007.02.07.01
//
// ===========================[
functions ]====================================


function Backup( BkUpCommand, FileHandle)
{
var ExitCode=0, BkUpUtil
BkUpUtil = BackUpUtil()
if (!FsCheckFileExists(BkUpUtil, FileHandle))
{
IoLogEvent("open", FileHandle, "Backup")
IoLogEvent("content", FileHandle, "Could not find: "+ BkUpUtil + "\n")
IoLogEvent("close", FileHandle, "")
ExitCode = 1
}
else
{
IoLogEvent("open", FileHandle, "Backup")
IoLogEvent("content", FileHandle," Starting with options: " + BkUpCommand +
"\n")
IoLogEvent("close", FileHandle, "")
ExitCode = FsRunExtProg("\""+BkUpUtil + "\" " + BkUpCommand, true,
FileHandle)
IoLogEvent("open", FileHandle, "Backup_Result")
IoLogEvent("content", FileHandle, ExitCode)
IoLogEvent("close", FileHandle, "")
}
return(ExitCode)
}



function BackupArgs(Name, SetLoc, overwrite)
{
var Label = "", Command = "", SetName="",i
for(i=1 i<5 i++)
{
if (BackUpSet(i)==SetLoc) SetName = "-" + i
}
Label = "\"" + Name + "\""
Command = "backup " + "\"" + SetLoc + "\""
Command += " /L:s /V:" + xData(4038) + " /R:no /RS:no /HC:" + xData(4035) +
" /SNAP:" + xData(4037)
Command += " /M normal /D " + Label + " /J " + Label
if (BackupToTape())
{
if (overwrite)
Command += " /N " + Label + " /P \"" + xData(4032) + "\" /UM"
else
Command += " /T " + Label + " /A"
}
if (BackupToDisk())
{
Command += " /N " + Label + " /f \"" + xData(4040) + "\\" +
TimeStr().substr(0,8) + SetName + ".bkf\""
}
return(Command)
}



function BackupLabel(text)
{
var label=""
if (text != "") text = " " + text + " "
else text =" "
label = GetData_CompName() + text + TimeStr().substr(0,8) + " Backup"
return(label)
}



function BackUpSet(n)
{
var x
switch (n)
{
case 1: x=xData(4051)
break
case 2: x=xData(4052)
break
case 3: x=xData(4053)
break
case 4: x=xData(4054)
break
default:
x=""
break
}
return(x)
}



function BackupToDisk()
{
if (xData(4030)=="disk") return(true)
else return(false)
}



function BackupToTape()
{
if (xData(4030)=="tape") return(true)
else return(false)
}



function BackUpUtil()
{
return(xData(4002))

}



function BackupRun(TapeDevice, NewLabel, Set, BackupStatus, LogHandle)
{
var CurrentLabel, Status=BackupStatus, FirstSet, ExitCode

if (BackUpSet(Set) == "") return(BackupStatus)

FirstSet = (BackupStatus & Flag("firstset")) == Flag("firstset")
if (BackupToTape()) CurrentLabel = TapeLabel(TapeDevice, LogHandle)
if (BackupToDisk() || (BackupToTape() && (CurrentLabel !="")))
{
ExitCode = Backup(BackupArgs(NewLabel, BackUpSet(Set), FirstSet),
LogHandle)
ConCatenateLogs(FirstSet, LogHandle)
Status = Status & (~ Flag("firstset"))
if (ExitCode != 0) Status = (Flag("results") << (Set-1)) | Status
}
else Status = (Status & (~ Flag("firstset")) ) | (Flag("results") <<
(Set-1))
return(Status)
}



function ConCatenateFile()
{
return(xData(1011) + "\\" + xData(4005))
}



function ConCatenateLogs(mode, FileHandle)
{
IoLogEvent("open", FileHandle, "")
if (mode)
{
FileHandle.Write("Creating log - " + ConCatenateFile() + "\n")
command = "cmd.exe /c type \"" + xData(4006) + "\" > \"" + ConCatenateFile()
+ "\""
}
else
{
FileHandle.Write("Appending to " + ConCatenateFile() + "\n")
command = "cmd.exe /c type \"" + xData(4006) + "\" >> \"" +
ConCatenateFile() + "\""
}
IoLogEvent("close", FileHandle, "")
FsRunExtProg(command , true, FileHandle)
return(0)
}



function ContinueBackup(CurrentStatus, FileHandle)
{
var Abort=0, LogF=0x10000000
Abort = CurrentStatus & xData(4026)

if (FsLogFlag(LogF))
{
IoLogEvent("open", FileHandle, "exception_check")
IoLogEvent("content", FileHandle, "exception status code: " + Abort)
IoLogEvent("close", FileHandle, "")
}
return((Abort==0))
}



function Flag(which)
{
var answer

switch (which)
{
case "label": //Command line label parameter
answer = 0x1
break

case "no_tape": // Tape not available
answer = 0x2
break

case "no_guid": //tape drive GUID not specified
answer = 0x4
break

case "disk_path": //path for backup-to-disk available
answer = 0x8
break

case "firstset": //the first backup set has not been done yet
answer = 0x10
break

case "results": //base for pass fail flags for each set
answer = 0x100
break

default:
answer = 0
break
}
return(answer)
}



function Tape_Eject(MediaName, LogHandle)
{
rsm("eject /pf\"" + MediaName + "\" /astart", LogHandle, 1)
}



function TapeInitialisation(LogHandle)
{
var Device=""
if (xData(4034)=="") return(Device)
TapeLog("create", "Busted Networks Ltd. Tape Log " + TimeStr().substr(0,8) +
"\n")
Device = GetData_TapeDrive(LogHandle)
if (Device=="") return(Device)
if (TapeLabel(Device, LogHandle)=="") Device=""
return(Device)
}



function TapeLabel(Drive, LogHandle)
{
var result="", i, tempstr=""
if (xData(4030)!="tape") return(1)
Tape_PollDrive(LogHandle)
result = rsm("view /tphysical_media /cg" + xData(4034), LogHandle, 1)
for(i=0i<result.lengthi++)
{
tempstr=""
while ( (result.substr(i,1)!="\"") && (i<result.length) ) i++
i++
while ( (result.substr(i,1)!="\"") && (i<result.length) )
{
tempstr += result.substr(i,1)
i++
}
i++
switch (tempstr)
{
case "PHYSICAL_MEDIA": tempstr="" break
case "The command completed successfully.": tempstr="" break
default:
i = result.length
break
}
}
return(tempstr)
}



function TapeLog(mode, data)
{
var fso = new ActiveXObject("Scripting.FileSystemObject")
var ForReading = 1, ForWriting = 2, ForAppending = 8, f
switch (mode)
{
case "create":
f = fso.OpenTextFile(TapeLogFile(), ForWriting, true)
break
case "append":
f = fso.OpenTextFile(TapeLogFile(), ForAppending, true)
break
default:
return(1)
}
f.Write(data)
f.Close()
return(0)
}



function TapeLogFile()
{
return(xData(1011) + "\\" + xData(4004))
}



function Tape_PollDrive(LogHandle)
{
var result="", i=0, tempstr=""
if (xData(4030)!="tape") return("")
rsm("refresh /lg\""+ xData(4034) + "\"", LogHandle, 1)
tempstr=""
while ( (result.substr(i,1)!="\"") && (i<result.length) ) i++
i++
while ( (result.substr(i,1)!="\"") && (i<result.length) )
{
tempstr += result.substr(i,1)
i++
}
i++
Sleep(xData(4033)*60)
return(tempstr)
}



//
============================================================================
// JScript Library module: time and date functions
// Author: David Hewison
// Version: 2007.02.01.01
//
// ===========================[
functions ]====================================


// [TimeDate Library]

function DateInfo()
{
var Today, year, month, day, wsh, datestr
Today = new Date()
wsh = WScript.createObject("WScript.Shell")

day = Today.getDate()
month = Today.getMonth()+1
year = Today.getYear()
datestr = StrNumToStr(year.toString(),4) + "-" +
StrNumToStr(month.toString(),2) + "-" + StrNumToStr(day.toString(),2)
return(datestr)
}




function Sleep(seconds)
{
WScript.Sleep(seconds * 1000)
return(0)
}




function TimeInfo()
{
var Today, wsh, timestr
Today = new Date()
wsh = WScript.createObject("WScript.Shell")

timestr = StrNumToStr(Today.getHours(),2) + ":" +
StrNumToStr(Today.getMinutes(),2) + ":" + StrNumToStr(Today.getSeconds(),2)
return(timestr)
}



function TimeStr()
{
var Today, year, month, day, hours, mins, secs, wsh, timestr
Today = new Date()
wsh = WScript.createObject("WScript.Shell")

secs = StrIdxStr(Today.getSeconds(),2)
mins = StrIdxStr(Today.getMinutes(),2)
hours = StrIdxStr(Today.getHours(),2)
day = StrIdxStr(Today.getDate(),2)
month = StrIdxStr((Today.getMonth() +1),2)
year = Today.getFullYear().toString()
timestr = year + month + day + hours + mins + secs
return(timestr)
}



//
============================================================================
// JScript Library module: xData
// Author: David Hewison
// Version: 2006.08.16.01
// Notes:
// This area is for the script configuration parameters.
// Configure your requiremets by modifying the answer lines.
//
// ===========================[
functions ]====================================

function xData(which)
{
var answer
switch (which)
{

case 1: // Script label
answer = "bn-backup"
break

case 2: // script version
answer = "3.41"
break

// ----------[ Logging data]-------------------------------------------

case 1001: // Logging flags
answer = 0x0FFFBFF0
break

case 1011: // Log File Path
answer = "c:\\Logs"
break

case 1012: // Log File Name
answer = "bn-backup.xml"
break

case 1014: // Log Event Information Name
answer = "bn-backup"
break

// ----------[ This System's exisiting configuration ] ----------------


case 2013: // This system's name
answer = GetData_CompName()
break

case 2014: // This system's OS
answer = GetData_OS()
break

// ----------[ Customer Data ]-----------------------------------------

case 3001: // Customer Company Name
answer = "OBC The Accountants"
break

// --------[ Application data ]--------------------------------------

case 3111: // Is this an Exchange server (yes/no) ?
answer = "no"
break

case 3112: // Exchange mailbox store rich text dB filename including full
path
answer = "c:\\program Files\\Exchsrvr\\mdbdata\\priv1.edb"
break

case 3113: // Exchange mailbox store streaming dB filename including full
path
answer = "c:\\program Files\\Exchsrvr\\mdbdata\\priv1.stm"
break

case 3114: // Exchange public store rich text dB filename including full
path
answer = "c:\\program Files\\Exchsrvr\\mdbdata\\pub1.edb"
break

case 3115: // Exchange public store streaming dB filename including full
path
answer = "c:\\program Files\\Exchsrvr\\mdbdata\\pub1.stm"
break

case 3121: // Is this a Sharepoint server (yes/no) ?
answer = "no"
break

case 3122: // STS Admin utility path
answer = "\"C:\\Program Files\\Common Files\\Microsoft Shared\\web server
extensions\\60\\BIN\\stsadm.exe\""
break

case 3123: //STS backup file with full path
answer = "d:\\admin\\backup\\STS\\sitebackup.dat"
break

case 3124: //STS site url
answer = "http://companyweb/"
break

case 3131: //Is this a SQL server
answer = "no"
break

case 3140: //Name of SQL Server Instance 1
answer = ""
break

case 3141: //Name of SQL Instance 1\database1
answer = "model"
break

case 3142: //Name of SQL Instance 1\database2
answer = ""
break

case 3143: //Name of SQL Instance 1\database3
answer = ""
break

case 3144: //Name of SQL Instance 1\database4
answer = ""
break

case 3145: //Name of SQL Instance 1\database5
answer = ""
break

case 3146: //Name of SQL Instance 1\database6
answer = ""
break

case 3147: //Name of SQL Instance 1\database7
answer = ""
break

case 3148: //Name of SQL Instance 1\database8
answer = ""
break

case 3149: //Name of SQL Instance 1\database9
answer = ""
break

// ----------[ Backup Data ]-----------------------------------------------

case 4002: // Backup utility location
answer = "C:\\windows\\system32\\ntbackup.exe"
break

case 4003: // Temporary work file
answer = "bn-temp.log"
break

case 4004: // Tape utility log
answer = "bn-tape.log"
break

case 4005: // Concatenation file for multiple logs
answer = "bn-backup.log"
break

case 4006: // Backup program's logfile location
answer = "C:\\Documents and Settings\\"
answer += xData(4007)
answer += "\\Local Settings\\Application Data\\Microsoft"
answer += "\\Windows NT\\NTbackup\\Data\\backup01.log"
break

case 4007: // Backup user profile folder name
answer = "administrator"
break

case 4021: // This script's email address
answer = "test" + "@" + xData(4022)
break

case 4022: // Public DNS domain
answer = "test domain"
break

case 4023: // Service monitor email address
answer = "testuser@test.com"
break

case 4024: //Enable email (yes/no)?
answer = "yes"
break

case 4026: // Abort flags
answer = (Flag("results") * 0xF) | Flag("no_tape") | Flag("no_guid") |
Flag("disk_path")
break

case 4030: // Backup device? Currently supports 'tape' or 'disk'
answer = "tape"
break

case 4031: // Eject tape after backup?
answer = "no"
break

case 4032: // Media Pool to use
answer = "LTO Ultrium"
break

case 4033: // Tape drive settling time in minutes
answer = 1
break

case 4034: //Tape drive to use specified by its rsm GUID
// -to find the rsm GUID use: rsm view /tlibrary /guiddisplay
answer = "895140920AFC450C8D134D70BD0A5132"
break

case 4035: //Enable (on) or disable (off) hardware compression
answer = "on"
break

case 4037: //Enable (on) or disable (off) shadow copying
answer = "on"
break

case 4038: //Verify after backup (yes/no)?
answer = "yes"
break

case 4040: //Destination for disk based backups
answer = ""
break

case 4041: //Disk folder for temporary sql backup files
answer = ""
break

case 4051: // backup set 1
answer = "@c:\\scripts\\backup.bks"
break



default:
answer = ""
break
}
return(answer)
}
 
Hi,

The script needs the full four sets specify in the configuration
(xData) section, add the following lines back in:

case 4052: // backup set 2
answer = ""
break

case 4053: // backup set 3
answer = ""
break

case 4054: // backup set 4
answer = ""
break

The script reads through the four backup sets, if a set string is
empty the it does not attempt to action it. So to run one set as you are
doing simply specify your bks set in one of the set strings (usually the
first as you did) and set the other three to empty, i.e. "".

David Hewison


--
dhewison
------------------------------------------------------------------------
dhewison's Profile: http://forums.techarena.in/members/dhewison.htm
View this thread: http://forums.techarena.in/windows-server-help/1058141.htm

http://forums.techarena.in
 
Back
Top