Logo

A division of Busted Networks Ltd

home services networking products support contacts hdr-butn-fill.gif (965 bytes)

CALL 01243 553251

home>products>infoshop>bn-backup


Product Name:
Version:
Release Date:
Licence:
System Requirements:


bn-backup.js
3.2
20th January 2007
GNU General Public License V2
Microsoft Windows 2000, 2003
Microsoft Windows SMTP service for mailing
Microsoft ntbackup utility
Microsoft rsm.exe
 

bn-backup help


// ==========================[ File Header ]===================================
// File: bn-backup.js
// Version: 3.2
// Date: 20th January 2007
// 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, firstset=true;
var Attachment2="";
var ForReading = 1, ForWriting = 2, ForAppending = 8;
var EmailBody = "Supplementary information:\n\n";
var NewLabel, Tapedevice, Tapelabel;

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

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

FileHandle = fso.OpenTextFile(IoLogFile(), ForWriting, true);
IoXMLHeader("", true, FileHandle);
IoLog("open", FileHandle);
if ((WScript.Arguments.length==1) && (WScript.Arguments(0).length<29))
{
IoLogCustomerInfo(FileHandle);
IoXMLDataRaw("open", "System", FileHandle, GetData_TagAttributes("System"))
IoLogHostInfo(FileHandle);
if (BackupToTape()) Tapedevice = TapeInitialisation(FileHandle);
NewLabel = GetData_CompName() + " " + WScript.Arguments(0) + " " + TimeStr().substr(0,8) + " Backup";
if (xData(3121)=="yes")
{
SharePointBackup(FileHandle);
EmailBody += GetData_SharepointSize(FileHandle);
}
if ((BackupToTape()) && (Tapedevice==""))
{
Tapedevice = TapeInitialisation(FileHandle);
if (Tapedevice=="")
{
EmailBody += "\nError: No tape media found.\n";
ExitStatus = 1;
}
}
if ((BackUpSet(1) != "") && (ExitStatus==0))
{
ExitStatus += BackupRun(Tapedevice, NewLabel, 1, firstset, FileHandle);
firstset = false;
}
if ((BackUpSet(2) != "") && (ExitStatus==0))
{
ExitStatus += BackupRun(Tapedevice, NewLabel, 2, firstset, FileHandle);
firstset = false;
}
if ((xData(3111) == "yes") && (BackUpSet(3) != "") && (ExitStatus==0))
{
ExitStatus += BackupRun(Tapedevice, NewLabel, 3, firstset, FileHandle);
firstset = false;
EmailBody += "\nExchange mailbox store size: " + GetData_ExchStoreSize("mbx",FileHandle) + " GB\n";
EmailBody += "\nExchange public store size: " + GetData_ExchStoreSize("pub",FileHandle) + " GB\n";
}
if ((BackUpSet(4) != "") && (ExitStatus==0))
{
ExitStatus += BackupRun(Tapedevice, NewLabel, 4, firstset, FileHandle);
firstset = false;
}
if ((xData(4031) == "yes") && (!firstset) && (xData(4030)=="tape"))
{
Tape_Eject(GetData_TapeLabel(Tapedevice, FileHandle), FileHandle)
}
GetData_LogicalDisk(FileHandle);
IoXMLDataRaw("close", "System", FileHandle, "")
}
else
{
IoLogEvent("open", FileHandle, "");
IoLogEvent("content", FileHandle, "No backup name supplied\n");
IoLogEvent("close", FileHandle, "");
}

IoLog("close", FileHandle);
FileHandle.Close();
Sleep(5);
if (!firstset) Attachment2=ConCatenateFile();

if ((ExitStatus==0) && (BackupStatus ==0) && (!firstset))
{
Email(MyAddr(), xData(4023), xData(3001) + " " + NewLabel + " log", EmailBody, IoLogFile(), Attachment2);
WScript.Quit(0);
}
else
{
Email(MyAddr(), xData(4023), xData(3001) + " " + NewLabel + " Failed", EmailBody, IoLogFile(), Attachment2);
WScript.Quit(1);
}

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


