CODE
----------------------------------------------------------------------------------------------------------
-- Name: BackupExec.lua
-- Author: Robert Aronsson - Intellipool AB
-- Required INM version: 3.1 Build 1536
-- Version: 1.0
-- Date: 2006-12-12
-- Description: Checks for a completion status in a BackupExec XML log file
-- Arguments:
-- 1) Max age of file to check, in hours
-- 2) Path of the folder contaning the XML Files, path cant contain space
----------------------------------------------------------------------------------------------------------
sErrorString = "";
----------------------------------------------------------------------------------------------------------
-- Creates a table of all lines ending with CR in the text file
function makeTable(s)
local sInData = s;
iLastPos = 0;
t = {};
max = string.len(sInData);
for count = 0, max do
cCharacter = string.byte(sInData,count);
if cCharacter == 10 then
local sTemp = string.sub(sInData,iLastPos,count-1);
table.insert(t,sTemp);
iLastPos = count+1;
end
end
return t;
end
----------------------------------------------------------------------------------------------------------
-- Checks if a file meets the conditions set
function CheckFile(sFileName,iFileAge)
file = TLuaFile();
iLen = file:GetFileSize( sFileName );
-- if file size == 0 then we assume that backupexec currently are writing to the file
if iLen > 0 then
TimeSpan = TLuaDateTime();
TimeSpan:CreateSpan(iFileAge,0,0);
FileTime1 = TLuaDateTime();
FileTime2 = file:GetFileModifiedTime(sFileName);
FileTime1:Sub(TimeSpan);
-- Check time of file, ignore older files
if FileTime2:GreaterOrEqual(FileTime1) then
--print("File time: "..FileTime2:GetDate().." "..FileTime2:GetTime());
--print("Check time: "..FileTime1:GetDate().." "..FileTime1:GetTime());
-- Get File size
iLength = file:GetFileSize( sFileName );
-- Open file
if file:Open(sFileName) == 0 then
iRes = GetLastError();
sRes = FormatErrorString(iRes)
sErrorString = sErrorString.."\n".."Cant open file: "..sFileName .." "..sRes;
return;
end
-- Read the binary data
local RawData = file:ReadData(iLength);
-- Close file
file:Close();
-- Convert it to 8 bit text
local StringData = ConvertFromUTF16(RawData,iLength);
-- Search for the string and return depending on the search result
iPos = string.find(StringData,"<completeStatus>3</completeStatus>");
if iPos == nil then
sErrorString = sErrorString.."\n".."Completion status incorrect in file: "..sFileName;
return;
end
end
end
end
-- Extract arguments
iFileAge = GetArgument(0);
sFolderPath = GetArgument(1);
-- Create the table
tableFiles = {};
file = TLuaFile();
-- List directory and aquire length
sRet = file:GetFileList( sFolderPath, "BEX_*.xml" );
file:Close();
iLen = string.len( sRet );
-- Check if we got a list of files, this can be modified so that an empty directory does not yeild an error
if iLen==0 then
sErrString = "Failed to list files, error code:"..GetLastError().."\n"
SetExitStatus(sErrString,false);
return;
else
tableFiles = makeTable( sRet );
end
-- step through the table of files
nTableMax = table.getn(tableFiles);
for count=1, nTableMax do
sFileName = tableFiles[count];
--print("\nChecking file "..sFileName);
CheckFile(sFileName,iFileAge)
end
-- Determin if we got a happy ending
if string.len(sErrorString) > 0 then
sErrorString = "Backups not ok."..sErrorString;
-- Not, teh end !
SetExitStatus(sErrorString,false);
else
-- Everything ok, teh end !
SetExitStatus("Backups ok",true);
end
-- Name: BackupExec.lua
-- Author: Robert Aronsson - Intellipool AB
-- Required INM version: 3.1 Build 1536
-- Version: 1.0
-- Date: 2006-12-12
-- Description: Checks for a completion status in a BackupExec XML log file
-- Arguments:
-- 1) Max age of file to check, in hours
-- 2) Path of the folder contaning the XML Files, path cant contain space
----------------------------------------------------------------------------------------------------------
sErrorString = "";
----------------------------------------------------------------------------------------------------------
-- Creates a table of all lines ending with CR in the text file
function makeTable(s)
local sInData = s;
iLastPos = 0;
t = {};
max = string.len(sInData);
for count = 0, max do
cCharacter = string.byte(sInData,count);
if cCharacter == 10 then
local sTemp = string.sub(sInData,iLastPos,count-1);
table.insert(t,sTemp);
iLastPos = count+1;
end
end
return t;
end
----------------------------------------------------------------------------------------------------------
-- Checks if a file meets the conditions set
function CheckFile(sFileName,iFileAge)
file = TLuaFile();
iLen = file:GetFileSize( sFileName );
-- if file size == 0 then we assume that backupexec currently are writing to the file
if iLen > 0 then
TimeSpan = TLuaDateTime();
TimeSpan:CreateSpan(iFileAge,0,0);
FileTime1 = TLuaDateTime();
FileTime2 = file:GetFileModifiedTime(sFileName);
FileTime1:Sub(TimeSpan);
-- Check time of file, ignore older files
if FileTime2:GreaterOrEqual(FileTime1) then
--print("File time: "..FileTime2:GetDate().." "..FileTime2:GetTime());
--print("Check time: "..FileTime1:GetDate().." "..FileTime1:GetTime());
-- Get File size
iLength = file:GetFileSize( sFileName );
-- Open file
if file:Open(sFileName) == 0 then
iRes = GetLastError();
sRes = FormatErrorString(iRes)
sErrorString = sErrorString.."\n".."Cant open file: "..sFileName .." "..sRes;
return;
end
-- Read the binary data
local RawData = file:ReadData(iLength);
-- Close file
file:Close();
-- Convert it to 8 bit text
local StringData = ConvertFromUTF16(RawData,iLength);
-- Search for the string and return depending on the search result
iPos = string.find(StringData,"<completeStatus>3</completeStatus>");
if iPos == nil then
sErrorString = sErrorString.."\n".."Completion status incorrect in file: "..sFileName;
return;
end
end
end
end
-- Extract arguments
iFileAge = GetArgument(0);
sFolderPath = GetArgument(1);
-- Create the table
tableFiles = {};
file = TLuaFile();
-- List directory and aquire length
sRet = file:GetFileList( sFolderPath, "BEX_*.xml" );
file:Close();
iLen = string.len( sRet );
-- Check if we got a list of files, this can be modified so that an empty directory does not yeild an error
if iLen==0 then
sErrString = "Failed to list files, error code:"..GetLastError().."\n"
SetExitStatus(sErrString,false);
return;
else
tableFiles = makeTable( sRet );
end
-- step through the table of files
nTableMax = table.getn(tableFiles);
for count=1, nTableMax do
sFileName = tableFiles[count];
--print("\nChecking file "..sFileName);
CheckFile(sFileName,iFileAge)
end
-- Determin if we got a happy ending
if string.len(sErrorString) > 0 then
sErrorString = "Backups not ok."..sErrorString;
-- Not, teh end !
SetExitStatus(sErrorString,false);
else
-- Everything ok, teh end !
SetExitStatus("Backups ok",true);
end