function Backup( BkUpCommand, FileHandle)
{
var ExitCode=0, BkUpUtil;
BkUpUtil = BackUpUtil();
IoLogEvent("open", FileHandle, "");
if (!FsCheckFileExists(BkUpUtil))
{
FileHandle.Write("Could not find: "+ BkUpUtil + "\n");
ExitCode = 1;
}
else
{
FileHandle.Write("Executing program: " + BkUpUtil);
FileHandle.Write(" with options: " + BkUpCommand + "\n");
ExitCode = RunExtProg("\""+BkUpUtil + "\" " + BkUpCommand, true);
IoLogEvent("content", FileHandle," --result: " + 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:yes /R:no /RS:no /HC:on /M normal";
Command += " /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 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, FirstSet, LogHandle)
{
var Tapelabel, Status=0;
if (BackupToTape()) Tapelabel = GetData_TapeLabel(TapeDevice, LogHandle);
if (BackupToDisk() || (BackupToTape() && (Tapelabel !="")))
{
Status = Backup(BackupArgs(NewLabel, BackUpSet(Set), FirstSet), LogHandle);
ConCatenateLogs(FirstSet, LogHandle);
FirstSet = false;
}
else Status =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() + "\"";
}
RunExtProg(command , true);
IoLogEvent("close", FileHandle, "");
return(0);
}



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 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 FsCheckFileExists(FileName)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ExitCode;
ExitCode = fso.FileExists(FileName)
return(ExitCode);
}



function FsCheckFolderExists(FolderName)
{
var ExitCode;
var fso = new ActiveXObject("Scripting.FileSystemObject");
ExitCode = fso.FolderExists(FolderName)
return(ExitCode);
}



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



function FsLogFlag(flag)
{
if ((xData(1001) & flag) == flag)

return(true);
else
return(false);
}



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 (FsLogFlag(LogF)) Logging = true;
if ((xData(3111) == "yes") && ((store=="mbx") || (store=="pub")))
{
if (store == "mbx")
{
size = FsFileSize(xData(3112), LogHandle) + FsFileSize(xData(3113), LogHandle);
size = parseInt(NumberConversion(size, "", Units)*100)/100;
if (Logging)
{
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 = parseInt(NumberConversion(size, "", Units)*100)/100;
if (Logging)
{
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";
var objWMIService = GetObject("winmgmts:\\\\" + strComputer + "\\root\\cimv2");
var e = new Enumerator(objWMIService.ExecQuery("Select * from Win32_LogicalDisk","WQL",48));

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", parseInt(NumberConversion(objItem.FreeSpace, "", Units)*100)/100, LogHandle);
IoXMLData("TotalSize", parseInt(NumberConversion(objItem.Size, "", Units)*100)/100, LogHandle);
IoXMLData("Units", Units, LogHandle);
IoXMLData("VolumeName", objItem.VolumeName, LogHandle);
IoXMLDataRaw("close", "LogicalDisk", LogHandle, "");
}
}
return(0);
}



function GetData_OS(LogHandle)
{
var strComputer = ".", oTxt="";
var objWMIService = GetObject("winmgmts:\\\\" + strComputer + "\\root\\cimv2");
var e = new Enumerator(objWMIService.ExecQuery("Select * from Win32_OperatingSystem","WQL",48));
oTxt += "date=\""+DateInfo()+"\"";
oTxt += " time=\""+TimeInfo()+"\"";
oTxt += " type=\"information\" source=\"GetData_OS\"";
oTxt += " category=\"none\" id=\"0\"";

for (;!e.atEnd();e.moveNext())
{ objItem = e.item();
IoXMLDataRaw("open", "SystemSummary", LogHandle, oTxt);
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 );
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 GetData_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=0;i<result.length;i++)
{
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 GetTempPath(os)
{
var wsh;
wsh = WScript.CreateObject("WScript.Shell").environment;
return(wsh("TEMP"));
}




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



// ============================================================================
// JScript Library module
// InfoShop 2000-2005
// 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: bn-backup V3.2 \n Code libraries David Hewison, Infoshop 2000-2007";
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);
}



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



function NumberConversion(x,srcUnits,targetUnits)
{
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( x * (y / z) );
}



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

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



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 = RunExtProg(cmdLine + " > \"" + TempFile() + "\"\"", true);
RunExtProg("cmd.exe /c type \"" + TempFile() + "\" >> \"" + TapeLogFile() + "\"\"", true);
IoLogEvent("open", FileHandle, "RSM_Result");
IoLogEvent("content", FileHandle, ReadTempFile());
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(ReadTempFile());
}



function RunExtProg(Prog, Synchronously)
{
var WshShell = new ActiveXObject("WScript.Shell");
var Process = WshShell.Exec(Prog);

if (!Synchronously)
{
return(0);
}
while (!Process.Status)
{
WScript.Sleep(10);
}
return(Process.ExitCode);
}



function SharePointBackup(LogHandle)
{
var ExitStatus, UtilCmd;
var UtilCmd1 = "-o backup -url http://localhost/ -filename ";
var UtilCmd2 = " -overwrite";
UtilCmd = UtilCmd1 + xData(3123) + UtilCmd2;

if (xData(3121)=="yes")
{
ExitStatus = RunExtProg("cmd.exe. /c " + xData(3122) + " " + UtilCmd, true)
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", FileHandle, "");
}
return(0);
}



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



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



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



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);
}



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


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 = IdxStr(Today.getSeconds(),2);
mins = IdxStr(Today.getMinutes(),2);
hours = IdxStr(Today.getHours(),2);
day = IdxStr(Today.getDate(),2);
month = IdxStr((Today.getMonth() +1),2);
year = Today.getFullYear().toString();
timestr = year + month + day + hours + mins + secs;
return(timestr);
}



// ============================================================================
// JScript Library module: string handling functions
// InfoShop 2000-2005
// 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: xData
// InfoShop 2000-2006
// 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)
{

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

case 1001: // Logging flags
answer = 0xFFFFFFFF;
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 = "Customer";
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 = "c:\\admin\\backup\\STS\\sitebackup.dat";
break;


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

case 4002: // Backup utility location
answer = "C:\\Winnt\\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 = "bn-backup." + GetData_CompName() + "@" + xData(4022);
break;

case 4022: // Public DNS domain
answer = "domain.co.uk";
break;

case 4023: // Service monitor email address
answer = "backup.administrator@domain.co.uk";
break;

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

case 4031: // Eject tape after backup?
answer = "yes";
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 rsm GUID -to find use: rsm view /tlibrary /guiddisplay
answer = "";
break;

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

case 4051: // backup set 1
answer = "@c:\\admin\\backup\\drive-c.bks";
break;

case 4052: // backup set 2
answer = "@c:\\admin\\backup\\drive-d.bks";
break;

case 4053: // backup set 3 - This must be the ExchangeIS set and only the Exchange set
answer = "@c:\\admin\\backup\\exchange.bks";
break;

case 4054: // backup set 4
answer = "@c:\\admin\\backup\\systemstate.bks";
break;

default:
answer = "";
break;
}
return(answer);
}
 

 

Registered as Busted Networks Limited in England and Wales as Company Number 3745185
Registered office Busted Networks Limited, Fiscal House, 2 Havant Road, Emsworth, Hampshire, PO10 7JE
VAT registration number 787 5689 46

(c) InfoShop 2000-2008